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;
477 /* Find CCB based on CID */
478 if ((p_bcb = bnepu_find_bcb_by_cid (l2cap_cid)) == NULL)
480 BNEP_TRACE_WARNING ("BNEP - Rcvd L2CAP data, unknown CID: 0x%x", l2cap_cid);
485 /* Get the type and extension bits */
487 extension_present = type >> 7;
489 if (type >= sizeof(bnep_frame_hdr_sizes) / sizeof(bnep_frame_hdr_sizes[0])) {
490 BNEP_TRACE_EVENT("BNEP - rcvd frame, bad type: 0x%02x", type);
491 android_errorWriteLog(0x534e4554, "68818034");
495 if ((rem_len <= bnep_frame_hdr_sizes[type]) || (rem_len > BNEP_MTU_SIZE))
497 BNEP_TRACE_EVENT ("BNEP - rcvd frame, bad len: %d type: 0x%02x", p_buf->len, type);
504 if ((p_bcb->con_state != BNEP_STATE_CONNECTED) &&
505 (!(p_bcb->con_flags & BNEP_FLAGS_CONN_COMPLETED)) &&
506 (type != BNEP_FRAME_CONTROL))
508 BNEP_TRACE_WARNING ("BNEP - Ignored L2CAP data while in state: %d, CID: 0x%x",
509 p_bcb->con_state, l2cap_cid);
511 if (extension_present)
514 ** When there is no connection if a data packet is received
515 ** with unknown control extension headers then those should be processed
516 ** according to complain/ignore law
519 UINT16 org_len, new_len;
520 /* parse the extension headers and process unknown control headers */
524 if (org_len < 2) break;
529 new_len = (length + 2);
530 if (new_len > org_len) break;
532 if ((!(ext & 0x7F)) && (*p > BNEP_FILTER_MULTI_ADDR_RESPONSE_MSG))
533 bnep_send_command_not_understood (p_bcb, *p);
537 } while (ext & 0x80);
538 android_errorWriteLog(0x534e4554, "67863755");
545 if (type > BNEP_FRAME_COMPRESSED_ETHERNET_DEST_ONLY)
547 BNEP_TRACE_EVENT ("BNEP - rcvd frame, unknown type: 0x%02x", type);
552 BNEP_TRACE_DEBUG ("BNEP - rcv frame, type: %d len: %d Ext: %d", type, p_buf->len, extension_present);
554 /* Initialize addresses to 'not supplied' */
555 p_src_addr = p_dst_addr = NULL;
559 case BNEP_FRAME_GENERAL_ETHERNET:
564 BE_STREAM_TO_UINT16 (protocol, p);
568 case BNEP_FRAME_CONTROL:
570 p = bnep_process_control_packet (p_bcb, p, &rem_len, FALSE);
572 if (ctrl_type == BNEP_SETUP_CONNECTION_REQUEST_MSG &&
573 p_bcb->con_state != BNEP_STATE_CONNECTED &&
574 extension_present && p && rem_len)
576 if (p_bcb->p_pending_data)
577 GKI_freebuf (p_bcb->p_pending_data);
578 p_bcb->p_pending_data = (BT_HDR *)GKI_getbuf (rem_len + sizeof(BT_HDR));
579 if (p_bcb->p_pending_data)
581 memcpy ((UINT8 *)(p_bcb->p_pending_data + 1), p, rem_len);
582 p_bcb->p_pending_data->len = rem_len;
583 p_bcb->p_pending_data->offset = 0;
588 while (extension_present && p && rem_len)
592 android_errorWriteLog(0x534e4554, "69271284");
593 extension_present = ext_type >> 7;
596 /* if unknown extension present stop processing */
600 p = bnep_process_control_packet (p_bcb, p, &rem_len, TRUE);
606 case BNEP_FRAME_COMPRESSED_ETHERNET:
607 BE_STREAM_TO_UINT16 (protocol, p);
611 case BNEP_FRAME_COMPRESSED_ETHERNET_SRC_ONLY:
614 BE_STREAM_TO_UINT16 (protocol, p);
618 case BNEP_FRAME_COMPRESSED_ETHERNET_DEST_ONLY:
621 BE_STREAM_TO_UINT16 (protocol, p);
626 /* Process the header extension if there is one */
627 while (extension_present && p && rem_len)
630 extension_present = ext_type >> 7;
633 /* if unknown extension present stop processing */
636 BNEP_TRACE_EVENT ("Data extension type 0x%x found", ext_type);
642 p = bnep_process_control_packet (p_bcb, p, &rem_len, TRUE);
645 p_buf->offset += p_buf->len - rem_len;
646 p_buf->len = rem_len;
648 /* Always give the upper layer MAC addresses */
650 p_src_addr = (UINT8 *) p_bcb->rem_bda;
653 p_dst_addr = (UINT8 *) controller_get_interface()->get_address();
655 /* check whether there are any extensions to be forwarded */
657 fw_ext_present = TRUE;
659 fw_ext_present = FALSE;
661 if (bnep_cb.p_data_buf_cb)
663 (*bnep_cb.p_data_buf_cb)(p_bcb->handle, p_src_addr, p_dst_addr, protocol, p_buf, fw_ext_present);
666 else if (bnep_cb.p_data_ind_cb)
668 (*bnep_cb.p_data_ind_cb)(p_bcb->handle, p_src_addr, p_dst_addr, protocol, p, rem_len, fw_ext_present);
675 /*******************************************************************************
677 ** Function bnep_process_timeout
679 ** Description This function processes a timeout. If it is a startup
680 ** timeout, we check for reading our BD address. If it
681 ** is an L2CAP timeout, we send a disconnect req to L2CAP.
685 *******************************************************************************/
686 void bnep_process_timeout (TIMER_LIST_ENT *p_tle)
695 p_bcb = (tBNEP_CONN *)p_tle->param;
697 BNEP_TRACE_EVENT ("BNEP - CCB timeout in state: %d CID: 0x%x flags %x, re_transmit %d",
698 p_bcb->con_state, p_bcb->l2cap_cid, p_bcb->con_flags, p_bcb->re_transmits);
700 if (p_bcb->con_state == BNEP_STATE_CONN_SETUP)
702 BNEP_TRACE_EVENT ("BNEP - CCB timeout in state: %d CID: 0x%x",
703 p_bcb->con_state, p_bcb->l2cap_cid);
705 if (!(p_bcb->con_flags & BNEP_FLAGS_IS_ORIG))
707 L2CA_DisconnectReq (p_bcb->l2cap_cid);
709 bnepu_release_bcb (p_bcb);
713 if (p_bcb->re_transmits++ != BNEP_MAX_RETRANSMITS)
715 bnep_send_conn_req (p_bcb);
716 btu_start_timer (&p_bcb->conn_tle, BTU_TTYPE_BNEP, BNEP_CONN_TIMEOUT);
720 L2CA_DisconnectReq (p_bcb->l2cap_cid);
722 if ((p_bcb->con_flags & BNEP_FLAGS_IS_ORIG) && (bnep_cb.p_conn_state_cb))
723 (*bnep_cb.p_conn_state_cb) (p_bcb->handle, p_bcb->rem_bda, BNEP_CONN_FAILED, FALSE);
725 bnepu_release_bcb (p_bcb);
729 else if (p_bcb->con_state != BNEP_STATE_CONNECTED)
731 BNEP_TRACE_EVENT ("BNEP - CCB timeout in state: %d CID: 0x%x",
732 p_bcb->con_state, p_bcb->l2cap_cid);
734 L2CA_DisconnectReq (p_bcb->l2cap_cid);
736 /* Tell the user if he has a callback */
737 if ((p_bcb->con_flags & BNEP_FLAGS_IS_ORIG) && (bnep_cb.p_conn_state_cb))
738 (*bnep_cb.p_conn_state_cb) (p_bcb->handle, p_bcb->rem_bda, BNEP_CONN_FAILED, FALSE);
740 bnepu_release_bcb (p_bcb);
742 else if (p_bcb->con_flags & BNEP_FLAGS_FILTER_RESP_PEND)
744 if (p_bcb->re_transmits++ != BNEP_MAX_RETRANSMITS)
746 bnepu_send_peer_our_filters (p_bcb);
747 btu_start_timer (&p_bcb->conn_tle, BTU_TTYPE_BNEP, BNEP_FILTER_SET_TIMEOUT);
751 L2CA_DisconnectReq (p_bcb->l2cap_cid);
753 /* Tell the user if he has a callback */
754 if (bnep_cb.p_conn_state_cb)
755 (*bnep_cb.p_conn_state_cb) (p_bcb->handle, p_bcb->rem_bda, BNEP_SET_FILTER_FAIL, FALSE);
757 bnepu_release_bcb (p_bcb);
761 else if (p_bcb->con_flags & BNEP_FLAGS_MULTI_RESP_PEND)
763 if (p_bcb->re_transmits++ != BNEP_MAX_RETRANSMITS)
765 bnepu_send_peer_our_multi_filters (p_bcb);
766 btu_start_timer (&p_bcb->conn_tle, BTU_TTYPE_BNEP, BNEP_FILTER_SET_TIMEOUT);
770 L2CA_DisconnectReq (p_bcb->l2cap_cid);
772 /* Tell the user if he has a callback */
773 if (bnep_cb.p_conn_state_cb)
774 (*bnep_cb.p_conn_state_cb) (p_bcb->handle, p_bcb->rem_bda, BNEP_SET_FILTER_FAIL, FALSE);
776 bnepu_release_bcb (p_bcb);
783 /*******************************************************************************
785 ** Function bnep_connected
787 ** Description This function is called when a connection is established
792 *******************************************************************************/
793 void bnep_connected (tBNEP_CONN *p_bcb)
795 BOOLEAN is_role_change;
797 if (p_bcb->con_flags & BNEP_FLAGS_CONN_COMPLETED)
798 is_role_change = TRUE;
800 is_role_change = FALSE;
802 p_bcb->con_state = BNEP_STATE_CONNECTED;
803 p_bcb->con_flags |= BNEP_FLAGS_CONN_COMPLETED;
804 p_bcb->con_flags &= (~BNEP_FLAGS_SETUP_RCVD);
806 /* Ensure timer is stopped */
807 btu_stop_timer (&p_bcb->conn_tle);
808 p_bcb->re_transmits = 0;
810 /* Tell the upper layer, if he has a callback */
811 if (bnep_cb.p_conn_state_cb)
812 (*bnep_cb.p_conn_state_cb) (p_bcb->handle, p_bcb->rem_bda, BNEP_SUCCESS, is_role_change);