2 * The NFC Controller Interface is the communication protocol between an
3 * NFC Controller (NFCC) and a Device Host (DH).
4 * This is the HCI over NCI implementation, as specified in the 10.2
5 * section of the NCI 1.1 specification.
7 * Copyright (C) 2014 STMicroelectronics SAS. All rights reserved.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2
11 * as published by the Free Software Foundation
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, see <http://www.gnu.org/licenses/>.
23 #include <linux/skbuff.h>
26 #include <net/nfc/nci.h>
27 #include <net/nfc/nci_core.h>
28 #include <linux/nfc.h>
38 struct nci_hci_create_pipe_params
{
44 struct nci_hci_create_pipe_resp
{
52 struct nci_hci_delete_pipe_noti
{
56 struct nci_hci_all_pipe_cleared_noti
{
60 struct nci_hcp_message
{
61 u8 header
; /* type -cmd,evt,rsp- + instruction */
65 struct nci_hcp_packet
{
66 u8 header
; /* cbit+pipe */
67 struct nci_hcp_message message
;
70 #define NCI_HCI_ANY_SET_PARAMETER 0x01
71 #define NCI_HCI_ANY_GET_PARAMETER 0x02
72 #define NCI_HCI_ANY_CLOSE_PIPE 0x04
73 #define NCI_HCI_ADM_CLEAR_ALL_PIPE 0x14
75 #define NCI_HFP_NO_CHAINING 0x80
77 #define NCI_NFCEE_ID_HCI 0x80
79 #define NCI_EVT_HOT_PLUG 0x03
81 #define NCI_HCI_ADMIN_PARAM_SESSION_IDENTITY 0x01
82 #define NCI_HCI_ADM_CREATE_PIPE 0x10
83 #define NCI_HCI_ADM_DELETE_PIPE 0x11
86 #define NCI_HCI_HCP_PACKET_HEADER_LEN 1
87 #define NCI_HCI_HCP_MESSAGE_HEADER_LEN 1
88 #define NCI_HCI_HCP_HEADER_LEN 2
91 #define NCI_HCI_HCP_COMMAND 0x00
92 #define NCI_HCI_HCP_EVENT 0x01
93 #define NCI_HCI_HCP_RESPONSE 0x02
95 #define NCI_HCI_ADM_NOTIFY_PIPE_CREATED 0x12
96 #define NCI_HCI_ADM_NOTIFY_PIPE_DELETED 0x13
97 #define NCI_HCI_ADM_NOTIFY_ALL_PIPE_CLEARED 0x15
99 #define NCI_HCI_FRAGMENT 0x7f
100 #define NCI_HCP_HEADER(type, instr) ((((type) & 0x03) << 6) |\
103 #define NCI_HCP_MSG_GET_TYPE(header) ((header & 0xc0) >> 6)
104 #define NCI_HCP_MSG_GET_CMD(header) (header & 0x3f)
105 #define NCI_HCP_MSG_GET_PIPE(header) (header & 0x7f)
107 static int nci_hci_result_to_errno(u8 result
)
112 case NCI_HCI_ANY_E_REG_PAR_UNKNOWN
:
114 case NCI_HCI_ANY_E_TIMEOUT
:
122 static void nci_hci_reset_pipes(struct nci_hci_dev
*hdev
)
126 for (i
= 0; i
< NCI_HCI_MAX_PIPES
; i
++) {
127 hdev
->pipes
[i
].gate
= NCI_HCI_INVALID_GATE
;
128 hdev
->pipes
[i
].host
= NCI_HCI_INVALID_HOST
;
130 memset(hdev
->gate2pipe
, NCI_HCI_INVALID_PIPE
, sizeof(hdev
->gate2pipe
));
133 static void nci_hci_reset_pipes_per_host(struct nci_dev
*ndev
, u8 host
)
137 for (i
= 0; i
< NCI_HCI_MAX_PIPES
; i
++) {
138 if (ndev
->hci_dev
->pipes
[i
].host
== host
) {
139 ndev
->hci_dev
->pipes
[i
].gate
= NCI_HCI_INVALID_GATE
;
140 ndev
->hci_dev
->pipes
[i
].host
= NCI_HCI_INVALID_HOST
;
145 /* Fragment HCI data over NCI packet.
146 * NFC Forum NCI 10.2.2 Data Exchange:
147 * The payload of the Data Packets sent on the Logical Connection SHALL be
148 * valid HCP packets, as defined within [ETSI_102622]. Each Data Packet SHALL
149 * contain a single HCP packet. NCI Segmentation and Reassembly SHALL NOT be
150 * applied to Data Messages in either direction. The HCI fragmentation mechanism
151 * is used if required.
153 static int nci_hci_send_data(struct nci_dev
*ndev
, u8 pipe
,
154 const u8 data_type
, const u8
*data
,
157 struct nci_conn_info
*conn_info
;
162 conn_info
= ndev
->hci_dev
->conn_info
;
167 skb
= nci_skb_alloc(ndev
, conn_info
->max_pkt_payload_len
+
168 NCI_DATA_HDR_SIZE
, GFP_KERNEL
);
172 skb_reserve(skb
, NCI_DATA_HDR_SIZE
+ 2);
173 *skb_push(skb
, 1) = data_type
;
176 len
= conn_info
->max_pkt_payload_len
;
178 /* If last packet add NCI_HFP_NO_CHAINING */
179 if (i
+ conn_info
->max_pkt_payload_len
-
180 (skb
->len
+ 1) >= data_len
) {
181 cb
|= NCI_HFP_NO_CHAINING
;
184 len
= conn_info
->max_pkt_payload_len
- skb
->len
- 1;
187 *skb_push(skb
, 1) = cb
;
190 memcpy(skb_put(skb
, len
), data
+ i
, len
);
192 r
= nci_send_data(ndev
, conn_info
->conn_id
, skb
);
199 skb
= nci_skb_alloc(ndev
,
200 conn_info
->max_pkt_payload_len
+
201 NCI_DATA_HDR_SIZE
, GFP_KERNEL
);
205 skb_reserve(skb
, NCI_DATA_HDR_SIZE
+ 1);
207 } while (i
< data_len
);
212 static void nci_hci_send_data_req(struct nci_dev
*ndev
, unsigned long opt
)
214 struct nci_data
*data
= (struct nci_data
*)opt
;
216 nci_hci_send_data(ndev
, data
->pipe
, data
->cmd
,
217 data
->data
, data
->data_len
);
220 int nci_hci_send_event(struct nci_dev
*ndev
, u8 gate
, u8 event
,
221 const u8
*param
, size_t param_len
)
223 u8 pipe
= ndev
->hci_dev
->gate2pipe
[gate
];
225 if (pipe
== NCI_HCI_INVALID_PIPE
)
226 return -EADDRNOTAVAIL
;
228 return nci_hci_send_data(ndev
, pipe
,
229 NCI_HCP_HEADER(NCI_HCI_HCP_EVENT
, event
),
232 EXPORT_SYMBOL(nci_hci_send_event
);
234 int nci_hci_send_cmd(struct nci_dev
*ndev
, u8 gate
, u8 cmd
,
235 const u8
*param
, size_t param_len
,
236 struct sk_buff
**skb
)
238 struct nci_hcp_message
*message
;
239 struct nci_conn_info
*conn_info
;
240 struct nci_data data
;
242 u8 pipe
= ndev
->hci_dev
->gate2pipe
[gate
];
244 if (pipe
== NCI_HCI_INVALID_PIPE
)
245 return -EADDRNOTAVAIL
;
247 conn_info
= ndev
->hci_dev
->conn_info
;
251 data
.conn_id
= conn_info
->conn_id
;
253 data
.cmd
= NCI_HCP_HEADER(NCI_HCI_HCP_COMMAND
, cmd
);
255 data
.data_len
= param_len
;
257 r
= nci_request(ndev
, nci_hci_send_data_req
, (unsigned long)&data
,
258 msecs_to_jiffies(NCI_DATA_TIMEOUT
));
259 if (r
== NCI_STATUS_OK
) {
260 message
= (struct nci_hcp_message
*)conn_info
->rx_skb
->data
;
261 r
= nci_hci_result_to_errno(
262 NCI_HCP_MSG_GET_CMD(message
->header
));
263 skb_pull(conn_info
->rx_skb
, NCI_HCI_HCP_MESSAGE_HEADER_LEN
);
266 *skb
= conn_info
->rx_skb
;
271 EXPORT_SYMBOL(nci_hci_send_cmd
);
273 int nci_hci_clear_all_pipes(struct nci_dev
*ndev
)
277 r
= nci_hci_send_cmd(ndev
, NCI_HCI_ADMIN_GATE
,
278 NCI_HCI_ADM_CLEAR_ALL_PIPE
, NULL
, 0, NULL
);
282 nci_hci_reset_pipes(ndev
->hci_dev
);
285 EXPORT_SYMBOL(nci_hci_clear_all_pipes
);
287 static void nci_hci_event_received(struct nci_dev
*ndev
, u8 pipe
,
288 u8 event
, struct sk_buff
*skb
)
290 if (ndev
->ops
->hci_event_received
)
291 ndev
->ops
->hci_event_received(ndev
, pipe
, event
, skb
);
294 static void nci_hci_cmd_received(struct nci_dev
*ndev
, u8 pipe
,
295 u8 cmd
, struct sk_buff
*skb
)
297 u8 gate
= ndev
->hci_dev
->pipes
[pipe
].gate
;
298 u8 status
= NCI_HCI_ANY_OK
| ~NCI_HCI_FRAGMENT
;
299 u8 dest_gate
, new_pipe
;
300 struct nci_hci_create_pipe_resp
*create_info
;
301 struct nci_hci_delete_pipe_noti
*delete_info
;
302 struct nci_hci_all_pipe_cleared_noti
*cleared_info
;
304 pr_debug("from gate %x pipe %x cmd %x\n", gate
, pipe
, cmd
);
307 case NCI_HCI_ADM_NOTIFY_PIPE_CREATED
:
309 status
= NCI_HCI_ANY_E_NOK
;
312 create_info
= (struct nci_hci_create_pipe_resp
*)skb
->data
;
313 dest_gate
= create_info
->dest_gate
;
314 new_pipe
= create_info
->pipe
;
316 /* Save the new created pipe and bind with local gate,
317 * the description for skb->data[3] is destination gate id
318 * but since we received this cmd from host controller, we
319 * are the destination and it is our local gate
321 ndev
->hci_dev
->gate2pipe
[dest_gate
] = new_pipe
;
322 ndev
->hci_dev
->pipes
[new_pipe
].gate
= dest_gate
;
323 ndev
->hci_dev
->pipes
[new_pipe
].host
=
324 create_info
->src_host
;
326 case NCI_HCI_ANY_OPEN_PIPE
:
327 /* If the pipe is not created report an error */
328 if (gate
== NCI_HCI_INVALID_GATE
) {
329 status
= NCI_HCI_ANY_E_NOK
;
333 case NCI_HCI_ADM_NOTIFY_PIPE_DELETED
:
335 status
= NCI_HCI_ANY_E_NOK
;
338 delete_info
= (struct nci_hci_delete_pipe_noti
*)skb
->data
;
340 ndev
->hci_dev
->pipes
[delete_info
->pipe
].gate
=
341 NCI_HCI_INVALID_GATE
;
342 ndev
->hci_dev
->pipes
[delete_info
->pipe
].host
=
343 NCI_HCI_INVALID_HOST
;
345 case NCI_HCI_ADM_NOTIFY_ALL_PIPE_CLEARED
:
347 status
= NCI_HCI_ANY_E_NOK
;
352 (struct nci_hci_all_pipe_cleared_noti
*)skb
->data
;
353 nci_hci_reset_pipes_per_host(ndev
, cleared_info
->host
);
356 pr_debug("Discarded unknown cmd %x to gate %x\n", cmd
, gate
);
360 if (ndev
->ops
->hci_cmd_received
)
361 ndev
->ops
->hci_cmd_received(ndev
, pipe
, cmd
, skb
);
364 nci_hci_send_data(ndev
, pipe
, status
, NULL
, 0);
369 static void nci_hci_resp_received(struct nci_dev
*ndev
, u8 pipe
,
370 u8 result
, struct sk_buff
*skb
)
372 struct nci_conn_info
*conn_info
;
375 conn_info
= ndev
->hci_dev
->conn_info
;
377 status
= NCI_STATUS_REJECTED
;
381 conn_info
->rx_skb
= skb
;
384 nci_req_complete(ndev
, NCI_STATUS_OK
);
387 /* Receive hcp message for pipe, with type and cmd.
388 * skb contains optional message data only.
390 static void nci_hci_hcp_message_rx(struct nci_dev
*ndev
, u8 pipe
,
391 u8 type
, u8 instruction
, struct sk_buff
*skb
)
394 case NCI_HCI_HCP_RESPONSE
:
395 nci_hci_resp_received(ndev
, pipe
, instruction
, skb
);
397 case NCI_HCI_HCP_COMMAND
:
398 nci_hci_cmd_received(ndev
, pipe
, instruction
, skb
);
400 case NCI_HCI_HCP_EVENT
:
401 nci_hci_event_received(ndev
, pipe
, instruction
, skb
);
404 pr_err("UNKNOWN MSG Type %d, instruction=%d\n",
410 nci_req_complete(ndev
, NCI_STATUS_OK
);
413 static void nci_hci_msg_rx_work(struct work_struct
*work
)
415 struct nci_hci_dev
*hdev
=
416 container_of(work
, struct nci_hci_dev
, msg_rx_work
);
418 struct nci_hcp_message
*message
;
419 u8 pipe
, type
, instruction
;
421 while ((skb
= skb_dequeue(&hdev
->msg_rx_queue
)) != NULL
) {
422 pipe
= NCI_HCP_MSG_GET_PIPE(skb
->data
[0]);
423 skb_pull(skb
, NCI_HCI_HCP_PACKET_HEADER_LEN
);
424 message
= (struct nci_hcp_message
*)skb
->data
;
425 type
= NCI_HCP_MSG_GET_TYPE(message
->header
);
426 instruction
= NCI_HCP_MSG_GET_CMD(message
->header
);
427 skb_pull(skb
, NCI_HCI_HCP_MESSAGE_HEADER_LEN
);
429 nci_hci_hcp_message_rx(hdev
->ndev
, pipe
,
430 type
, instruction
, skb
);
434 void nci_hci_data_received_cb(void *context
,
435 struct sk_buff
*skb
, int err
)
437 struct nci_dev
*ndev
= (struct nci_dev
*)context
;
438 struct nci_hcp_packet
*packet
;
440 struct sk_buff
*hcp_skb
;
441 struct sk_buff
*frag_skb
;
447 nci_req_complete(ndev
, err
);
451 packet
= (struct nci_hcp_packet
*)skb
->data
;
452 if ((packet
->header
& ~NCI_HCI_FRAGMENT
) == 0) {
453 skb_queue_tail(&ndev
->hci_dev
->rx_hcp_frags
, skb
);
457 /* it's the last fragment. Does it need re-aggregation? */
458 if (skb_queue_len(&ndev
->hci_dev
->rx_hcp_frags
)) {
459 pipe
= NCI_HCP_MSG_GET_PIPE(packet
->header
);
460 skb_queue_tail(&ndev
->hci_dev
->rx_hcp_frags
, skb
);
463 skb_queue_walk(&ndev
->hci_dev
->rx_hcp_frags
, frag_skb
) {
464 msg_len
+= (frag_skb
->len
-
465 NCI_HCI_HCP_PACKET_HEADER_LEN
);
468 hcp_skb
= nfc_alloc_recv_skb(NCI_HCI_HCP_PACKET_HEADER_LEN
+
469 msg_len
, GFP_KERNEL
);
471 nci_req_complete(ndev
, -ENOMEM
);
475 *skb_put(hcp_skb
, NCI_HCI_HCP_PACKET_HEADER_LEN
) = pipe
;
477 skb_queue_walk(&ndev
->hci_dev
->rx_hcp_frags
, frag_skb
) {
478 msg_len
= frag_skb
->len
- NCI_HCI_HCP_PACKET_HEADER_LEN
;
479 memcpy(skb_put(hcp_skb
, msg_len
), frag_skb
->data
+
480 NCI_HCI_HCP_PACKET_HEADER_LEN
, msg_len
);
483 skb_queue_purge(&ndev
->hci_dev
->rx_hcp_frags
);
485 packet
->header
&= NCI_HCI_FRAGMENT
;
489 /* if this is a response, dispatch immediately to
490 * unblock waiting cmd context. Otherwise, enqueue to dispatch
491 * in separate context where handler can also execute command.
493 packet
= (struct nci_hcp_packet
*)hcp_skb
->data
;
494 type
= NCI_HCP_MSG_GET_TYPE(packet
->message
.header
);
495 if (type
== NCI_HCI_HCP_RESPONSE
) {
496 pipe
= NCI_HCP_MSG_GET_PIPE(packet
->header
);
497 skb_pull(hcp_skb
, NCI_HCI_HCP_PACKET_HEADER_LEN
);
498 nci_hci_hcp_message_rx(ndev
, pipe
, type
,
499 NCI_STATUS_OK
, hcp_skb
);
501 skb_queue_tail(&ndev
->hci_dev
->msg_rx_queue
, hcp_skb
);
502 schedule_work(&ndev
->hci_dev
->msg_rx_work
);
506 int nci_hci_open_pipe(struct nci_dev
*ndev
, u8 pipe
)
508 struct nci_data data
;
509 struct nci_conn_info
*conn_info
;
511 conn_info
= ndev
->hci_dev
->conn_info
;
515 data
.conn_id
= conn_info
->conn_id
;
517 data
.cmd
= NCI_HCP_HEADER(NCI_HCI_HCP_COMMAND
,
518 NCI_HCI_ANY_OPEN_PIPE
);
522 return nci_request(ndev
, nci_hci_send_data_req
,
523 (unsigned long)&data
,
524 msecs_to_jiffies(NCI_DATA_TIMEOUT
));
526 EXPORT_SYMBOL(nci_hci_open_pipe
);
528 static u8
nci_hci_create_pipe(struct nci_dev
*ndev
, u8 dest_host
,
529 u8 dest_gate
, int *result
)
533 struct nci_hci_create_pipe_params params
;
534 struct nci_hci_create_pipe_resp
*resp
;
536 pr_debug("gate=%d\n", dest_gate
);
538 params
.src_gate
= NCI_HCI_ADMIN_GATE
;
539 params
.dest_host
= dest_host
;
540 params
.dest_gate
= dest_gate
;
542 *result
= nci_hci_send_cmd(ndev
, NCI_HCI_ADMIN_GATE
,
543 NCI_HCI_ADM_CREATE_PIPE
,
544 (u8
*)¶ms
, sizeof(params
), &skb
);
546 return NCI_HCI_INVALID_PIPE
;
548 resp
= (struct nci_hci_create_pipe_resp
*)skb
->data
;
552 pr_debug("pipe created=%d\n", pipe
);
557 static int nci_hci_delete_pipe(struct nci_dev
*ndev
, u8 pipe
)
561 return nci_hci_send_cmd(ndev
, NCI_HCI_ADMIN_GATE
,
562 NCI_HCI_ADM_DELETE_PIPE
, &pipe
, 1, NULL
);
565 int nci_hci_set_param(struct nci_dev
*ndev
, u8 gate
, u8 idx
,
566 const u8
*param
, size_t param_len
)
568 struct nci_hcp_message
*message
;
569 struct nci_conn_info
*conn_info
;
570 struct nci_data data
;
573 u8 pipe
= ndev
->hci_dev
->gate2pipe
[gate
];
575 pr_debug("idx=%d to gate %d\n", idx
, gate
);
577 if (pipe
== NCI_HCI_INVALID_PIPE
)
578 return -EADDRNOTAVAIL
;
580 conn_info
= ndev
->hci_dev
->conn_info
;
584 tmp
= kmalloc(1 + param_len
, GFP_KERNEL
);
589 memcpy(tmp
+ 1, param
, param_len
);
591 data
.conn_id
= conn_info
->conn_id
;
593 data
.cmd
= NCI_HCP_HEADER(NCI_HCI_HCP_COMMAND
,
594 NCI_HCI_ANY_SET_PARAMETER
);
596 data
.data_len
= param_len
+ 1;
598 r
= nci_request(ndev
, nci_hci_send_data_req
,
599 (unsigned long)&data
,
600 msecs_to_jiffies(NCI_DATA_TIMEOUT
));
601 if (r
== NCI_STATUS_OK
) {
602 message
= (struct nci_hcp_message
*)conn_info
->rx_skb
->data
;
603 r
= nci_hci_result_to_errno(
604 NCI_HCP_MSG_GET_CMD(message
->header
));
605 skb_pull(conn_info
->rx_skb
, NCI_HCI_HCP_MESSAGE_HEADER_LEN
);
611 EXPORT_SYMBOL(nci_hci_set_param
);
613 int nci_hci_get_param(struct nci_dev
*ndev
, u8 gate
, u8 idx
,
614 struct sk_buff
**skb
)
616 struct nci_hcp_message
*message
;
617 struct nci_conn_info
*conn_info
;
618 struct nci_data data
;
620 u8 pipe
= ndev
->hci_dev
->gate2pipe
[gate
];
622 pr_debug("idx=%d to gate %d\n", idx
, gate
);
624 if (pipe
== NCI_HCI_INVALID_PIPE
)
625 return -EADDRNOTAVAIL
;
627 conn_info
= ndev
->hci_dev
->conn_info
;
631 data
.conn_id
= conn_info
->conn_id
;
633 data
.cmd
= NCI_HCP_HEADER(NCI_HCI_HCP_COMMAND
,
634 NCI_HCI_ANY_GET_PARAMETER
);
638 r
= nci_request(ndev
, nci_hci_send_data_req
, (unsigned long)&data
,
639 msecs_to_jiffies(NCI_DATA_TIMEOUT
));
641 if (r
== NCI_STATUS_OK
) {
642 message
= (struct nci_hcp_message
*)conn_info
->rx_skb
->data
;
643 r
= nci_hci_result_to_errno(
644 NCI_HCP_MSG_GET_CMD(message
->header
));
645 skb_pull(conn_info
->rx_skb
, NCI_HCI_HCP_MESSAGE_HEADER_LEN
);
648 *skb
= conn_info
->rx_skb
;
653 EXPORT_SYMBOL(nci_hci_get_param
);
655 int nci_hci_connect_gate(struct nci_dev
*ndev
,
656 u8 dest_host
, u8 dest_gate
, u8 pipe
)
658 bool pipe_created
= false;
661 if (pipe
== NCI_HCI_DO_NOT_OPEN_PIPE
)
664 if (ndev
->hci_dev
->gate2pipe
[dest_gate
] != NCI_HCI_INVALID_PIPE
)
667 if (pipe
!= NCI_HCI_INVALID_PIPE
)
671 case NCI_HCI_LINK_MGMT_GATE
:
672 pipe
= NCI_HCI_LINK_MGMT_PIPE
;
674 case NCI_HCI_ADMIN_GATE
:
675 pipe
= NCI_HCI_ADMIN_PIPE
;
678 pipe
= nci_hci_create_pipe(ndev
, dest_host
, dest_gate
, &r
);
679 if (pipe
== NCI_HCI_INVALID_PIPE
)
686 r
= nci_hci_open_pipe(ndev
, pipe
);
689 if (nci_hci_delete_pipe(ndev
, pipe
) < 0) {
690 /* TODO: Cannot clean by deleting pipe...
691 * -> inconsistent state
698 ndev
->hci_dev
->pipes
[pipe
].gate
= dest_gate
;
699 ndev
->hci_dev
->pipes
[pipe
].host
= dest_host
;
700 ndev
->hci_dev
->gate2pipe
[dest_gate
] = pipe
;
704 EXPORT_SYMBOL(nci_hci_connect_gate
);
706 static int nci_hci_dev_connect_gates(struct nci_dev
*ndev
,
708 struct nci_hci_gate
*gates
)
712 while (gate_count
--) {
713 r
= nci_hci_connect_gate(ndev
, gates
->dest_host
,
714 gates
->gate
, gates
->pipe
);
723 int nci_hci_dev_session_init(struct nci_dev
*ndev
)
725 struct nci_conn_info
*conn_info
;
729 ndev
->hci_dev
->count_pipes
= 0;
730 ndev
->hci_dev
->expected_pipes
= 0;
732 conn_info
= ndev
->hci_dev
->conn_info
;
736 conn_info
->data_exchange_cb
= nci_hci_data_received_cb
;
737 conn_info
->data_exchange_cb_context
= ndev
;
739 nci_hci_reset_pipes(ndev
->hci_dev
);
741 if (ndev
->hci_dev
->init_data
.gates
[0].gate
!= NCI_HCI_ADMIN_GATE
)
744 r
= nci_hci_connect_gate(ndev
,
745 ndev
->hci_dev
->init_data
.gates
[0].dest_host
,
746 ndev
->hci_dev
->init_data
.gates
[0].gate
,
747 ndev
->hci_dev
->init_data
.gates
[0].pipe
);
751 r
= nci_hci_get_param(ndev
, NCI_HCI_ADMIN_GATE
,
752 NCI_HCI_ADMIN_PARAM_SESSION_IDENTITY
, &skb
);
757 skb
->len
== strlen(ndev
->hci_dev
->init_data
.session_id
) &&
758 !memcmp(ndev
->hci_dev
->init_data
.session_id
, skb
->data
, skb
->len
) &&
759 ndev
->ops
->hci_load_session
) {
760 /* Restore gate<->pipe table from some proprietary location. */
761 r
= ndev
->ops
->hci_load_session(ndev
);
763 r
= nci_hci_clear_all_pipes(ndev
);
767 r
= nci_hci_dev_connect_gates(ndev
,
768 ndev
->hci_dev
->init_data
.gate_count
,
769 ndev
->hci_dev
->init_data
.gates
);
773 r
= nci_hci_set_param(ndev
, NCI_HCI_ADMIN_GATE
,
774 NCI_HCI_ADMIN_PARAM_SESSION_IDENTITY
,
775 ndev
->hci_dev
->init_data
.session_id
,
776 strlen(ndev
->hci_dev
->init_data
.session_id
));
784 EXPORT_SYMBOL(nci_hci_dev_session_init
);
786 struct nci_hci_dev
*nci_hci_allocate(struct nci_dev
*ndev
)
788 struct nci_hci_dev
*hdev
;
790 hdev
= kzalloc(sizeof(*hdev
), GFP_KERNEL
);
794 skb_queue_head_init(&hdev
->rx_hcp_frags
);
795 INIT_WORK(&hdev
->msg_rx_work
, nci_hci_msg_rx_work
);
796 skb_queue_head_init(&hdev
->msg_rx_queue
);