18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (C) 2012  Intel Corporation. All rights reserved.
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#ifndef __LOCAL_HCI_H
78c2ecf20Sopenharmony_ci#define __LOCAL_HCI_H
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#include <net/nfc/hci.h>
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_cistruct gate_pipe_map {
128c2ecf20Sopenharmony_ci	u8 gate;
138c2ecf20Sopenharmony_ci	u8 pipe;
148c2ecf20Sopenharmony_ci};
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_cistruct hcp_message {
178c2ecf20Sopenharmony_ci	u8 header;		/* type -cmd,evt,rsp- + instruction */
188c2ecf20Sopenharmony_ci	u8 data[];
198c2ecf20Sopenharmony_ci} __packed;
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_cistruct hcp_packet {
228c2ecf20Sopenharmony_ci	u8 header;		/* cbit+pipe */
238c2ecf20Sopenharmony_ci	struct hcp_message message;
248c2ecf20Sopenharmony_ci} __packed;
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_cistruct hcp_exec_waiter {
278c2ecf20Sopenharmony_ci	wait_queue_head_t *wq;
288c2ecf20Sopenharmony_ci	bool exec_complete;
298c2ecf20Sopenharmony_ci	int exec_result;
308c2ecf20Sopenharmony_ci	struct sk_buff *result_skb;
318c2ecf20Sopenharmony_ci};
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_cistruct hci_msg {
348c2ecf20Sopenharmony_ci	struct list_head msg_l;
358c2ecf20Sopenharmony_ci	struct sk_buff_head msg_frags;
368c2ecf20Sopenharmony_ci	bool wait_response;
378c2ecf20Sopenharmony_ci	data_exchange_cb_t cb;
388c2ecf20Sopenharmony_ci	void *cb_context;
398c2ecf20Sopenharmony_ci	unsigned long completion_delay;
408c2ecf20Sopenharmony_ci};
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_cistruct hci_create_pipe_params {
438c2ecf20Sopenharmony_ci	u8 src_gate;
448c2ecf20Sopenharmony_ci	u8 dest_host;
458c2ecf20Sopenharmony_ci	u8 dest_gate;
468c2ecf20Sopenharmony_ci} __packed;
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_cistruct hci_create_pipe_resp {
498c2ecf20Sopenharmony_ci	u8 src_host;
508c2ecf20Sopenharmony_ci	u8 src_gate;
518c2ecf20Sopenharmony_ci	u8 dest_host;
528c2ecf20Sopenharmony_ci	u8 dest_gate;
538c2ecf20Sopenharmony_ci	u8 pipe;
548c2ecf20Sopenharmony_ci} __packed;
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_cistruct hci_delete_pipe_noti {
578c2ecf20Sopenharmony_ci	u8 pipe;
588c2ecf20Sopenharmony_ci} __packed;
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_cistruct hci_all_pipe_cleared_noti {
618c2ecf20Sopenharmony_ci	u8 host;
628c2ecf20Sopenharmony_ci} __packed;
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci#define NFC_HCI_FRAGMENT	0x7f
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci#define HCP_HEADER(type, instr) ((((type) & 0x03) << 6) | ((instr) & 0x3f))
678c2ecf20Sopenharmony_ci#define HCP_MSG_GET_TYPE(header) ((header & 0xc0) >> 6)
688c2ecf20Sopenharmony_ci#define HCP_MSG_GET_CMD(header) (header & 0x3f)
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ciint nfc_hci_hcp_message_tx(struct nfc_hci_dev *hdev, u8 pipe,
718c2ecf20Sopenharmony_ci			   u8 type, u8 instruction,
728c2ecf20Sopenharmony_ci			   const u8 *payload, size_t payload_len,
738c2ecf20Sopenharmony_ci			   data_exchange_cb_t cb, void *cb_context,
748c2ecf20Sopenharmony_ci			   unsigned long completion_delay);
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_civoid nfc_hci_hcp_message_rx(struct nfc_hci_dev *hdev, u8 pipe, u8 type,
778c2ecf20Sopenharmony_ci			    u8 instruction, struct sk_buff *skb);
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci/* HCP headers */
808c2ecf20Sopenharmony_ci#define NFC_HCI_HCP_PACKET_HEADER_LEN	1
818c2ecf20Sopenharmony_ci#define NFC_HCI_HCP_MESSAGE_HEADER_LEN	1
828c2ecf20Sopenharmony_ci#define NFC_HCI_HCP_HEADER_LEN		2
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci/* HCP types */
858c2ecf20Sopenharmony_ci#define NFC_HCI_HCP_COMMAND	0x00
868c2ecf20Sopenharmony_ci#define NFC_HCI_HCP_EVENT	0x01
878c2ecf20Sopenharmony_ci#define NFC_HCI_HCP_RESPONSE	0x02
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci/* Generic commands */
908c2ecf20Sopenharmony_ci#define NFC_HCI_ANY_SET_PARAMETER	0x01
918c2ecf20Sopenharmony_ci#define NFC_HCI_ANY_GET_PARAMETER	0x02
928c2ecf20Sopenharmony_ci#define NFC_HCI_ANY_OPEN_PIPE		0x03
938c2ecf20Sopenharmony_ci#define NFC_HCI_ANY_CLOSE_PIPE		0x04
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci/* Reader RF commands */
968c2ecf20Sopenharmony_ci#define NFC_HCI_WR_XCHG_DATA		0x10
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci/* Admin commands */
998c2ecf20Sopenharmony_ci#define NFC_HCI_ADM_CREATE_PIPE			0x10
1008c2ecf20Sopenharmony_ci#define NFC_HCI_ADM_DELETE_PIPE			0x11
1018c2ecf20Sopenharmony_ci#define NFC_HCI_ADM_NOTIFY_PIPE_CREATED		0x12
1028c2ecf20Sopenharmony_ci#define NFC_HCI_ADM_NOTIFY_PIPE_DELETED		0x13
1038c2ecf20Sopenharmony_ci#define NFC_HCI_ADM_CLEAR_ALL_PIPE		0x14
1048c2ecf20Sopenharmony_ci#define NFC_HCI_ADM_NOTIFY_ALL_PIPE_CLEARED	0x15
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci/* Generic responses */
1078c2ecf20Sopenharmony_ci#define NFC_HCI_ANY_OK				0x00
1088c2ecf20Sopenharmony_ci#define NFC_HCI_ANY_E_NOT_CONNECTED		0x01
1098c2ecf20Sopenharmony_ci#define NFC_HCI_ANY_E_CMD_PAR_UNKNOWN		0x02
1108c2ecf20Sopenharmony_ci#define NFC_HCI_ANY_E_NOK			0x03
1118c2ecf20Sopenharmony_ci#define NFC_HCI_ANY_E_PIPES_FULL		0x04
1128c2ecf20Sopenharmony_ci#define NFC_HCI_ANY_E_REG_PAR_UNKNOWN		0x05
1138c2ecf20Sopenharmony_ci#define NFC_HCI_ANY_E_PIPE_NOT_OPENED		0x06
1148c2ecf20Sopenharmony_ci#define NFC_HCI_ANY_E_CMD_NOT_SUPPORTED		0x07
1158c2ecf20Sopenharmony_ci#define NFC_HCI_ANY_E_INHIBITED			0x08
1168c2ecf20Sopenharmony_ci#define NFC_HCI_ANY_E_TIMEOUT			0x09
1178c2ecf20Sopenharmony_ci#define NFC_HCI_ANY_E_REG_ACCESS_DENIED		0x0a
1188c2ecf20Sopenharmony_ci#define NFC_HCI_ANY_E_PIPE_ACCESS_DENIED	0x0b
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci#endif /* __LOCAL_HCI_H */
121