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"
30 #include "bt_common.h"
46 #include "device/include/controller.h"
49 extern fixed_queue_t *btu_general_alarm_queue;
51 /********************************************************************************/
52 /* G L O B A L B N E P D A T A */
53 /********************************************************************************/
54 #if BNEP_DYNAMIC_MEMORY == FALSE
58 const UINT16 bnep_frame_hdr_sizes[] = {14, 1, 2, 8, 8};
60 /********************************************************************************/
61 /* L O C A L F U N C T I O N P R O T O T Y P E S */
62 /********************************************************************************/
63 static void bnep_connect_ind (BD_ADDR bd_addr, UINT16 l2cap_cid, UINT16 psm, UINT8 l2cap_id);
64 static void bnep_connect_cfm (UINT16 l2cap_cid, UINT16 result);
65 static void bnep_config_ind (UINT16 l2cap_cid, tL2CAP_CFG_INFO *p_cfg);
66 static void bnep_config_cfm (UINT16 l2cap_cid, tL2CAP_CFG_INFO *p_cfg);
67 static void bnep_disconnect_ind (UINT16 l2cap_cid, BOOLEAN ack_needed);
68 static void bnep_disconnect_cfm (UINT16 l2cap_cid, UINT16 result);
69 static void bnep_data_ind (UINT16 l2cap_cid, BT_HDR *p_msg);
70 static void bnep_congestion_ind (UINT16 lcid, BOOLEAN is_congested);
73 /*******************************************************************************
75 ** Function bnep_register_with_l2cap
77 ** Description This function registers BNEP PSM with L2CAP
81 *******************************************************************************/
82 tBNEP_RESULT bnep_register_with_l2cap (void)
84 /* Initialize the L2CAP configuration. We only care about MTU and flush */
85 memset(&bnep_cb.l2cap_my_cfg, 0, sizeof(tL2CAP_CFG_INFO));
87 bnep_cb.l2cap_my_cfg.mtu_present = TRUE;
88 bnep_cb.l2cap_my_cfg.mtu = BNEP_MTU_SIZE;
89 bnep_cb.l2cap_my_cfg.flush_to_present = TRUE;
90 bnep_cb.l2cap_my_cfg.flush_to = BNEP_FLUSH_TO;
92 bnep_cb.reg_info.pL2CA_ConnectInd_Cb = bnep_connect_ind;
93 bnep_cb.reg_info.pL2CA_ConnectCfm_Cb = bnep_connect_cfm;
94 bnep_cb.reg_info.pL2CA_ConfigInd_Cb = bnep_config_ind;
95 bnep_cb.reg_info.pL2CA_ConfigCfm_Cb = bnep_config_cfm;
96 bnep_cb.reg_info.pL2CA_DisconnectInd_Cb = bnep_disconnect_ind;
97 bnep_cb.reg_info.pL2CA_DisconnectCfm_Cb = bnep_disconnect_cfm;
98 bnep_cb.reg_info.pL2CA_DataInd_Cb = bnep_data_ind;
99 bnep_cb.reg_info.pL2CA_CongestionStatus_Cb = bnep_congestion_ind;
101 /* Now, register with L2CAP */
102 if (!L2CA_Register (BT_PSM_BNEP, &bnep_cb.reg_info))
104 BNEP_TRACE_ERROR ("BNEP - Registration failed");
105 return BNEP_SECURITY_FAIL;
112 /*******************************************************************************
114 ** Function bnep_connect_ind
116 ** Description This function handles an inbound connection indication
117 ** from L2CAP. This is the case where we are acting as a
122 *******************************************************************************/
123 static void bnep_connect_ind (BD_ADDR bd_addr, UINT16 l2cap_cid, UINT16 psm, UINT8 l2cap_id)
125 tBNEP_CONN *p_bcb = bnepu_find_bcb_by_bd_addr (bd_addr);
128 /* If we are not acting as server, or already have a connection, or have */
129 /* no more resources to handle the connection, reject the connection. */
130 if (!(bnep_cb.profile_registered) || (p_bcb)
131 || ((p_bcb = bnepu_allocate_bcb(bd_addr)) == NULL))
133 L2CA_ConnectRsp (bd_addr, l2cap_id, l2cap_cid, L2CAP_CONN_NO_PSM, 0);
137 /* Transition to the next appropriate state, waiting for config setup. */
138 p_bcb->con_state = BNEP_STATE_CFG_SETUP;
140 /* Save the L2CAP Channel ID. */
141 p_bcb->l2cap_cid = l2cap_cid;
143 /* Send response to the L2CAP layer. */
144 L2CA_ConnectRsp (bd_addr, l2cap_id, l2cap_cid, L2CAP_CONN_OK, L2CAP_CONN_OK);
146 /* Send a Configuration Request. */
147 L2CA_ConfigReq (l2cap_cid, &bnep_cb.l2cap_my_cfg);
149 /* Start timer waiting for config setup */
150 alarm_set_on_queue(p_bcb->conn_timer, BNEP_CONN_TIMEOUT_MS,
151 bnep_conn_timer_timeout, p_bcb,
152 btu_general_alarm_queue);
154 BNEP_TRACE_EVENT("BNEP - Rcvd L2CAP conn ind, CID: 0x%x", p_bcb->l2cap_cid);
159 /*******************************************************************************
161 ** Function bnep_connect_cfm
163 ** Description This function handles the connect confirm events
164 ** from L2CAP. This is the case when we are acting as a
165 ** client and have sent a connect request.
169 *******************************************************************************/
170 static void bnep_connect_cfm (UINT16 l2cap_cid, UINT16 result)
174 /* Find CCB based on CID */
175 if ((p_bcb = bnepu_find_bcb_by_cid (l2cap_cid)) == NULL)
177 BNEP_TRACE_WARNING ("BNEP - Rcvd conn cnf for unknown CID 0x%x", l2cap_cid);
181 /* If the connection response contains success status, then */
182 /* Transition to the next state and startup the timer. */
183 if ((result == L2CAP_CONN_OK) && (p_bcb->con_state == BNEP_STATE_CONN_START))
185 p_bcb->con_state = BNEP_STATE_CFG_SETUP;
187 /* Send a Configuration Request. */
188 L2CA_ConfigReq (l2cap_cid, &bnep_cb.l2cap_my_cfg);
190 /* Start timer waiting for config results */
191 alarm_set_on_queue(p_bcb->conn_timer, BNEP_CONN_TIMEOUT_MS,
192 bnep_conn_timer_timeout, p_bcb,
193 btu_general_alarm_queue);
195 BNEP_TRACE_EVENT ("BNEP - got conn cnf, sent cfg req, CID: 0x%x", p_bcb->l2cap_cid);
199 BNEP_TRACE_WARNING ("BNEP - Rcvd conn cnf with error: 0x%x CID 0x%x", result, p_bcb->l2cap_cid);
201 /* Tell the upper layer, if he has a callback */
202 if (bnep_cb.p_conn_state_cb &&
203 p_bcb->con_flags & BNEP_FLAGS_IS_ORIG)
205 (*bnep_cb.p_conn_state_cb) (p_bcb->handle, p_bcb->rem_bda, BNEP_CONN_FAILED, FALSE);
208 bnepu_release_bcb (p_bcb);
212 /*******************************************************************************
214 ** Function bnep_config_ind
216 ** Description This function processes the L2CAP configuration indication
221 *******************************************************************************/
222 static void bnep_config_ind (UINT16 l2cap_cid, tL2CAP_CFG_INFO *p_cfg)
225 UINT16 result, mtu = 0;
227 /* Find CCB based on CID */
228 if ((p_bcb = bnepu_find_bcb_by_cid (l2cap_cid)) == NULL)
230 BNEP_TRACE_WARNING ("BNEP - Rcvd L2CAP cfg ind, unknown CID: 0x%x", l2cap_cid);
234 BNEP_TRACE_EVENT ("BNEP - Rcvd cfg ind, CID: 0x%x", l2cap_cid);
236 /* Remember the remote MTU size */
237 if ((!p_cfg->mtu_present) || (p_cfg->mtu < BNEP_MIN_MTU_SIZE))
240 p_cfg->flush_to_present = FALSE;
241 p_cfg->mtu_present = TRUE;
242 p_cfg->mtu = BNEP_MIN_MTU_SIZE;
243 p_cfg->result = result = L2CAP_CFG_UNACCEPTABLE_PARAMS;
247 if (p_cfg->mtu > BNEP_MTU_SIZE)
248 p_bcb->rem_mtu_size = BNEP_MTU_SIZE;
250 p_bcb->rem_mtu_size = p_cfg->mtu;
252 /* For now, always accept configuration from the other side */
253 p_cfg->flush_to_present = FALSE;
254 p_cfg->mtu_present = FALSE;
255 p_cfg->result = result = L2CAP_CFG_OK;
258 L2CA_ConfigRsp (l2cap_cid, p_cfg);
260 if (result != L2CAP_CFG_OK)
262 BNEP_TRACE_EVENT ("BNEP - Rcvd cfg ind with bad MTU %d, CID: 0x%x", mtu, l2cap_cid);
266 p_bcb->con_flags |= BNEP_FLAGS_HIS_CFG_DONE;
268 if (p_bcb->con_flags & BNEP_FLAGS_MY_CFG_DONE)
270 p_bcb->con_state = BNEP_STATE_SEC_CHECKING;
272 /* Start timer waiting for setup or response */
273 alarm_set_on_queue(p_bcb->conn_timer, BNEP_HOST_TIMEOUT_MS,
274 bnep_conn_timer_timeout, p_bcb,
275 btu_general_alarm_queue);
277 if (p_bcb->con_flags & BNEP_FLAGS_IS_ORIG)
279 btm_sec_mx_access_request (p_bcb->rem_bda, BT_PSM_BNEP, TRUE,
281 bnep_get_uuid32(&(p_bcb->src_uuid)),
282 &bnep_sec_check_complete, p_bcb);
288 /*******************************************************************************
290 ** Function bnep_config_cfm
292 ** Description This function processes the L2CAP configuration confirmation
297 *******************************************************************************/
298 static void bnep_config_cfm (UINT16 l2cap_cid, tL2CAP_CFG_INFO *p_cfg)
302 BNEP_TRACE_EVENT ("BNEP - Rcvd cfg cfm, CID: 0x%x Result: %d", l2cap_cid, p_cfg->result);
304 /* Find CCB based on CID */
305 if ((p_bcb = bnepu_find_bcb_by_cid (l2cap_cid)) == NULL)
307 BNEP_TRACE_WARNING ("BNEP - Rcvd L2CAP cfg ind, unknown CID: 0x%x", l2cap_cid);
311 /* For now, always accept configuration from the other side */
312 if (p_cfg->result == L2CAP_CFG_OK)
314 p_bcb->con_flags |= BNEP_FLAGS_MY_CFG_DONE;
316 if (p_bcb->con_flags & BNEP_FLAGS_HIS_CFG_DONE)
318 p_bcb->con_state = BNEP_STATE_SEC_CHECKING;
320 /* Start timer waiting for setup or response */
321 alarm_set_on_queue(p_bcb->conn_timer, BNEP_HOST_TIMEOUT_MS,
322 bnep_conn_timer_timeout, p_bcb,
323 btu_general_alarm_queue);
325 if (p_bcb->con_flags & BNEP_FLAGS_IS_ORIG)
327 btm_sec_mx_access_request (p_bcb->rem_bda, BT_PSM_BNEP, TRUE,
329 bnep_get_uuid32(&(p_bcb->src_uuid)),
330 &bnep_sec_check_complete, p_bcb);
336 /* Tell the upper layer, if he has a callback */
337 if ((p_bcb->con_flags & BNEP_FLAGS_IS_ORIG) && (bnep_cb.p_conn_state_cb))
339 (*bnep_cb.p_conn_state_cb) (p_bcb->handle, p_bcb->rem_bda, BNEP_CONN_FAILED_CFG, FALSE);
342 L2CA_DisconnectReq (p_bcb->l2cap_cid);
344 bnepu_release_bcb (p_bcb);
349 /*******************************************************************************
351 ** Function bnep_disconnect_ind
353 ** Description This function handles a disconnect event from L2CAP. If
354 ** requested to, we ack the disconnect before dropping the CCB
358 *******************************************************************************/
359 static void bnep_disconnect_ind (UINT16 l2cap_cid, BOOLEAN ack_needed)
364 L2CA_DisconnectRsp (l2cap_cid);
366 /* Find CCB based on CID */
367 if ((p_bcb = bnepu_find_bcb_by_cid (l2cap_cid)) == NULL)
369 BNEP_TRACE_WARNING ("BNEP - Rcvd L2CAP disc, unknown CID: 0x%x", l2cap_cid);
373 BNEP_TRACE_EVENT ("BNEP - Rcvd L2CAP disc, CID: 0x%x", l2cap_cid);
375 /* Tell the user if he has a callback */
376 if (p_bcb->con_state == BNEP_STATE_CONNECTED)
378 if (bnep_cb.p_conn_state_cb)
379 (*bnep_cb.p_conn_state_cb)(p_bcb->handle, p_bcb->rem_bda, BNEP_CONN_DISCONNECTED, FALSE);
383 if ((bnep_cb.p_conn_state_cb) && ((p_bcb->con_flags & BNEP_FLAGS_IS_ORIG) ||
384 (p_bcb->con_flags & BNEP_FLAGS_CONN_COMPLETED)))
385 (*bnep_cb.p_conn_state_cb) (p_bcb->handle, p_bcb->rem_bda, BNEP_CONN_FAILED, FALSE);
388 bnepu_release_bcb (p_bcb);
393 /*******************************************************************************
395 ** Function bnep_disconnect_cfm
397 ** Description This function gets the disconnect confirm event from L2CAP
401 *******************************************************************************/
402 static void bnep_disconnect_cfm (UINT16 l2cap_cid, UINT16 result)
404 BNEP_TRACE_EVENT ("BNEP - Rcvd L2CAP disc cfm, CID: 0x%x, Result 0x%x", l2cap_cid, result);
409 /*******************************************************************************
411 ** Function bnep_congestion_ind
413 ** Description This is a callback function called by L2CAP when
414 ** congestion status changes
416 *******************************************************************************/
417 static void bnep_congestion_ind (UINT16 l2cap_cid, BOOLEAN is_congested)
421 /* Find BCB based on CID */
422 if ((p_bcb = bnepu_find_bcb_by_cid (l2cap_cid)) == NULL)
424 BNEP_TRACE_WARNING ("BNEP - Rcvd L2CAP cong, unknown CID: 0x%x", l2cap_cid);
430 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_OFF);
438 p_bcb->con_flags &= ~BNEP_FLAGS_L2CAP_CONGESTED;
440 if(bnep_cb.p_tx_data_flow_cb)
442 bnep_cb.p_tx_data_flow_cb(p_bcb->handle, BNEP_TX_FLOW_ON);
445 /* While not congested, send as many buffers as we can */
446 while (!(p_bcb->con_flags & BNEP_FLAGS_L2CAP_CONGESTED))
448 BT_HDR *p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_bcb->xmit_q);
453 L2CA_DataWrite (l2cap_cid, p_buf);
460 /*******************************************************************************
462 ** Function bnep_data_ind
464 ** Description This function is called when data is received from L2CAP.
465 ** if we are the originator of the connection, we are the SDP
466 ** client, and the received message is queued up for the client.
468 ** If we are the destination of the connection, we are the SDP
469 ** server, so the message is passed to the server processing
474 *******************************************************************************/
475 static void bnep_data_ind (UINT16 l2cap_cid, BT_HDR *p_buf)
478 UINT8 *p = (UINT8 *)(p_buf + 1) + p_buf->offset;
479 UINT16 rem_len = p_buf->len;
480 UINT8 type, ctrl_type, ext_type = 0;
481 BOOLEAN extension_present, fw_ext_present;
483 UINT8 *p_src_addr, *p_dst_addr;
486 /* Find CCB based on CID */
487 if ((p_bcb = bnepu_find_bcb_by_cid (l2cap_cid)) == NULL)
489 BNEP_TRACE_WARNING ("BNEP - Rcvd L2CAP data, unknown CID: 0x%x", l2cap_cid);
494 /* Get the type and extension bits */
496 extension_present = type >> 7;
498 if ((rem_len <= bnep_frame_hdr_sizes[type]) || (rem_len > BNEP_MTU_SIZE))
500 BNEP_TRACE_EVENT ("BNEP - rcvd frame, bad len: %d type: 0x%02x", p_buf->len, type);
507 if ((p_bcb->con_state != BNEP_STATE_CONNECTED) &&
508 (!(p_bcb->con_flags & BNEP_FLAGS_CONN_COMPLETED)) &&
509 (type != BNEP_FRAME_CONTROL))
511 BNEP_TRACE_WARNING ("BNEP - Ignored L2CAP data while in state: %d, CID: 0x%x",
512 p_bcb->con_state, l2cap_cid);
514 if (extension_present)
517 ** When there is no connection if a data packet is received
518 ** with unknown control extension headers then those should be processed
519 ** according to complain/ignore law
522 UINT16 org_len, new_len;
523 /* parse the extension headers and process unknown control headers */
532 if ((!(ext & 0x7F)) && (*p > BNEP_FILTER_MULTI_ADDR_RESPONSE_MSG))
533 bnep_send_command_not_understood (p_bcb, *p);
535 new_len += (length + 2);
537 if (new_len > org_len)
540 } while (ext & 0x80);
547 if (type > BNEP_FRAME_COMPRESSED_ETHERNET_DEST_ONLY)
549 BNEP_TRACE_EVENT ("BNEP - rcvd frame, unknown type: 0x%02x", type);
554 BNEP_TRACE_DEBUG ("BNEP - rcv frame, type: %d len: %d Ext: %d", type, p_buf->len, extension_present);
556 /* Initialize addresses to 'not supplied' */
557 p_src_addr = p_dst_addr = NULL;
561 case BNEP_FRAME_GENERAL_ETHERNET:
566 BE_STREAM_TO_UINT16 (protocol, p);
570 case BNEP_FRAME_CONTROL:
572 p = bnep_process_control_packet (p_bcb, p, &rem_len, FALSE);
574 if (ctrl_type == BNEP_SETUP_CONNECTION_REQUEST_MSG &&
575 p_bcb->con_state != BNEP_STATE_CONNECTED &&
576 extension_present && p && rem_len)
578 osi_free(p_bcb->p_pending_data);
579 p_bcb->p_pending_data = (BT_HDR *)osi_malloc(rem_len + sizeof(BT_HDR));
580 memcpy((UINT8 *)(p_bcb->p_pending_data + 1), p, rem_len);
581 p_bcb->p_pending_data->len = rem_len;
582 p_bcb->p_pending_data->offset = 0;
586 while (extension_present && p && rem_len)
589 extension_present = ext_type >> 7;
592 /* if unknown extension present stop processing */
596 p = bnep_process_control_packet (p_bcb, p, &rem_len, TRUE);
602 case BNEP_FRAME_COMPRESSED_ETHERNET:
603 BE_STREAM_TO_UINT16 (protocol, p);
607 case BNEP_FRAME_COMPRESSED_ETHERNET_SRC_ONLY:
610 BE_STREAM_TO_UINT16 (protocol, p);
614 case BNEP_FRAME_COMPRESSED_ETHERNET_DEST_ONLY:
617 BE_STREAM_TO_UINT16 (protocol, p);
622 /* Process the header extension if there is one */
623 while (extension_present && p && rem_len)
626 extension_present = ext_type >> 7;
629 /* if unknown extension present stop processing */
632 BNEP_TRACE_EVENT ("Data extension type 0x%x found", ext_type);
638 p = bnep_process_control_packet (p_bcb, p, &rem_len, TRUE);
641 p_buf->offset += p_buf->len - rem_len;
642 p_buf->len = rem_len;
644 /* Always give the upper layer MAC addresses */
646 p_src_addr = (UINT8 *) p_bcb->rem_bda;
649 p_dst_addr = (UINT8 *) controller_get_interface()->get_address();
651 /* check whether there are any extensions to be forwarded */
653 fw_ext_present = TRUE;
655 fw_ext_present = FALSE;
657 if (bnep_cb.p_data_buf_cb)
659 (*bnep_cb.p_data_buf_cb)(p_bcb->handle, p_src_addr, p_dst_addr, protocol, p_buf, fw_ext_present);
661 else if (bnep_cb.p_data_ind_cb)
663 (*bnep_cb.p_data_ind_cb)(p_bcb->handle, p_src_addr, p_dst_addr, protocol, p, rem_len, fw_ext_present);
670 /*******************************************************************************
672 ** Function bnep_conn_timer_timeout
674 ** Description This function processes a timeout. If it is a startup
675 ** timeout, we check for reading our BD address. If it
676 ** is an L2CAP timeout, we send a disconnect req to L2CAP.
680 *******************************************************************************/
681 void bnep_conn_timer_timeout(void *data)
683 tBNEP_CONN *p_bcb = (tBNEP_CONN *)data;
685 BNEP_TRACE_EVENT ("BNEP - CCB timeout in state: %d CID: 0x%x flags %x, re_transmit %d",
686 p_bcb->con_state, p_bcb->l2cap_cid, p_bcb->con_flags, p_bcb->re_transmits);
688 if (p_bcb->con_state == BNEP_STATE_CONN_SETUP)
690 BNEP_TRACE_EVENT ("BNEP - CCB timeout in state: %d CID: 0x%x",
691 p_bcb->con_state, p_bcb->l2cap_cid);
693 if (!(p_bcb->con_flags & BNEP_FLAGS_IS_ORIG))
695 L2CA_DisconnectReq (p_bcb->l2cap_cid);
697 bnepu_release_bcb (p_bcb);
701 if (p_bcb->re_transmits++ != BNEP_MAX_RETRANSMITS)
703 bnep_send_conn_req (p_bcb);
704 alarm_set_on_queue(p_bcb->conn_timer, BNEP_CONN_TIMEOUT_MS,
705 bnep_conn_timer_timeout, p_bcb,
706 btu_general_alarm_queue);
710 L2CA_DisconnectReq (p_bcb->l2cap_cid);
712 if ((p_bcb->con_flags & BNEP_FLAGS_IS_ORIG) && (bnep_cb.p_conn_state_cb))
713 (*bnep_cb.p_conn_state_cb) (p_bcb->handle, p_bcb->rem_bda, BNEP_CONN_FAILED, FALSE);
715 bnepu_release_bcb (p_bcb);
719 else if (p_bcb->con_state != BNEP_STATE_CONNECTED)
721 BNEP_TRACE_EVENT ("BNEP - CCB timeout in state: %d CID: 0x%x",
722 p_bcb->con_state, p_bcb->l2cap_cid);
724 L2CA_DisconnectReq (p_bcb->l2cap_cid);
726 /* Tell the user if he has a callback */
727 if ((p_bcb->con_flags & BNEP_FLAGS_IS_ORIG) && (bnep_cb.p_conn_state_cb))
728 (*bnep_cb.p_conn_state_cb) (p_bcb->handle, p_bcb->rem_bda, BNEP_CONN_FAILED, FALSE);
730 bnepu_release_bcb (p_bcb);
732 else if (p_bcb->con_flags & BNEP_FLAGS_FILTER_RESP_PEND)
734 if (p_bcb->re_transmits++ != BNEP_MAX_RETRANSMITS)
736 bnepu_send_peer_our_filters (p_bcb);
737 alarm_set_on_queue(p_bcb->conn_timer, BNEP_FILTER_SET_TIMEOUT_MS,
738 bnep_conn_timer_timeout, p_bcb,
739 btu_general_alarm_queue);
743 L2CA_DisconnectReq (p_bcb->l2cap_cid);
745 /* Tell the user if he has a callback */
746 if (bnep_cb.p_conn_state_cb)
747 (*bnep_cb.p_conn_state_cb) (p_bcb->handle, p_bcb->rem_bda, BNEP_SET_FILTER_FAIL, FALSE);
749 bnepu_release_bcb (p_bcb);
753 else if (p_bcb->con_flags & BNEP_FLAGS_MULTI_RESP_PEND)
755 if (p_bcb->re_transmits++ != BNEP_MAX_RETRANSMITS)
757 bnepu_send_peer_our_multi_filters (p_bcb);
758 alarm_set_on_queue(p_bcb->conn_timer, BNEP_FILTER_SET_TIMEOUT_MS,
759 bnep_conn_timer_timeout, p_bcb,
760 btu_general_alarm_queue);
764 L2CA_DisconnectReq (p_bcb->l2cap_cid);
766 /* Tell the user if he has a callback */
767 if (bnep_cb.p_conn_state_cb)
768 (*bnep_cb.p_conn_state_cb) (p_bcb->handle, p_bcb->rem_bda, BNEP_SET_FILTER_FAIL, FALSE);
770 bnepu_release_bcb (p_bcb);
777 /*******************************************************************************
779 ** Function bnep_connected
781 ** Description This function is called when a connection is established
786 *******************************************************************************/
787 void bnep_connected (tBNEP_CONN *p_bcb)
789 BOOLEAN is_role_change;
791 if (p_bcb->con_flags & BNEP_FLAGS_CONN_COMPLETED)
792 is_role_change = TRUE;
794 is_role_change = FALSE;
796 p_bcb->con_state = BNEP_STATE_CONNECTED;
797 p_bcb->con_flags |= BNEP_FLAGS_CONN_COMPLETED;
798 p_bcb->con_flags &= (~BNEP_FLAGS_SETUP_RCVD);
800 /* Ensure timer is stopped */
801 alarm_cancel(p_bcb->conn_timer);
802 p_bcb->re_transmits = 0;
804 /* Tell the upper layer, if he has a callback */
805 if (bnep_cb.p_conn_state_cb)
806 (*bnep_cb.p_conn_state_cb) (p_bcb->handle, p_bcb->rem_bda, BNEP_SUCCESS, is_role_change);