/******************************************************************************* ** ** Function L2CA_UcdRegister ** ** Description Register PSM on UCD. ** ** Parameters: tL2CAP_UCD_CB_INFO ** ** Return value: TRUE if successs ** *******************************************************************************/ BOOLEAN L2CA_UcdRegister ( UINT16 psm, tL2CAP_UCD_CB_INFO *p_cb_info ) { tL2C_RCB *p_rcb; L2CAP_TRACE_API ("L2CA_UcdRegister() PSM: 0x%04x", psm); if ((!p_cb_info->pL2CA_UCD_Discover_Cb) || (!p_cb_info->pL2CA_UCD_Data_Cb)) { L2CAP_TRACE_ERROR ("L2CAP - no callback registering PSM(0x%04x) on UCD", psm); return (FALSE); } if ((p_rcb = l2cu_find_rcb_by_psm (psm)) == NULL) { L2CAP_TRACE_ERROR ("L2CAP - no RCB for L2CA_UcdRegister, PSM: 0x%04x", psm); return (FALSE); } p_rcb->ucd.state = L2C_UCD_STATE_W4_DATA; p_rcb->ucd.cb_info = *p_cb_info; /* check if master rcb is created for UCD */ if ((p_rcb = l2cu_find_rcb_by_psm (L2C_UCD_RCB_ID)) == NULL) { if ((p_rcb = l2cu_allocate_rcb (L2C_UCD_RCB_ID)) == NULL) { L2CAP_TRACE_ERROR ("L2CAP - no RCB available for L2CA_UcdRegister"); return (FALSE); } else { /* these callback functions will forward data to each UCD application */ p_rcb->ucd.cb_info.pL2CA_UCD_Discover_Cb = l2c_ucd_discover_cback; p_rcb->ucd.cb_info.pL2CA_UCD_Data_Cb = l2c_ucd_data_ind_cback; p_rcb->ucd.cb_info.pL2CA_UCD_Congestion_Status_Cb = l2c_ucd_congestion_status_cback; memset (&p_rcb->api, 0, sizeof(tL2CAP_APPL_INFO)); p_rcb->api.pL2CA_DisconnectInd_Cb = l2c_ucd_disconnect_ind_cback; /* This will make L2CAP check UCD congestion callback */ p_rcb->api.pL2CA_CongestionStatus_Cb = NULL; /* do nothing but prevent crash */ p_rcb->api.pL2CA_ConfigInd_Cb = l2c_ucd_config_ind_cback; p_rcb->api.pL2CA_ConfigCfm_Cb = l2c_ucd_config_cfm_cback; } } return (TRUE); }
/******************************************************************************* ** ** Function L2CA_UcdDeregister ** ** Description Deregister PSM on UCD. ** ** Parameters: PSM ** ** Return value: TRUE if successs ** *******************************************************************************/ BOOLEAN L2CA_UcdDeregister ( UINT16 psm ) { tL2C_CCB *p_ccb; tL2C_RCB *p_rcb; UINT16 xx; L2CAP_TRACE_API ("L2CA_UcdDeregister() PSM: 0x%04x", psm); if ((p_rcb = l2cu_find_rcb_by_psm (psm)) == NULL) { L2CAP_TRACE_ERROR ("L2CAP - no RCB for L2CA_UcdDeregister, PSM: 0x%04x", psm); return (FALSE); } p_rcb->ucd.state = L2C_UCD_STATE_UNUSED; /* check this was the last UCD registration */ p_rcb = &l2cb.rcb_pool[0]; for (xx = 0; xx < MAX_L2CAP_CLIENTS; xx++, p_rcb++) { if ((p_rcb->in_use) && (p_rcb->ucd.state != L2C_UCD_STATE_UNUSED)) { return (TRUE); } } /* delete master rcb for UCD */ if ((p_rcb = l2cu_find_rcb_by_psm (L2C_UCD_RCB_ID)) != NULL) { l2cu_release_rcb (p_rcb); } /* delete CCB for UCD */ p_ccb = l2cb.ccb_pool; for ( xx = 0; xx < MAX_L2CAP_CHANNELS; xx++ ) { if (( p_ccb->in_use ) && ( p_ccb->local_cid == L2CAP_CONNECTIONLESS_CID )) { l2cu_release_ccb (p_ccb); } p_ccb++; } return (TRUE); }
/******************************************************************************* ** ** Function L2CA_UcdDiscover ** ** Description Discover UCD of remote device. ** ** Parameters: PSM ** BD_ADDR of remote device ** info_type : L2CAP_UCD_INFO_TYPE_RECEPTION ** L2CAP_UCD_INFO_TYPE_MTU ** ** ** Return value: TRUE if successs ** *******************************************************************************/ BOOLEAN L2CA_UcdDiscover ( UINT16 psm, BD_ADDR rem_bda, UINT8 info_type ) { tL2C_LCB *p_lcb; tL2C_CCB *p_ccb; tL2C_RCB *p_rcb; L2CAP_TRACE_API ("L2CA_UcdDiscover() PSM: 0x%04x BDA: %08x%04x, InfoType=0x%02x", psm, (rem_bda[0] << 24) + (rem_bda[1] << 16) + (rem_bda[2] << 8) + rem_bda[3], (rem_bda[4] << 8) + rem_bda[5], info_type); /* Fail if the PSM is not registered */ if (((p_rcb = l2cu_find_rcb_by_psm (psm)) == NULL) || ( p_rcb->ucd.state == L2C_UCD_STATE_UNUSED )) { L2CAP_TRACE_WARNING ("L2CAP - no RCB for L2CA_UcdDiscover, PSM: 0x%04x", psm); return (FALSE); } /* First, see if we already have a link to the remote */ /* then find the channel control block for UCD. */ if (((p_lcb = l2cu_find_lcb_by_bd_addr (rem_bda, BT_TRANSPORT_BR_EDR)) == NULL) || ((p_ccb = l2cu_find_ccb_by_cid (p_lcb, L2CAP_CONNECTIONLESS_CID)) == NULL)) { if ( l2c_ucd_connect (rem_bda) == FALSE ) { return (FALSE); } } /* set waiting flags in rcb */ if ( info_type & L2CAP_UCD_INFO_TYPE_RECEPTION ) { p_rcb->ucd.state |= L2C_UCD_STATE_W4_RECEPTION; } if ( info_type & L2CAP_UCD_INFO_TYPE_MTU ) { p_rcb->ucd.state |= L2C_UCD_STATE_W4_MTU; } /* if link is already established */ if ((p_lcb) && (p_lcb->link_state == LST_CONNECTED)) { if (!p_ccb) { p_ccb = l2cu_find_ccb_by_cid (p_lcb, L2CAP_CONNECTIONLESS_CID); } l2c_ucd_check_pending_info_req(p_ccb); } return (TRUE); }
/******************************************************************************* ** ** Function l2c_ucd_data_ind_cback ** ** Description UCD Data callback ** ** Returns void ** *******************************************************************************/ static void l2c_ucd_data_ind_cback (BD_ADDR rem_bda, BT_HDR *p_buf) { UINT8 *p; UINT16 psm; tL2C_RCB *p_rcb; L2CAP_TRACE_DEBUG ("L2CAP - l2c_ucd_data_ind_cback"); p = (UINT8 *)(p_buf + 1) + p_buf->offset; STREAM_TO_UINT16(psm, p) p_buf->offset += L2CAP_UCD_OVERHEAD; p_buf->len -= L2CAP_UCD_OVERHEAD; if ((p_rcb = l2cu_find_rcb_by_psm (psm)) == NULL) { L2CAP_TRACE_ERROR ("L2CAP - no RCB for l2c_ucd_data_ind_cback, PSM: 0x%04x", psm); osi_free (p_buf); } else { p_rcb->ucd.cb_info.pL2CA_UCD_Data_Cb(rem_bda, p_buf); } }
/******************************************************************************* ** ** Function l2c_ucd_connect ** ** Description Connect UCD to remote device. ** ** Parameters: BD_ADDR of remote device ** ** Return value: TRUE if successs ** *******************************************************************************/ static BOOLEAN l2c_ucd_connect ( BD_ADDR rem_bda ) { tL2C_LCB *p_lcb; tL2C_CCB *p_ccb; tL2C_RCB *p_rcb; L2CAP_TRACE_DEBUG ("l2c_ucd_connect() BDA: %08x%04x", (rem_bda[0] << 24) + (rem_bda[1] << 16) + (rem_bda[2] << 8) + rem_bda[3], (rem_bda[4] << 8) + rem_bda[5]); /* Fail if we have not established communications with the controller */ if (!BTM_IsDeviceUp()) { L2CAP_TRACE_WARNING ("l2c_ucd_connect - BTU not ready"); return (FALSE); } /* First, see if we already have a link to the remote */ if ((p_lcb = l2cu_find_lcb_by_bd_addr (rem_bda, BT_TRANSPORT_BR_EDR)) == NULL) { /* No link. Get an LCB and start link establishment */ if ( ((p_lcb = l2cu_allocate_lcb (rem_bda, FALSE, BT_TRANSPORT_BR_EDR)) == NULL) || (l2cu_create_conn(p_lcb, BT_TRANSPORT_BR_EDR) == FALSE) ) { L2CAP_TRACE_WARNING ("L2CAP - conn not started l2c_ucd_connect"); return (FALSE); } } else if ( p_lcb->info_rx_bits & (1 << L2CAP_EXTENDED_FEATURES_INFO_TYPE) ) { if (!(p_lcb->peer_ext_fea & L2CAP_EXTFEA_UCD_RECEPTION)) { L2CAP_TRACE_WARNING ("L2CAP - UCD is not supported by peer, l2c_ucd_connect"); return (FALSE); } } /* Find the channel control block. */ if ((p_ccb = l2cu_find_ccb_by_cid (p_lcb, L2CAP_CONNECTIONLESS_CID)) == NULL) { /* Allocate a channel control block */ if ((p_ccb = l2cu_allocate_ccb (p_lcb, 0)) == NULL) { L2CAP_TRACE_WARNING ("L2CAP - no CCB for l2c_ucd_connect"); return (FALSE); } else { /* Set CID for the connection */ p_ccb->local_cid = L2CAP_CONNECTIONLESS_CID; p_ccb->remote_cid = L2CAP_CONNECTIONLESS_CID; /* Set the default idle timeout value to use */ p_ccb->fixed_chnl_idle_tout = L2CAP_UCD_IDLE_TIMEOUT; /* Set the default channel priority value to use */ l2cu_change_pri_ccb (p_ccb, L2CAP_UCD_CH_PRIORITY); if ((p_rcb = l2cu_find_rcb_by_psm (L2C_UCD_RCB_ID)) == NULL) { L2CAP_TRACE_WARNING ("L2CAP - no UCD registered, l2c_ucd_connect"); return (FALSE); } /* Save UCD registration info */ p_ccb->p_rcb = p_rcb; /* There is no configuration, so if the link is up, the channel is up */ if (p_lcb->link_state == LST_CONNECTED) { p_ccb->chnl_state = CST_OPEN; } } } return (TRUE); }
/******************************************************************************* ** ** Function L2CA_UcdDataWrite ** ** Description Send UCD to remote device ** ** Parameters: PSM ** BD Address of remote ** Pointer to buffer of type BT_HDR ** flags : L2CAP_FLUSHABLE_CH_BASED ** L2CAP_FLUSHABLE_PKT ** L2CAP_NON_FLUSHABLE_PKT ** ** Return value L2CAP_DW_SUCCESS, if data accepted ** L2CAP_DW_FAILED, if error ** *******************************************************************************/ UINT16 L2CA_UcdDataWrite (UINT16 psm, BD_ADDR rem_bda, BT_HDR *p_buf, UINT16 flags) { tL2C_LCB *p_lcb; tL2C_CCB *p_ccb; tL2C_RCB *p_rcb; UINT8 *p; L2CAP_TRACE_API ("L2CA_UcdDataWrite() PSM: 0x%04x BDA: %08x%04x", psm, (rem_bda[0] << 24) + (rem_bda[1] << 16) + (rem_bda[2] << 8) + rem_bda[3], (rem_bda[4] << 8) + rem_bda[5]); /* Fail if the PSM is not registered */ if (((p_rcb = l2cu_find_rcb_by_psm (psm)) == NULL) || ( p_rcb->ucd.state == L2C_UCD_STATE_UNUSED )) { L2CAP_TRACE_WARNING ("L2CAP - no RCB for L2CA_UcdDataWrite, PSM: 0x%04x", psm); osi_free (p_buf); return (L2CAP_DW_FAILED); } /* First, see if we already have a link to the remote */ /* then find the channel control block for UCD */ if (((p_lcb = l2cu_find_lcb_by_bd_addr (rem_bda, BT_TRANSPORT_BR_EDR)) == NULL) || ((p_ccb = l2cu_find_ccb_by_cid (p_lcb, L2CAP_CONNECTIONLESS_CID)) == NULL)) { if ( l2c_ucd_connect (rem_bda) == FALSE ) { osi_free (p_buf); return (L2CAP_DW_FAILED); } /* If we still don't have lcb and ccb after connect attempt, then can't proceed */ if (((p_lcb = l2cu_find_lcb_by_bd_addr (rem_bda, BT_TRANSPORT_BR_EDR)) == NULL) || ((p_ccb = l2cu_find_ccb_by_cid (p_lcb, L2CAP_CONNECTIONLESS_CID)) == NULL)) { osi_free (p_buf); return (L2CAP_DW_FAILED); } } /* write PSM */ p_buf->offset -= L2CAP_UCD_OVERHEAD; p_buf->len += L2CAP_UCD_OVERHEAD; p = (UINT8 *)(p_buf + 1) + p_buf->offset; UINT16_TO_STREAM (p, psm); /* UCD MTU check */ if ((p_lcb->ucd_mtu) && (p_buf->len > p_lcb->ucd_mtu)) { L2CAP_TRACE_WARNING ("L2CAP - Handle: 0x%04x UCD bigger than peer's UCD mtu size cannot be sent", p_lcb->handle); osi_free (p_buf); return (L2CAP_DW_FAILED); } /* If already congested, do not accept any more packets */ if (p_ccb->cong_sent) { L2CAP_TRACE_ERROR ("L2CAP - Handle: 0x%04x UCD cannot be sent, already congested count: %u buff_quota: %u", p_lcb->handle, (fixed_queue_length(p_ccb->xmit_hold_q) + fixed_queue_length(p_lcb->ucd_out_sec_pending_q)), p_ccb->buff_quota); osi_free (p_buf); return (L2CAP_DW_FAILED); } /* channel based, packet based flushable or non-flushable */ p_buf->layer_specific = flags; l2c_csm_execute (p_ccb, L2CEVT_L2CA_DATA_WRITE, p_buf); if (p_ccb->cong_sent) { return (L2CAP_DW_CONGESTED); } else { return (L2CAP_DW_SUCCESS); } }
/******************************************************************************* ** ** Function process_l2cap_cmd ** ** Description This function is called when a packet is received on the ** L2CAP signalling CID ** ** Returns void ** *******************************************************************************/ static void process_l2cap_cmd (tL2C_LCB *p_lcb, UINT8 *p, UINT16 pkt_len) { UINT8 *p_pkt_end, *p_next_cmd, *p_cfg_end, *p_cfg_start; UINT8 cmd_code, cfg_code, cfg_len, id; tL2C_CONN_INFO con_info; tL2CAP_CFG_INFO cfg_info; UINT16 rej_reason, rej_mtu, lcid, rcid, info_type; tL2C_CCB *p_ccb; tL2C_RCB *p_rcb; BOOLEAN cfg_rej; UINT16 cfg_rej_len, cmd_len; UINT16 result; tL2C_CONN_INFO ci; #if (defined BLE_INCLUDED && BLE_INCLUDED == TRUE) /* if l2cap command received in CID 1 on top of an LE link, ignore this command */ if (p_lcb->is_ble_link) return; #endif p_next_cmd = p; p_pkt_end = p + pkt_len; memset (&cfg_info, 0, sizeof(cfg_info)); /* An L2CAP packet may contain multiple commands */ while (TRUE) { /* Smallest command is 4 bytes */ if ((p = p_next_cmd) > (p_pkt_end - 4)) break; STREAM_TO_UINT8 (cmd_code, p); STREAM_TO_UINT8 (id, p); STREAM_TO_UINT16 (cmd_len, p); if(cmd_len > GKI_BUF2_SIZE) { L2CAP_TRACE_WARNING0 ("L2CAP - Invalid MTU Size"); l2cu_send_peer_cmd_reject (p_lcb, L2CAP_CMD_REJ_MTU_EXCEEDED, id, 0, 0); return; } /* Check command length does not exceed packet length */ if ((p_next_cmd = p + cmd_len) > p_pkt_end) { L2CAP_TRACE_WARNING3 ("Command len bad pkt_len: %d cmd_len: %d code: %d", pkt_len, cmd_len, cmd_code); break; } switch (cmd_code) { case L2CAP_CMD_REJECT: STREAM_TO_UINT16 (rej_reason, p); if (rej_reason == L2CAP_CMD_REJ_MTU_EXCEEDED) { STREAM_TO_UINT16 (rej_mtu, p); /* What to do with the MTU reject ? We have negotiated an MTU. For now */ /* we will ignore it and let a higher protocol timeout take care of it */ L2CAP_TRACE_WARNING2 ("L2CAP - MTU rej Handle: %d MTU: %d", p_lcb->handle, rej_mtu); } if (rej_reason == L2CAP_CMD_REJ_INVALID_CID) { STREAM_TO_UINT16 (rcid, p); STREAM_TO_UINT16 (lcid, p); L2CAP_TRACE_WARNING2 ("L2CAP - rej with CID invalid, LCID: 0x%04x RCID: 0x%04x", lcid, rcid); /* Remote CID invalid. Treat as a disconnect */ if (((p_ccb = l2cu_find_ccb_by_cid (p_lcb, lcid)) != NULL) && (p_ccb->remote_cid == rcid)) { /* Fake link disconnect - no reply is generated */ l2c_csm_execute (p_ccb, L2CEVT_LP_DISCONNECT_IND, NULL); } } /* SonyEricsson Info request Bug workaround (Continue connection) */ else if (rej_reason == L2CAP_CMD_REJ_NOT_UNDERSTOOD && p_lcb->w4_info_rsp) { btu_stop_timer (&p_lcb->info_timer_entry); p_lcb->w4_info_rsp = FALSE; ci.status = HCI_SUCCESS; memcpy (ci.bd_addr, p_lcb->remote_bd_addr, sizeof(BD_ADDR)); /* For all channels, send the event through their FSMs */ for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb; p_ccb = p_ccb->p_next_ccb) { l2c_csm_execute (p_ccb, L2CEVT_L2CAP_INFO_RSP, &ci); } } break; case L2CAP_CMD_CONN_REQ: STREAM_TO_UINT16 (con_info.psm, p); STREAM_TO_UINT16 (rcid, p); if ((p_rcb = l2cu_find_rcb_by_psm (con_info.psm)) == NULL) { L2CAP_TRACE_WARNING1 ("L2CAP - rcvd conn req for unknown PSM: %d", con_info.psm); l2cu_reject_connection (p_lcb, rcid, id, L2CAP_CONN_NO_PSM); break; } else { if (!p_rcb->api.pL2CA_ConnectInd_Cb) { L2CAP_TRACE_WARNING1 ("L2CAP - rcvd conn req for outgoing-only connection PSM: %d", con_info.psm); l2cu_reject_connection (p_lcb, rcid, id, L2CAP_CONN_NO_PSM); break; } } if ((p_ccb = l2cu_allocate_ccb (p_lcb, 0)) == NULL) { L2CAP_TRACE_ERROR0 ("L2CAP - unable to allocate CCB"); l2cu_reject_connection (p_lcb, rcid, id, L2CAP_CONN_NO_RESOURCES); break; } p_ccb->remote_id = id; p_ccb->p_rcb = p_rcb; p_ccb->remote_cid = rcid; l2c_csm_execute(p_ccb, L2CEVT_L2CAP_CONNECT_REQ, &con_info); break; case L2CAP_CMD_CONN_RSP: STREAM_TO_UINT16 (con_info.remote_cid, p); STREAM_TO_UINT16 (lcid, p); STREAM_TO_UINT16 (con_info.l2cap_result, p); STREAM_TO_UINT16 (con_info.l2cap_status, p); if ((p_ccb = l2cu_find_ccb_by_cid (p_lcb, lcid)) == NULL) { L2CAP_TRACE_WARNING2 ("L2CAP - no CCB for conn rsp, LCID: %d RCID: %d", lcid, con_info.remote_cid); break; } if (p_ccb->local_id != id) { L2CAP_TRACE_WARNING2 ("L2CAP - con rsp - bad ID. Exp: %d Got: %d", p_ccb->local_id, id); break; } if (con_info.l2cap_result == L2CAP_CONN_OK) l2c_csm_execute(p_ccb, L2CEVT_L2CAP_CONNECT_RSP, &con_info); else if (con_info.l2cap_result == L2CAP_CONN_PENDING) l2c_csm_execute(p_ccb, L2CEVT_L2CAP_CONNECT_RSP_PND, &con_info); else l2c_csm_execute(p_ccb, L2CEVT_L2CAP_CONNECT_RSP_NEG, &con_info); break; case L2CAP_CMD_CONFIG_REQ: p_cfg_end = p + cmd_len; cfg_rej = FALSE; cfg_rej_len = 0; STREAM_TO_UINT16 (lcid, p); STREAM_TO_UINT16 (cfg_info.flags, p); p_cfg_start = p; cfg_info.flush_to_present = cfg_info.mtu_present = cfg_info.qos_present = cfg_info.fcr_present = cfg_info.fcs_present = FALSE; while (p < p_cfg_end) { STREAM_TO_UINT8 (cfg_code, p); STREAM_TO_UINT8 (cfg_len, p); switch (cfg_code & 0x7F) { case L2CAP_CFG_TYPE_MTU: cfg_info.mtu_present = TRUE; STREAM_TO_UINT16 (cfg_info.mtu, p); break; case L2CAP_CFG_TYPE_FLUSH_TOUT: cfg_info.flush_to_present = TRUE; STREAM_TO_UINT16 (cfg_info.flush_to, p); break; case L2CAP_CFG_TYPE_QOS: cfg_info.qos_present = TRUE; STREAM_TO_UINT8 (cfg_info.qos.qos_flags, p); STREAM_TO_UINT8 (cfg_info.qos.service_type, p); STREAM_TO_UINT32 (cfg_info.qos.token_rate, p); STREAM_TO_UINT32 (cfg_info.qos.token_bucket_size, p); STREAM_TO_UINT32 (cfg_info.qos.peak_bandwidth, p); STREAM_TO_UINT32 (cfg_info.qos.latency, p); STREAM_TO_UINT32 (cfg_info.qos.delay_variation, p); break; case L2CAP_CFG_TYPE_FCR: cfg_info.fcr_present = TRUE; STREAM_TO_UINT8 (cfg_info.fcr.mode, p); STREAM_TO_UINT8 (cfg_info.fcr.tx_win_sz, p); STREAM_TO_UINT8 (cfg_info.fcr.max_transmit, p); STREAM_TO_UINT16 (cfg_info.fcr.rtrans_tout, p); STREAM_TO_UINT16 (cfg_info.fcr.mon_tout, p); STREAM_TO_UINT16 (cfg_info.fcr.mps, p); break; case L2CAP_CFG_TYPE_FCS: cfg_info.fcs_present = TRUE; STREAM_TO_UINT8 (cfg_info.fcs, p); break; case L2CAP_CFG_TYPE_EXT_FLOW: cfg_info.ext_flow_spec_present = TRUE; STREAM_TO_UINT8 (cfg_info.ext_flow_spec.id, p); STREAM_TO_UINT8 (cfg_info.ext_flow_spec.stype, p); STREAM_TO_UINT16 (cfg_info.ext_flow_spec.max_sdu_size, p); STREAM_TO_UINT32 (cfg_info.ext_flow_spec.sdu_inter_time, p); STREAM_TO_UINT32 (cfg_info.ext_flow_spec.access_latency, p); STREAM_TO_UINT32 (cfg_info.ext_flow_spec.flush_timeout, p); break; default: /* sanity check option length */ if ((cfg_len + L2CAP_CFG_OPTION_OVERHEAD) <= cmd_len) { p += cfg_len; if ((cfg_code & 0x80) == 0) { cfg_rej_len += cfg_len + L2CAP_CFG_OPTION_OVERHEAD; cfg_rej = TRUE; } } /* bad length; force loop exit */ else { p = p_cfg_end; cfg_rej = TRUE; } break; } } if ((p_ccb = l2cu_find_ccb_by_cid (p_lcb, lcid)) != NULL) { p_ccb->remote_id = id; if (cfg_rej) { l2cu_send_peer_config_rej (p_ccb, p_cfg_start, (UINT16) (cmd_len - L2CAP_CONFIG_REQ_LEN), cfg_rej_len); } else { l2c_csm_execute (p_ccb, L2CEVT_L2CAP_CONFIG_REQ, &cfg_info); } } else { /* updated spec says send command reject on invalid cid */ l2cu_send_peer_cmd_reject (p_lcb, L2CAP_CMD_REJ_INVALID_CID, id, 0, 0); } break; case L2CAP_CMD_CONFIG_RSP: p_cfg_end = p + cmd_len; STREAM_TO_UINT16 (lcid, p); STREAM_TO_UINT16 (cfg_info.flags, p); STREAM_TO_UINT16 (cfg_info.result, p); cfg_info.flush_to_present = cfg_info.mtu_present = cfg_info.qos_present = cfg_info.fcr_present = cfg_info.fcs_present = FALSE; while (p < p_cfg_end) { STREAM_TO_UINT8 (cfg_code, p); STREAM_TO_UINT8 (cfg_len, p); switch (cfg_code & 0x7F) { case L2CAP_CFG_TYPE_MTU: cfg_info.mtu_present = TRUE; STREAM_TO_UINT16 (cfg_info.mtu, p); break; case L2CAP_CFG_TYPE_FLUSH_TOUT: cfg_info.flush_to_present = TRUE; STREAM_TO_UINT16 (cfg_info.flush_to, p); break; case L2CAP_CFG_TYPE_QOS: cfg_info.qos_present = TRUE; STREAM_TO_UINT8 (cfg_info.qos.qos_flags, p); STREAM_TO_UINT8 (cfg_info.qos.service_type, p); STREAM_TO_UINT32 (cfg_info.qos.token_rate, p); STREAM_TO_UINT32 (cfg_info.qos.token_bucket_size, p); STREAM_TO_UINT32 (cfg_info.qos.peak_bandwidth, p); STREAM_TO_UINT32 (cfg_info.qos.latency, p); STREAM_TO_UINT32 (cfg_info.qos.delay_variation, p); break; case L2CAP_CFG_TYPE_FCR: cfg_info.fcr_present = TRUE; STREAM_TO_UINT8 (cfg_info.fcr.mode, p); STREAM_TO_UINT8 (cfg_info.fcr.tx_win_sz, p); STREAM_TO_UINT8 (cfg_info.fcr.max_transmit, p); STREAM_TO_UINT16 (cfg_info.fcr.rtrans_tout, p); STREAM_TO_UINT16 (cfg_info.fcr.mon_tout, p); STREAM_TO_UINT16 (cfg_info.fcr.mps, p); break; case L2CAP_CFG_TYPE_FCS: cfg_info.fcs_present = TRUE; STREAM_TO_UINT8 (cfg_info.fcs, p); break; case L2CAP_CFG_TYPE_EXT_FLOW: cfg_info.ext_flow_spec_present = TRUE; STREAM_TO_UINT8 (cfg_info.ext_flow_spec.id, p); STREAM_TO_UINT8 (cfg_info.ext_flow_spec.stype, p); STREAM_TO_UINT16 (cfg_info.ext_flow_spec.max_sdu_size, p); STREAM_TO_UINT32 (cfg_info.ext_flow_spec.sdu_inter_time, p); STREAM_TO_UINT32 (cfg_info.ext_flow_spec.access_latency, p); STREAM_TO_UINT32 (cfg_info.ext_flow_spec.flush_timeout, p); break; } } if ((p_ccb = l2cu_find_ccb_by_cid (p_lcb, lcid)) != NULL) { if (p_ccb->local_id != id) { L2CAP_TRACE_WARNING2 ("L2CAP - cfg rsp - bad ID. Exp: %d Got: %d", p_ccb->local_id, id); break; } if ( (cfg_info.result == L2CAP_CFG_OK) || (cfg_info.result == L2CAP_CFG_PENDING) ) l2c_csm_execute (p_ccb, L2CEVT_L2CAP_CONFIG_RSP, &cfg_info); else l2c_csm_execute (p_ccb, L2CEVT_L2CAP_CONFIG_RSP_NEG, &cfg_info); } else { L2CAP_TRACE_WARNING1 ("L2CAP - rcvd cfg rsp for unknown CID: 0x%04x", lcid); } break; case L2CAP_CMD_DISC_REQ: STREAM_TO_UINT16 (lcid, p); STREAM_TO_UINT16 (rcid, p); if ((p_ccb = l2cu_find_ccb_by_cid (p_lcb, lcid)) != NULL) { if (p_ccb->remote_cid == rcid) { p_ccb->remote_id = id; l2c_csm_execute (p_ccb, L2CEVT_L2CAP_DISCONNECT_REQ, &con_info); } } else l2cu_send_peer_disc_rsp (p_lcb, id, lcid, rcid); break; case L2CAP_CMD_DISC_RSP: STREAM_TO_UINT16 (rcid, p); STREAM_TO_UINT16 (lcid, p); if ((p_ccb = l2cu_find_ccb_by_cid (p_lcb, lcid)) != NULL) { if ((p_ccb->remote_cid == rcid) && (p_ccb->local_id == id)) { l2c_csm_execute (p_ccb, L2CEVT_L2CAP_DISCONNECT_RSP, &con_info); } } break; case L2CAP_CMD_ECHO_REQ: l2cu_send_peer_echo_rsp (p_lcb, id, p, cmd_len); break; case L2CAP_CMD_ECHO_RSP: if (p_lcb->p_echo_rsp_cb) { tL2CA_ECHO_RSP_CB *p_cb = p_lcb->p_echo_rsp_cb; /* Zero out the callback in case app immediately calls us again */ p_lcb->p_echo_rsp_cb = NULL; (*p_cb) (L2CAP_PING_RESULT_OK); } break; case L2CAP_CMD_INFO_REQ: STREAM_TO_UINT16 (info_type, p); l2cu_send_peer_info_rsp (p_lcb, id, info_type); break; case L2CAP_CMD_INFO_RSP: /* Stop the link connect timer if sent before L2CAP connection is up */ if (p_lcb->w4_info_rsp) { btu_stop_timer (&p_lcb->info_timer_entry); p_lcb->w4_info_rsp = FALSE; } STREAM_TO_UINT16 (info_type, p); STREAM_TO_UINT16 (result, p); p_lcb->info_rx_bits |= (1 << info_type); if ( (info_type == L2CAP_EXTENDED_FEATURES_INFO_TYPE) && (result == L2CAP_INFO_RESP_RESULT_SUCCESS) ) { STREAM_TO_UINT32( p_lcb->peer_ext_fea, p ); #if (L2CAP_NUM_FIXED_CHNLS > 0) if (p_lcb->peer_ext_fea & L2CAP_EXTFEA_FIXED_CHNLS) { l2cu_send_peer_info_req (p_lcb, L2CAP_FIXED_CHANNELS_INFO_TYPE); break; } else { l2cu_process_fixed_chnl_resp (p_lcb); } #endif } #if (L2CAP_NUM_FIXED_CHNLS > 0) if (info_type == L2CAP_FIXED_CHANNELS_INFO_TYPE) { if (result == L2CAP_INFO_RESP_RESULT_SUCCESS) { memcpy (p_lcb->peer_chnl_mask, p, L2CAP_FIXED_CHNL_ARRAY_SIZE); } l2cu_process_fixed_chnl_resp (p_lcb); } #endif #if (L2CAP_UCD_INCLUDED == TRUE) else if (info_type == L2CAP_CONNLESS_MTU_INFO_TYPE) { if (result == L2CAP_INFO_RESP_RESULT_SUCCESS) { STREAM_TO_UINT16 (p_lcb->ucd_mtu, p); } } #endif ci.status = HCI_SUCCESS; memcpy (ci.bd_addr, p_lcb->remote_bd_addr, sizeof(BD_ADDR)); for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb; p_ccb = p_ccb->p_next_ccb) { l2c_csm_execute (p_ccb, L2CEVT_L2CAP_INFO_RSP, &ci); } break; default: L2CAP_TRACE_WARNING1 ("L2CAP - bad cmd code: %d", cmd_code); l2cu_send_peer_cmd_reject (p_lcb, L2CAP_CMD_REJ_NOT_UNDERSTOOD, id, 0, 0); return; } } }