1 /******************************************************************************
3 * Copyright (C) 2001-2012 Broadcom Corporation
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 ******************************************************************************/
19 /******************************************************************************
21 * this file contains the main BNEP functions
23 ******************************************************************************/
25 #include "bt_target.h"
47 #include "device/include/controller.h"
50 /********************************************************************************/
51 /* G L O B A L B N E P D A T A */
52 /********************************************************************************/
53 #if BNEP_DYNAMIC_MEMORY == FALSE
57 const UINT16 bnep_frame_hdr_sizes[] = {14, 1, 2, 8, 8};
59 /********************************************************************************/
60 /* L O C A L F U N C T I O N P R O T O T Y P E S */
61 /********************************************************************************/
62 static void bnep_connect_ind (BD_ADDR bd_addr, UINT16 l2cap_cid, UINT16 psm, UINT8 l2cap_id);
63 static void bnep_connect_cfm (UINT16 l2cap_cid, UINT16 result);
64 static void bnep_config_ind (UINT16 l2cap_cid, tL2CAP_CFG_INFO *p_cfg);
65 static void bnep_config_cfm (UINT16 l2cap_cid, tL2CAP_CFG_INFO *p_cfg);
66 static void bnep_disconnect_ind (UINT16 l2cap_cid, BOOLEAN ack_needed);
67 static void bnep_disconnect_cfm (UINT16 l2cap_cid, UINT16 result);
68 static void bnep_data_ind (UINT16 l2cap_cid, BT_HDR *p_msg);
69 static void bnep_congestion_ind (UINT16 lcid, BOOLEAN is_congested);
72 /*******************************************************************************
74 ** Function bnep_register_with_l2cap
76 ** Description This function registers BNEP PSM with L2CAP
80 *******************************************************************************/
81 tBNEP_RESULT bnep_register_with_l2cap (void)
83 /* Initialize the L2CAP configuration. We only care about MTU and flush */
84 memset(&bnep_cb.l2cap_my_cfg, 0, sizeof(tL2CAP_CFG_INFO));
86 bnep_cb.l2cap_my_cfg.mtu_present = TRUE;
87 bnep_cb.l2cap_my_cfg.mtu = BNEP_MTU_SIZE;
88 bnep_cb.l2cap_my_cfg.flush_to_present = TRUE;
89 bnep_cb.l2cap_my_cfg.flush_to = BNEP_FLUSH_TO;
91 bnep_cb.reg_info.pL2CA_ConnectInd_Cb = bnep_connect_ind;
92 bnep_cb.reg_info.pL2CA_ConnectCfm_Cb = bnep_connect_cfm;
93 bnep_cb.reg_info.pL2CA_ConfigInd_Cb = bnep_config_ind;
94 bnep_cb.reg_info.pL2CA_ConfigCfm_Cb = bnep_config_cfm;
95 bnep_cb.reg_info.pL2CA_DisconnectInd_Cb = bnep_disconnect_ind;
96 bnep_cb.reg_info.pL2CA_DisconnectCfm_Cb = bnep_disconnect_cfm;
97 bnep_cb.reg_info.pL2CA_DataInd_Cb = bnep_data_ind;
98 bnep_cb.reg_info.pL2CA_CongestionStatus_Cb = bnep_congestion_ind;
100 /* Now, register with L2CAP */
101 if (!L2CA_Register (BT_PSM_BNEP, &bnep_cb.reg_info))
103 BNEP_TRACE_ERROR ("BNEP - Registration failed");
104 return BNEP_SECURITY_FAIL;
111 /*******************************************************************************
113 ** Function bnep_connect_ind
115 ** Description This function handles an inbound connection indication
116 ** from L2CAP. This is the case where we are acting as a
121 *******************************************************************************/
122 static void bnep_connect_ind (BD_ADDR bd_addr, UINT16 l2cap_cid, UINT16 psm, UINT8 l2cap_id)
124 tBNEP_CONN *p_bcb = bnepu_find_bcb_by_bd_addr (bd_addr);
127 /* If we are not acting as server, or already have a connection, or have */
128 /* no more resources to handle the connection, reject the connection. */
129 if (!(bnep_cb.profile_registered) || (p_bcb)
130 || ((p_bcb = bnepu_allocate_bcb(bd_addr)) == NULL))
132 L2CA_ConnectRsp (bd_addr, l2cap_id, l2cap_cid, L2CAP_CONN_NO_PSM, 0);
136 /* Transition to the next appropriate state, waiting for config setup. */
137 p_bcb->con_state = BNEP_STATE_CFG_SETUP;
139 /* Save the L2CAP Channel ID. */
140 p_bcb->l2cap_cid = l2cap_cid;
142 /* Send response to the L2CAP layer. */
143 L2CA_ConnectRsp (bd_addr, l2cap_id, l2cap_cid, L2CAP_CONN_OK, L2CAP_CONN_OK);
145 /* Send a Configuration Request. */
146 L2CA_ConfigReq (l2cap_cid, &bnep_cb.l2cap_my_cfg);
148 /* Start timer waiting for config setup */
149 btu_start_timer (&p_bcb->conn_tle, BTU_TTYPE_BNEP, BNEP_CONN_TIMEOUT);
151 BNEP_TRACE_EVENT("BNEP - Rcvd L2CAP conn ind, CID: 0x%x", p_bcb->l2cap_cid);
156 /*******************************************************************************
158 ** Function bnep_connect_cfm
160 ** Description This function handles the connect confirm events
161 ** from L2CAP. This is the case when we are acting as a
162 ** client and have sent a connect request.
166 *******************************************************************************/
167 static void bnep_connect_cfm (UINT16 l2cap_cid, UINT16 result)
171 /* Find CCB based on CID */
172 if ((bcb = bnepu_find_bcb_by_cid (l2cap_cid)) == NULL)
174 BNEP_TRACE_WARNING ("BNEP - Rcvd conn cnf for unknown CID 0x%x", l2cap_cid);
178 /* If the connection response contains success status, then */
179 /* Transition to the next state and startup the timer. */
180 if ((result == L2CAP_CONN_OK) && (bcb->con_state == BNEP_STATE_CONN_START))
182 bcb->con_state = BNEP_STATE_CFG_SETUP;
184 /* Send a Configuration Request. */
185 L2CA_ConfigReq (l2cap_cid, &bnep_cb.l2cap_my_cfg);
187 /* Start timer waiting for config results */
188 btu_start_timer (&bcb->conn_tle, BTU_TTYPE_BNEP, BNEP_CONN_TIMEOUT);
190 BNEP_TRACE_EVENT ("BNEP - got conn cnf, sent cfg req, CID: 0x%x", bcb->l2cap_cid);
194 BNEP_TRACE_WARNING ("BNEP - Rcvd conn cnf with error: 0x%x CID 0x%x", result, bcb->l2cap_cid);
196 /* Tell the upper layer, if he has a callback */
197 if (bnep_cb.p_conn_state_cb &&
198 bcb->con_flags & BNEP_FLAGS_IS_ORIG)
200 (*bnep_cb.p_conn_state_cb) (bcb->handle, bcb->rem_bda, BNEP_CONN_FAILED, FALSE);
203 bnepu_release_bcb (bcb);
207 /*******************************************************************************
209 ** Function bnep_config_ind
211 ** Description This function processes the L2CAP configuration indication
216 *******************************************************************************/
217 static void bnep_config_ind (UINT16 l2cap_cid, tL2CAP_CFG_INFO *p_cfg)
220 UINT16 result, mtu = 0;
222 /* Find CCB based on CID */
223 if ((p_bcb = bnepu_find_bcb_by_cid (l2cap_cid)) == NULL)
225 BNEP_TRACE_WARNING ("BNEP - Rcvd L2CAP cfg ind, unknown CID: 0x%x", l2cap_cid);
229 BNEP_TRACE_EVENT ("BNEP - Rcvd cfg ind, CID: 0x%x", l2cap_cid);
231 /* Remember the remote MTU size */
232 if ((!p_cfg->mtu_present) || (p_cfg->mtu < BNEP_MIN_MTU_SIZE))
235 p_cfg->flush_to_present = FALSE;
236 p_cfg->mtu_present = TRUE;
237 p_cfg->mtu = BNEP_MIN_MTU_SIZE;
238 p_cfg->result = result = L2CAP_CFG_UNACCEPTABLE_PARAMS;
242 if (p_cfg->mtu > BNEP_MTU_SIZE)
243 p_bcb->rem_mtu_size = BNEP_MTU_SIZE;
245 p_bcb->rem_mtu_size = p_cfg->mtu;
247 /* For now, always accept configuration from the other side */
248 p_cfg->flush_to_present = FALSE;
249 p_cfg->mtu_present = FALSE;
250 p_cfg->result = result = L2CAP_CFG_OK;
253 L2CA_ConfigRsp (l2cap_cid, p_cfg);
255 if (result != L2CAP_CFG_OK)
257 BNEP_TRACE_EVENT ("BNEP - Rcvd cfg ind with bad MTU %d, CID: 0x%x", mtu, l2cap_cid);
261 p_bcb->con_flags |= BNEP_FLAGS_HIS_CFG_DONE;
263 if (p_bcb->con_flags & BNEP_FLAGS_MY_CFG_DONE)
265 p_bcb->con_state = BNEP_STATE_SEC_CHECKING;
267 /* Start timer waiting for setup or response */
268 btu_start_timer (&p_bcb->conn_tle, BTU_TTYPE_BNEP, BNEP_HOST_TIMEOUT);
270 if (p_bcb->con_flags & BNEP_FLAGS_IS_ORIG)
272 btm_sec_mx_access_request (p_bcb->rem_bda, BT_PSM_BNEP, TRUE,
274 bnep_get_uuid32(&(p_bcb->src_uuid)),
275 &bnep_sec_check_complete, p_bcb);
281 /*******************************************************************************
283 ** Function bnep_config_cfm
285 ** Description This function processes the L2CAP configuration confirmation
290 *******************************************************************************/
291 static void bnep_config_cfm (UINT16 l2cap_cid, tL2CAP_CFG_INFO *p_cfg)
295 BNEP_TRACE_EVENT ("BNEP - Rcvd cfg cfm, CID: 0x%x Result: %d", l2cap_cid, p_cfg->result);
297 /* Find CCB based on CID */
298 if ((p_bcb = bnepu_find_bcb_by_cid (l2cap_cid)) == NULL)
300 BNEP_TRACE_WARNING ("BNEP - Rcvd L2CAP cfg ind, unknown CID: 0x%x", l2cap_cid);
304 /* For now, always accept configuration from the other side */
305 if (p_cfg->result == L2CAP_CFG_OK)
307 p_bcb->con_flags |= BNEP_FLAGS_MY_CFG_DONE;
309 if (p_bcb->con_flags & BNEP_FLAGS_HIS_CFG_DONE)
311 p_bcb->con_state = BNEP_STATE_SEC_CHECKING;
313 /* Start timer waiting for setup or response */
314 btu_start_timer (&p_bcb->conn_tle, BTU_TTYPE_BNEP, BNEP_HOST_TIMEOUT);
316 if (p_bcb->con_flags & BNEP_FLAGS_IS_ORIG)
318 btm_sec_mx_access_request (p_bcb->rem_bda, BT_PSM_BNEP, TRUE,
320 bnep_get_uuid32(&(p_bcb->src_uuid)),
321 &bnep_sec_check_complete, p_bcb);
327 /* Tell the upper layer, if he has a callback */
328 if ((p_bcb->con_flags & BNEP_FLAGS_IS_ORIG) && (bnep_cb.p_conn_state_cb))
330 (*bnep_cb.p_conn_state_cb) (p_bcb->handle, p_bcb->rem_bda, BNEP_CONN_FAILED_CFG, FALSE);
333 L2CA_DisconnectReq (p_bcb->l2cap_cid);
335 bnepu_release_bcb (p_bcb);
340 /*******************************************************************************
342 ** Function bnep_disconnect_ind
344 ** Description This function handles a disconnect event from L2CAP. If
345 ** requested to, we ack the disconnect before dropping the CCB
349 *******************************************************************************/
350 static void bnep_disconnect_ind (UINT16 l2cap_cid, BOOLEAN ack_needed)
355 L2CA_DisconnectRsp (l2cap_cid);
357 /* Find CCB based on CID */
358 if ((p_bcb = bnepu_find_bcb_by_cid (l2cap_cid)) == NULL)
360 BNEP_TRACE_WARNING ("BNEP - Rcvd L2CAP disc, unknown CID: 0x%x", l2cap_cid);
364 BNEP_TRACE_EVENT ("BNEP - Rcvd L2CAP disc, CID: 0x%x", l2cap_cid);
366 /* Tell the user if he has a callback */
367 if (p_bcb->con_state == BNEP_STATE_CONNECTED)
369 if (bnep_cb.p_conn_state_cb)
370 (*bnep_cb.p_conn_state_cb)(p_bcb->handle, p_bcb->rem_bda, BNEP_CONN_DISCONNECTED, FALSE);
374 if ((bnep_cb.p_conn_state_cb) && ((p_bcb->con_flags & BNEP_FLAGS_IS_ORIG) ||
375 (p_bcb->con_flags & BNEP_FLAGS_CONN_COMPLETED)))
376 (*bnep_cb.p_conn_state_cb) (p_bcb->handle, p_bcb->rem_bda, BNEP_CONN_FAILED, FALSE);
379 bnepu_release_bcb (p_bcb);
384 /*******************************************************************************
386 ** Function bnep_disconnect_cfm
388 ** Description This function gets the disconnect confirm event from L2CAP
392 *******************************************************************************/
393 static void bnep_disconnect_cfm (UINT16 l2cap_cid, UINT16 result)
395 BNEP_TRACE_EVENT ("BNEP - Rcvd L2CAP disc cfm, CID: 0x%x, Result 0x%x", l2cap_cid, result);
400 /*******************************************************************************
402 ** Function bnep_congestion_ind
404 ** Description This is a callback function called by L2CAP when
405 ** congestion status changes
407 *******************************************************************************/
408 static void bnep_congestion_ind (UINT16 l2cap_cid, BOOLEAN is_congested)
412 /* Find BCB based on CID */
413 if ((p_bcb = bnepu_find_bcb_by_cid (l2cap_cid)) == NULL)
415 BNEP_TRACE_WARNING ("BNEP - Rcvd L2CAP cong, unknown CID: 0x%x", l2cap_cid);
421 p_bcb->con_flags |= BNEP_FLAGS_L2CAP_CONGESTED;
422 if(bnep_cb.p_tx_data_flow_cb)
424 bnep_cb.p_tx_data_flow_cb(p_bcb->handle, BNEP_TX_FLOW_OFF);
429 p_bcb->con_flags &= ~BNEP_FLAGS_L2CAP_CONGESTED;
431 if(bnep_cb.p_tx_data_flow_cb)
433 bnep_cb.p_tx_data_flow_cb(p_bcb->handle, BNEP_TX_FLOW_ON);
436 /* While not congested, send as many buffers as we can */
437 while (!(p_bcb->con_flags & BNEP_FLAGS_L2CAP_CONGESTED))
439 BT_HDR *p_buf = (BT_HDR *)GKI_dequeue (&p_bcb->xmit_q);
444 L2CA_DataWrite (l2cap_cid, p_buf);
451 /*******************************************************************************
453 ** Function bnep_data_ind
455 ** Description This function is called when data is received from L2CAP.
456 ** if we are the originator of the connection, we are the SDP
457 ** client, and the received message is queued up for the client.
459 ** If we are the destination of the connection, we are the SDP
460 ** server, so the message is passed to the server processing
465 *******************************************************************************/
466 static void bnep_data_ind (UINT16 l2cap_cid, BT_HDR *p_buf)
469 UINT8 *p = (UINT8 *)(p_buf + 1) + p_buf->offset;
470 UINT16 rem_len = p_buf->len;
471 UINT8 type, ctrl_type, ext_type = 0;
472 BOOLEAN extension_present, fw_ext_present;
474 UINT8 *p_src_addr, *p_dst_addr;
478 android_errorWriteLog(0x534e4554, "78286118");
484 /* Find CCB based on CID */
485 if ((p_bcb = bnepu_find_bcb_by_cid (l2cap_cid)) == NULL)
487 BNEP_TRACE_WARNING ("BNEP - Rcvd L2CAP data, unknown CID: 0x%x", l2cap_cid);
492 /* Get the type and extension bits */
494 extension_present = type >> 7;
496 if (type >= sizeof(bnep_frame_hdr_sizes) / sizeof(bnep_frame_hdr_sizes[0])) {
497 BNEP_TRACE_EVENT("BNEP - rcvd frame, bad type: 0x%02x", type);
498 android_errorWriteLog(0x534e4554, "68818034");
502 if ((rem_len <= bnep_frame_hdr_sizes[type]) || (rem_len > BNEP_MTU_SIZE))
504 BNEP_TRACE_EVENT ("BNEP - rcvd frame, bad len: %d type: 0x%02x", p_buf->len, type);
511 if ((p_bcb->con_state != BNEP_STATE_CONNECTED) &&
512 (!(p_bcb->con_flags & BNEP_FLAGS_CONN_COMPLETED)) &&
513 (type != BNEP_FRAME_CONTROL))
515 BNEP_TRACE_WARNING ("BNEP - Ignored L2CAP data while in state: %d, CID: 0x%x",
516 p_bcb->con_state, l2cap_cid);
518 if (extension_present)
521 ** When there is no connection if a data packet is received
522 ** with unknown control extension headers then those should be processed
523 ** according to complain/ignore law
526 UINT16 org_len, new_len;
527 /* parse the extension headers and process unknown control headers */
531 android_errorWriteLog(0x534e4554, "67863755");
537 new_len = (length + 2);
538 if (new_len > org_len) {
539 android_errorWriteLog(0x534e4554, "67863755");
543 if ((ext & 0x7F) == BNEP_EXTENSION_FILTER_CONTROL) {
545 android_errorWriteLog(0x534e4554, "79164722");
548 if (*p > BNEP_FILTER_MULTI_ADDR_RESPONSE_MSG) {
549 bnep_send_command_not_understood(p_bcb, *p);
557 } while (ext & 0x80);
564 if (type > BNEP_FRAME_COMPRESSED_ETHERNET_DEST_ONLY)
566 BNEP_TRACE_EVENT ("BNEP - rcvd frame, unknown type: 0x%02x", type);
571 BNEP_TRACE_DEBUG ("BNEP - rcv frame, type: %d len: %d Ext: %d", type, p_buf->len, extension_present);
573 /* Initialize addresses to 'not supplied' */
574 p_src_addr = p_dst_addr = NULL;
578 case BNEP_FRAME_GENERAL_ETHERNET:
583 BE_STREAM_TO_UINT16 (protocol, p);
587 case BNEP_FRAME_CONTROL:
589 p = bnep_process_control_packet (p_bcb, p, &rem_len, FALSE);
591 if (ctrl_type == BNEP_SETUP_CONNECTION_REQUEST_MSG &&
592 p_bcb->con_state != BNEP_STATE_CONNECTED &&
593 extension_present && p && rem_len)
595 if (p_bcb->p_pending_data)
596 GKI_freebuf (p_bcb->p_pending_data);
597 p_bcb->p_pending_data = (BT_HDR *)GKI_getbuf (rem_len + sizeof(BT_HDR));
598 if (p_bcb->p_pending_data)
600 memcpy ((UINT8 *)(p_bcb->p_pending_data + 1), p, rem_len);
601 p_bcb->p_pending_data->len = rem_len;
602 p_bcb->p_pending_data->offset = 0;
607 while (extension_present && p && rem_len)
611 extension_present = ext_type >> 7;
614 /* if unknown extension present stop processing */
615 if (ext_type != BNEP_EXTENSION_FILTER_CONTROL) break;
617 android_errorWriteLog(0x534e4554, "69271284");
618 p = bnep_process_control_packet (p_bcb, p, &rem_len, TRUE);
624 case BNEP_FRAME_COMPRESSED_ETHERNET:
625 BE_STREAM_TO_UINT16 (protocol, p);
629 case BNEP_FRAME_COMPRESSED_ETHERNET_SRC_ONLY:
632 BE_STREAM_TO_UINT16 (protocol, p);
636 case BNEP_FRAME_COMPRESSED_ETHERNET_DEST_ONLY:
639 BE_STREAM_TO_UINT16 (protocol, p);
644 /* Process the header extension if there is one */
645 while (extension_present && p && rem_len)
648 extension_present = ext_type >> 7;
651 /* if unknown extension present stop processing */
654 BNEP_TRACE_EVENT ("Data extension type 0x%x found", ext_type);
660 p = bnep_process_control_packet (p_bcb, p, &rem_len, TRUE);
663 p_buf->offset += p_buf->len - rem_len;
664 p_buf->len = rem_len;
666 /* Always give the upper layer MAC addresses */
668 p_src_addr = (UINT8 *) p_bcb->rem_bda;
671 p_dst_addr = (UINT8 *) controller_get_interface()->get_address();
673 /* check whether there are any extensions to be forwarded */
675 fw_ext_present = TRUE;
677 fw_ext_present = FALSE;
679 if (bnep_cb.p_data_buf_cb)
681 (*bnep_cb.p_data_buf_cb)(p_bcb->handle, p_src_addr, p_dst_addr, protocol, p_buf, fw_ext_present);
683 else if (bnep_cb.p_data_ind_cb)
685 (*bnep_cb.p_data_ind_cb)(p_bcb->handle, p_src_addr, p_dst_addr, protocol, p, rem_len, fw_ext_present);
692 /*******************************************************************************
694 ** Function bnep_process_timeout
696 ** Description This function processes a timeout. If it is a startup
697 ** timeout, we check for reading our BD address. If it
698 ** is an L2CAP timeout, we send a disconnect req to L2CAP.
702 *******************************************************************************/
703 void bnep_process_timeout (TIMER_LIST_ENT *p_tle)
712 p_bcb = (tBNEP_CONN *)p_tle->param;
714 BNEP_TRACE_EVENT ("BNEP - CCB timeout in state: %d CID: 0x%x flags %x, re_transmit %d",
715 p_bcb->con_state, p_bcb->l2cap_cid, p_bcb->con_flags, p_bcb->re_transmits);
717 if (p_bcb->con_state == BNEP_STATE_CONN_SETUP)
719 BNEP_TRACE_EVENT ("BNEP - CCB timeout in state: %d CID: 0x%x",
720 p_bcb->con_state, p_bcb->l2cap_cid);
722 if (!(p_bcb->con_flags & BNEP_FLAGS_IS_ORIG))
724 L2CA_DisconnectReq (p_bcb->l2cap_cid);
726 bnepu_release_bcb (p_bcb);
730 if (p_bcb->re_transmits++ != BNEP_MAX_RETRANSMITS)
732 bnep_send_conn_req (p_bcb);
733 btu_start_timer (&p_bcb->conn_tle, BTU_TTYPE_BNEP, BNEP_CONN_TIMEOUT);
737 L2CA_DisconnectReq (p_bcb->l2cap_cid);
739 if ((p_bcb->con_flags & BNEP_FLAGS_IS_ORIG) && (bnep_cb.p_conn_state_cb))
740 (*bnep_cb.p_conn_state_cb) (p_bcb->handle, p_bcb->rem_bda, BNEP_CONN_FAILED, FALSE);
742 bnepu_release_bcb (p_bcb);
746 else if (p_bcb->con_state != BNEP_STATE_CONNECTED)
748 BNEP_TRACE_EVENT ("BNEP - CCB timeout in state: %d CID: 0x%x",
749 p_bcb->con_state, p_bcb->l2cap_cid);
751 L2CA_DisconnectReq (p_bcb->l2cap_cid);
753 /* Tell the user if he has a callback */
754 if ((p_bcb->con_flags & BNEP_FLAGS_IS_ORIG) && (bnep_cb.p_conn_state_cb))
755 (*bnep_cb.p_conn_state_cb) (p_bcb->handle, p_bcb->rem_bda, BNEP_CONN_FAILED, FALSE);
757 bnepu_release_bcb (p_bcb);
759 else if (p_bcb->con_flags & BNEP_FLAGS_FILTER_RESP_PEND)
761 if (p_bcb->re_transmits++ != BNEP_MAX_RETRANSMITS)
763 bnepu_send_peer_our_filters (p_bcb);
764 btu_start_timer (&p_bcb->conn_tle, BTU_TTYPE_BNEP, BNEP_FILTER_SET_TIMEOUT);
768 L2CA_DisconnectReq (p_bcb->l2cap_cid);
770 /* Tell the user if he has a callback */
771 if (bnep_cb.p_conn_state_cb)
772 (*bnep_cb.p_conn_state_cb) (p_bcb->handle, p_bcb->rem_bda, BNEP_SET_FILTER_FAIL, FALSE);
774 bnepu_release_bcb (p_bcb);
778 else if (p_bcb->con_flags & BNEP_FLAGS_MULTI_RESP_PEND)
780 if (p_bcb->re_transmits++ != BNEP_MAX_RETRANSMITS)
782 bnepu_send_peer_our_multi_filters (p_bcb);
783 btu_start_timer (&p_bcb->conn_tle, BTU_TTYPE_BNEP, BNEP_FILTER_SET_TIMEOUT);
787 L2CA_DisconnectReq (p_bcb->l2cap_cid);
789 /* Tell the user if he has a callback */
790 if (bnep_cb.p_conn_state_cb)
791 (*bnep_cb.p_conn_state_cb) (p_bcb->handle, p_bcb->rem_bda, BNEP_SET_FILTER_FAIL, FALSE);
793 bnepu_release_bcb (p_bcb);
800 /*******************************************************************************
802 ** Function bnep_connected
804 ** Description This function is called when a connection is established
809 *******************************************************************************/
810 void bnep_connected (tBNEP_CONN *p_bcb)
812 BOOLEAN is_role_change;
814 if (p_bcb->con_flags & BNEP_FLAGS_CONN_COMPLETED)
815 is_role_change = TRUE;
817 is_role_change = FALSE;
819 p_bcb->con_state = BNEP_STATE_CONNECTED;
820 p_bcb->con_flags |= BNEP_FLAGS_CONN_COMPLETED;
821 p_bcb->con_flags &= (~BNEP_FLAGS_SETUP_RCVD);
823 /* Ensure timer is stopped */
824 btu_stop_timer (&p_bcb->conn_tle);
825 p_bcb->re_transmits = 0;
827 /* Tell the upper layer, if he has a callback */
828 if (bnep_cb.p_conn_state_cb)
829 (*bnep_cb.p_conn_state_cb) (p_bcb->handle, p_bcb->rem_bda, BNEP_SUCCESS, is_role_change);