blob: 45f2fe4fd48670ea1f890c3303e3d20405def3a3 [file] [log] [blame]
Eric Lapuyade8b8d2e02012-04-10 19:43:06 +02001/*
2 * Copyright (C) 2012 Intel Corporation. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20#ifndef __LOCAL_HCI_H
21#define __LOCAL_HCI_H
22
23struct gate_pipe_map {
24 u8 gate;
25 u8 pipe;
26};
27
28struct hcp_message {
29 u8 header; /* type -cmd,evt,rsp- + instruction */
30 u8 data[];
31} __packed;
32
33struct hcp_packet {
34 u8 header; /* cbit+pipe */
35 struct hcp_message message;
36} __packed;
37
38/*
39 * HCI command execution completion callback.
40 * result will be one of the HCI response codes.
41 * skb contains the response data and must be disposed.
42 */
43typedef void (*hci_cmd_cb_t) (struct nfc_hci_dev *hdev, u8 result,
44 struct sk_buff *skb, void *cb_data);
45
46struct hcp_exec_waiter {
47 wait_queue_head_t *wq;
48 bool exec_complete;
49 int exec_result;
50 struct sk_buff *result_skb;
51};
52
53struct hci_msg {
54 struct list_head msg_l;
55 struct sk_buff_head msg_frags;
56 bool wait_response;
57 hci_cmd_cb_t cb;
58 void *cb_context;
59 unsigned long completion_delay;
60};
61
62struct hci_create_pipe_params {
63 u8 src_gate;
64 u8 dest_host;
65 u8 dest_gate;
66} __packed;
67
68struct hci_create_pipe_resp {
69 u8 src_host;
70 u8 src_gate;
71 u8 dest_host;
72 u8 dest_gate;
73 u8 pipe;
74} __packed;
75
76#define NFC_HCI_FRAGMENT 0x7f
77
78#define HCP_HEADER(type, instr) ((((type) & 0x03) << 6) | ((instr) & 0x3f))
79#define HCP_MSG_GET_TYPE(header) ((header & 0xc0) >> 6)
80#define HCP_MSG_GET_CMD(header) (header & 0x3f)
81
82int nfc_hci_hcp_message_tx(struct nfc_hci_dev *hdev, u8 pipe,
83 u8 type, u8 instruction,
84 const u8 *payload, size_t payload_len,
85 hci_cmd_cb_t cb, void *cb_data,
86 unsigned long completion_delay);
87
88u8 nfc_hci_pipe2gate(struct nfc_hci_dev *hdev, u8 pipe);
89
90void nfc_hci_hcp_message_rx(struct nfc_hci_dev *hdev, u8 pipe, u8 type,
91 u8 instruction, struct sk_buff *skb);
92
93/* HCP headers */
94#define NFC_HCI_HCP_PACKET_HEADER_LEN 1
95#define NFC_HCI_HCP_MESSAGE_HEADER_LEN 1
96#define NFC_HCI_HCP_HEADER_LEN 2
97
98/* HCP types */
99#define NFC_HCI_HCP_COMMAND 0x00
100#define NFC_HCI_HCP_EVENT 0x01
101#define NFC_HCI_HCP_RESPONSE 0x02
102
103/* Generic commands */
104#define NFC_HCI_ANY_SET_PARAMETER 0x01
105#define NFC_HCI_ANY_GET_PARAMETER 0x02
106#define NFC_HCI_ANY_OPEN_PIPE 0x03
107#define NFC_HCI_ANY_CLOSE_PIPE 0x04
108
109/* Reader RF commands */
110#define NFC_HCI_WR_XCHG_DATA 0x10
111
112/* Admin commands */
113#define NFC_HCI_ADM_CREATE_PIPE 0x10
114#define NFC_HCI_ADM_DELETE_PIPE 0x11
115#define NFC_HCI_ADM_NOTIFY_PIPE_CREATED 0x12
116#define NFC_HCI_ADM_NOTIFY_PIPE_DELETED 0x13
117#define NFC_HCI_ADM_CLEAR_ALL_PIPE 0x14
118#define NFC_HCI_ADM_NOTIFY_ALL_PIPE_CLEARED 0x15
119
120/* Generic responses */
121#define NFC_HCI_ANY_OK 0x00
122#define NFC_HCI_ANY_E_NOT_CONNECTED 0x01
123#define NFC_HCI_ANY_E_CMD_PAR_UNKNOWN 0x02
124#define NFC_HCI_ANY_E_NOK 0x03
125#define NFC_HCI_ANY_E_PIPES_FULL 0x04
126#define NFC_HCI_ANY_E_REG_PAR_UNKNOWN 0x05
127#define NFC_HCI_ANY_E_PIPE_NOT_OPENED 0x06
128#define NFC_HCI_ANY_E_CMD_NOT_SUPPORTED 0x07
129#define NFC_HCI_ANY_E_INHIBITED 0x08
130#define NFC_HCI_ANY_E_TIMEOUT 0x09
131#define NFC_HCI_ANY_E_REG_ACCESS_DENIED 0x0a
132#define NFC_HCI_ANY_E_PIPE_ACCESS_DENIED 0x0b
133
134/* Pipes */
135#define NFC_HCI_INVALID_PIPE 0x80
136#define NFC_HCI_LINK_MGMT_PIPE 0x00
137#define NFC_HCI_ADMIN_PIPE 0x01
138
139#endif /* __LOCAL_HCI_H */