/******************************************************************************* ** ** Function sdp_disconnect_ind ** ** Description This function handles a disconnect event from L2CAP. If ** requested to, we ack the disconnect before dropping the CCB ** ** Returns void ** *******************************************************************************/ static void sdp_disconnect_ind (UINT16 l2cap_cid, BOOLEAN ack_needed) { tCONN_CB *p_ccb; /* Find CCB based on CID */ if ((p_ccb = sdpu_find_ccb_by_cid (l2cap_cid)) == NULL) { SDP_TRACE_WARNING1 ("SDP - Rcvd L2CAP disc, unknown CID: 0x%x", l2cap_cid); return; } if (ack_needed) L2CA_DisconnectRsp (l2cap_cid); SDP_TRACE_EVENT1 ("SDP - Rcvd L2CAP disc, CID: 0x%x", l2cap_cid); #if SDP_CLIENT_ENABLED == TRUE /* Tell the user if he has a callback */ if (p_ccb->p_cb) (*p_ccb->p_cb) ((UINT16) ((p_ccb->con_state == SDP_STATE_CONNECTED) ? SDP_SUCCESS : SDP_CONN_FAILED)); else if (p_ccb->p_cb2) (*p_ccb->p_cb2) ((UINT16) ((p_ccb->con_state == SDP_STATE_CONNECTED) ? SDP_SUCCESS : SDP_CONN_FAILED), p_ccb->user_data); #endif sdpu_release_ccb (p_ccb); }
/******************************************************************************* ** ** Function sdp_conn_originate ** ** Description This function is called from the API to originate a ** connection. ** ** Returns void ** *******************************************************************************/ tCONN_CB *sdp_conn_originate (UINT8 *p_bd_addr) { tCONN_CB *p_ccb; UINT16 cid; /* Allocate a new CCB. Return if none available. */ if ((p_ccb = sdpu_allocate_ccb()) == NULL) { SDP_TRACE_WARNING ("SDP - no spare CCB for orig\n"); return (NULL); } SDP_TRACE_EVENT ("SDP - Originate started\n"); /* We are the originator of this connection */ p_ccb->con_flags |= SDP_FLAGS_IS_ORIG; /* Save the BD Address and Channel ID. */ memcpy (&p_ccb->device_address[0], p_bd_addr, sizeof (BD_ADDR)); /* Transition to the next appropriate state, waiting for connection confirm. */ p_ccb->con_state = SDP_STATE_CONN_SETUP; cid = L2CA_ConnectReq (SDP_PSM, p_bd_addr); /* Check if L2CAP started the connection process */ if (cid != 0) { p_ccb->connection_id = cid; return (p_ccb); } else { SDP_TRACE_WARNING ("SDP - Originate failed\n"); sdpu_release_ccb (p_ccb); return (NULL); } }
/******************************************************************************* ** ** Function sdp_connect_cfm ** ** Description This function handles the connect confirm events ** from L2CAP. This is the case when we are acting as a ** client and have sent a connect request. ** ** Returns void ** *******************************************************************************/ static void sdp_connect_cfm (UINT16 l2cap_cid, UINT16 result) { tCONN_CB *p_ccb; tL2CAP_CFG_INFO cfg; /* Find CCB based on CID */ if ((p_ccb = sdpu_find_ccb_by_cid (l2cap_cid)) == NULL) { SDP_TRACE_WARNING ("SDP - Rcvd conn cnf for unknown CID 0x%x\n", l2cap_cid); return; } /* If the connection response contains success status, then */ /* Transition to the next state and startup the timer. */ if ((result == L2CAP_CONN_OK) && (p_ccb->con_state == SDP_STATE_CONN_SETUP)) { p_ccb->con_state = SDP_STATE_CFG_SETUP; cfg = sdp_cb.l2cap_my_cfg; if (cfg.fcr_present) { SDP_TRACE_DEBUG("sdp_connect_cfm: mode %u, txwinsz %u, max_trans %u, rtrans_tout %u, mon_tout %u, mps %u\n", cfg.fcr.mode, cfg.fcr.tx_win_sz, cfg.fcr.max_transmit, cfg.fcr.rtrans_tout, cfg.fcr.mon_tout, cfg.fcr.mps); } if ((!L2CA_ConfigReq (l2cap_cid, &cfg)) && cfg.fcr_present && cfg.fcr.mode != L2CAP_FCR_BASIC_MODE) { /* FCR not desired; try again in basic mode */ cfg.fcr_present = FALSE; cfg.fcr.mode = L2CAP_FCR_BASIC_MODE; L2CA_ConfigReq (l2cap_cid, &cfg); } SDP_TRACE_EVENT ("SDP - got conn cnf, sent cfg req, CID: 0x%x\n", p_ccb->connection_id); } else { SDP_TRACE_WARNING ("SDP - Rcvd conn cnf with error: 0x%x CID 0x%x\n", result, p_ccb->connection_id); /* Tell the user if he has a callback */ if (p_ccb->p_cb || p_ccb->p_cb2) { UINT16 err = -1; if ((result == HCI_ERR_HOST_REJECT_SECURITY) || (result == HCI_ERR_AUTH_FAILURE) || (result == HCI_ERR_PAIRING_NOT_ALLOWED) || (result == HCI_ERR_PAIRING_WITH_UNIT_KEY_NOT_SUPPORTED) || (result == HCI_ERR_KEY_MISSING)) { err = SDP_SECURITY_ERR; } else if (result == HCI_ERR_HOST_REJECT_DEVICE) { err = SDP_CONN_REJECTED; } else { err = SDP_CONN_FAILED; } if (p_ccb->p_cb) { (*p_ccb->p_cb)(err); } else if (p_ccb->p_cb2) { (*p_ccb->p_cb2)(err, p_ccb->user_data); } } sdpu_release_ccb (p_ccb); } }
/******************************************************************************* ** ** Function sdp_conn_timeout ** ** Description This function processes a timeout. Currently, we simply send ** a disconnect request to L2CAP. ** ** Returns void ** *******************************************************************************/ void sdp_conn_timeout (tCONN_CB*p_ccb) { SDP_TRACE_EVENT2 ("SDP - CCB timeout in state: %d CID: 0x%x", p_ccb->con_state, p_ccb->connection_id); L2CA_DisconnectReq (p_ccb->connection_id); #if SDP_CLIENT_ENABLED == TRUE /* Tell the user if he has a callback */ if (p_ccb->p_cb) (*p_ccb->p_cb) (SDP_CONN_FAILED); else if (p_ccb->p_cb2) (*p_ccb->p_cb2) (SDP_CONN_FAILED, p_ccb->user_data); #endif sdpu_release_ccb (p_ccb); }
/******************************************************************************* ** ** Function sdp_conn_originate ** ** Description This function is called from the API to originate a ** connection. ** ** Returns void ** *******************************************************************************/ tCONN_CB* sdp_conn_originate (UINT8 *p_bd_addr) { tCONN_CB *p_ccb; UINT16 cid; /* Allocate a new CCB. Return if none available. */ if ((p_ccb = sdpu_allocate_ccb()) == NULL) { SDP_TRACE_WARNING0 ("SDP - no spare CCB for orig"); return (NULL); } SDP_TRACE_EVENT0 ("SDP - Originate started"); /* We are the originator of this connection */ p_ccb->con_flags |= SDP_FLAGS_IS_ORIG; /* Save the BD Address and Channel ID. */ memcpy (&p_ccb->device_address[0], p_bd_addr, sizeof (BD_ADDR)); /* Transition to the next appropriate state, waiting for connection confirm. */ p_ccb->con_state = SDP_STATE_CONN_SETUP; // btla-specific ++ #ifndef ANDROID_APP_INCLUDED /* Skip for Android: Do not need to set out_service for sdp, since sdp does not use sec. Prevents over-writing service_rec of a connection already in progress */ BTM_SetOutService(p_bd_addr, BTM_SEC_SERVICE_SDP_SERVER, 0); #endif // btla-specific -- cid = L2CA_ConnectReq (SDP_PSM, p_bd_addr); /* Check if L2CAP started the connection process */ if (cid != 0) { p_ccb->connection_id = cid; return (p_ccb); } else { SDP_TRACE_WARNING0 ("SDP - Originate failed"); sdpu_release_ccb (p_ccb); return (NULL); } }
/******************************************************************************* ** ** Function sdp_disconnect_cfm ** ** Description This function handles a disconnect confirm event from L2CAP. ** ** Returns void ** *******************************************************************************/ static void sdp_disconnect_cfm (UINT16 l2cap_cid, UINT16 result) { tCONN_CB *p_ccb; /* Find CCB based on CID */ if ((p_ccb = sdpu_find_ccb_by_cid (l2cap_cid)) == NULL) { SDP_TRACE_WARNING1 ("SDP - Rcvd L2CAP disc cfm, unknown CID: 0x%x", l2cap_cid); return; } SDP_TRACE_EVENT1 ("SDP - Rcvd L2CAP disc cfm, CID: 0x%x", l2cap_cid); /* Tell the user if he has a callback */ if (p_ccb->p_cb) (*p_ccb->p_cb) (p_ccb->disconnect_reason); else if (p_ccb->p_cb2) (*p_ccb->p_cb2) (p_ccb->disconnect_reason, p_ccb->user_data); sdpu_release_ccb (p_ccb); }
/******************************************************************************* ** ** Function sdp_disconnect ** ** Description This function disconnects a connection. ** ** Returns void ** *******************************************************************************/ void sdp_disconnect (tCONN_CB*p_ccb, UINT16 reason) { #if (defined(SDP_BROWSE_PLUS) && SDP_BROWSE_PLUS == TRUE) /* If we are browsing for multiple UUIDs ... */ if ((p_ccb->con_state == SDP_STATE_CONNECTED) && (p_ccb->con_flags & SDP_FLAGS_IS_ORIG) && ((reason == SDP_SUCCESS) || (reason == SDP_NO_RECS_MATCH))) { /* If the browse found something, do no more searching */ if ((p_ccb->cur_uuid_idx == 0) && (p_ccb->p_db->p_first_rec)) p_ccb->cur_uuid_idx = p_ccb->p_db->num_uuid_filters; while (++p_ccb->cur_uuid_idx < p_ccb->p_db->num_uuid_filters) { /* Check we have not already found the UUID (maybe through browse) */ if ((p_ccb->p_db->uuid_filters[p_ccb->cur_uuid_idx].len == 2) && (SDP_FindServiceInDb (p_ccb->p_db, p_ccb->p_db->uuid_filters[p_ccb->cur_uuid_idx].uu.uuid16, NULL))) continue; if ((p_ccb->p_db->uuid_filters[p_ccb->cur_uuid_idx].len > 2) && (SDP_FindServiceUUIDInDb (p_ccb->p_db, &p_ccb->p_db->uuid_filters[p_ccb->cur_uuid_idx], NULL))) continue; p_ccb->cur_handle = 0; SDP_TRACE_EVENT1 ("SDP - looking for for more, CID: 0x%x", p_ccb->connection_id); sdp_disc_connected (p_ccb); return; } } if ((reason == SDP_NO_RECS_MATCH) && (p_ccb->p_db->p_first_rec)) reason = SDP_SUCCESS; #endif SDP_TRACE_EVENT1 ("SDP - disconnect CID: 0x%x", p_ccb->connection_id); /* Check if we have a connection ID */ if (p_ccb->connection_id != 0) { L2CA_DisconnectReq (p_ccb->connection_id); p_ccb->disconnect_reason = reason; } /* If at setup state, we may not get callback ind from L2CAP */ /* Call user callback immediately */ if (p_ccb->con_state == SDP_STATE_CONN_SETUP) { /* Tell the user if he has a callback */ if (p_ccb->p_cb) (*p_ccb->p_cb) (reason); else if (p_ccb->p_cb2) (*p_ccb->p_cb2) (reason, p_ccb->user_data); sdpu_release_ccb (p_ccb); } }