diff options
-rwxr-xr-x[-rw-r--r--] | bta/dm/bta_dm_api.c | 342 | ||||
-rw-r--r-- | btif/co/bta_hl_co.c | 34 | ||||
-rwxr-xr-x[-rw-r--r--] | btif/include/btif_hl.h | 122 | ||||
-rw-r--r-- | btif/include/btif_storage.h | 69 | ||||
-rwxr-xr-x[-rw-r--r--] | btif/src/btif_hl.c | 2154 | ||||
-rwxr-xr-x[-rw-r--r--] | btif/src/btif_storage.c | 680 | ||||
-rwxr-xr-x[-rw-r--r--] | stack/sdp/sdp_api.c | 328 | ||||
-rwxr-xr-x[-rw-r--r--] | udrv/include/unv.h | 61 | ||||
-rwxr-xr-x[-rw-r--r--] | udrv/ulinux/unv_linux.c | 264 |
9 files changed, 2916 insertions, 1138 deletions
diff --git a/bta/dm/bta_dm_api.c b/bta/dm/bta_dm_api.c index 4c77f37..cbf80ae 100644..100755 --- a/bta/dm/bta_dm_api.c +++ b/bta/dm/bta_dm_api.c @@ -42,16 +42,16 @@ static const tBTA_SYS_REG bta_dm_search_reg = ** ** Description Enables bluetooth service. This function must be ** called before any other functions in the BTA API are called. -** ** -** Returns tBTA_STATUS +** +** Returns tBTA_STATUS ** *******************************************************************************/ tBTA_STATUS BTA_EnableBluetooth(tBTA_DM_SEC_CBACK *p_cback) { tBTA_DM_API_ENABLE *p_msg; - + /* Bluetooth disabling is in progress */ if (bta_dm_cb.disabling) return BTA_FAILURE; @@ -66,7 +66,7 @@ tBTA_STATUS BTA_EnableBluetooth(tBTA_DM_SEC_CBACK *p_cback) bta_sys_eir_register(bta_dm_eir_update_uuid); GKI_sched_unlock(); - + if ((p_msg = (tBTA_DM_API_ENABLE *) GKI_getbuf(sizeof(tBTA_DM_API_ENABLE))) != NULL) { p_msg->hdr.event = BTA_DM_API_ENABLE_EVT; @@ -84,14 +84,14 @@ tBTA_STATUS BTA_EnableBluetooth(tBTA_DM_SEC_CBACK *p_cback) ** ** Description Disables bluetooth service. This function is called when ** the application no longer needs bluetooth service -** -** Returns void +** +** Returns void ** *******************************************************************************/ tBTA_STATUS BTA_DisableBluetooth(void) { - BT_HDR *p_msg; + BT_HDR *p_msg; if ((p_msg = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL) { @@ -102,7 +102,7 @@ tBTA_STATUS BTA_DisableBluetooth(void) { return BTA_FAILURE; } - + return BTA_SUCCESS; } @@ -111,15 +111,15 @@ tBTA_STATUS BTA_DisableBluetooth(void) ** Function BTA_EnableTestMode ** ** Description Enables bluetooth device under test mode -** ** -** Returns tBTA_STATUS +** +** Returns tBTA_STATUS ** *******************************************************************************/ tBTA_STATUS BTA_EnableTestMode(void) { - BT_HDR *p_msg; - + BT_HDR *p_msg; + APPL_TRACE_API0("BTA_EnableTestMode"); if ((p_msg = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL) @@ -136,15 +136,15 @@ tBTA_STATUS BTA_EnableTestMode(void) ** Function BTA_DisableTestMode ** ** Description Disable bluetooth device under test mode -** ** -** Returns None +** +** Returns None ** *******************************************************************************/ void BTA_DisableTestMode(void) { - BT_HDR *p_msg; - + BT_HDR *p_msg; + APPL_TRACE_API0("BTA_DisableTestMode"); if ((p_msg = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL) @@ -160,8 +160,8 @@ void BTA_DisableTestMode(void) ** ** Description Called during startup to check whether the bluetooth module ** is up and ready -** -** Returns BOOLEAN +** +** Returns BOOLEAN ** *******************************************************************************/ BOOLEAN BTA_DmIsDeviceUp(void) @@ -181,23 +181,23 @@ BOOLEAN BTA_DmIsDeviceUp(void) ** Function BTA_DmSetDeviceName ** ** Description This function sets the Bluetooth name of local device -** ** -** Returns void +** +** Returns void ** *******************************************************************************/ void BTA_DmSetDeviceName(char *p_name) { - tBTA_DM_API_SET_NAME *p_msg; - + tBTA_DM_API_SET_NAME *p_msg; + if ((p_msg = (tBTA_DM_API_SET_NAME *) GKI_getbuf(sizeof(tBTA_DM_API_SET_NAME))) != NULL) { p_msg->hdr.event = BTA_DM_API_SET_NAME_EVT; /* truncate the name if needed */ BCM_STRNCPY_S(p_msg->name, sizeof(p_msg->name), p_name, BD_NAME_LEN-1); p_msg->name[BD_NAME_LEN-1]=0; - + bta_sys_sendmsg(p_msg); } @@ -210,16 +210,16 @@ void BTA_DmSetDeviceName(char *p_name) ** ** Description This function sets the Bluetooth connectable, ** discoverable, pairable and conn paired only modes of local device -** ** -** Returns void +** +** Returns void ** *******************************************************************************/ void BTA_DmSetVisibility(tBTA_DM_DISC disc_mode, tBTA_DM_CONN conn_mode, UINT8 pairable_mode, UINT8 conn_filter ) { - tBTA_DM_API_SET_VISIBILITY *p_msg; - + tBTA_DM_API_SET_VISIBILITY *p_msg; + if ((p_msg = (tBTA_DM_API_SET_VISIBILITY *) GKI_getbuf(sizeof(tBTA_DM_MSG))) != NULL) { p_msg->hdr.event = BTA_DM_API_SET_VISIBILITY_EVT; @@ -228,7 +228,7 @@ void BTA_DmSetVisibility(tBTA_DM_DISC disc_mode, tBTA_DM_CONN conn_mode, UINT8 p p_msg->pair_mode = pairable_mode; p_msg->conn_paired_only = conn_filter; - + bta_sys_sendmsg(p_msg); } @@ -241,9 +241,9 @@ void BTA_DmSetVisibility(tBTA_DM_DISC disc_mode, tBTA_DM_CONN conn_mode, UINT8 p ** ** Description This function sets the parameters for page scan and ** inquiry scan. -** ** -** Returns void +** +** Returns void ** *******************************************************************************/ void BTA_DmSetScanParam (UINT16 page_scan_interval, UINT16 page_scan_window, @@ -267,14 +267,14 @@ void BTA_DmSetScanParam (UINT16 page_scan_interval, UINT16 page_scan_window, ** last disable channel, so channels within ** that range are disabled. ** -** Returns void +** Returns void ** *******************************************************************************/ void BTA_DmSetAfhChannels(UINT8 first, UINT8 last) { - tBTA_DM_API_SET_AFH_CHANNELS_EVT *p_msg; - + tBTA_DM_API_SET_AFH_CHANNELS_EVT *p_msg; + if ((p_msg = (tBTA_DM_API_SET_AFH_CHANNELS_EVT *) GKI_getbuf(sizeof(tBTA_DM_MSG))) != NULL) { p_msg->hdr.event = BTA_DM_API_SET_AFH_CHANNELS_EVT; @@ -297,11 +297,11 @@ void BTA_DmSetAfhChannels(UINT8 first, UINT8 last) *******************************************************************************/ void BTA_DmSetAfhChannelAssessment (BOOLEAN enable_or_disable) { - tBTA_DM_API_SET_AFH_CHANNEL_ASSESSMENT *p_msg; + tBTA_DM_API_SET_AFH_CHANNEL_ASSESSMENT *p_msg; if ((p_msg = (tBTA_DM_API_SET_AFH_CHANNEL_ASSESSMENT *) GKI_getbuf(sizeof(tBTA_DM_API_SET_AFH_CHANNEL_ASSESSMENT))) != NULL) { - p_msg->hdr.event = BTA_DM_API_SET_AFH_CHANNEL_ASSESMENT_EVT; + p_msg->hdr.event = BTA_DM_API_SET_AFH_CHANNEL_ASSESMENT_EVT; p_msg->enable_or_disable = enable_or_disable; bta_sys_sendmsg(p_msg); } @@ -313,19 +313,19 @@ void BTA_DmSetAfhChannelAssessment (BOOLEAN enable_or_disable) ** ** Description This function sends the vendor specific command ** to the controller -** ** -** Returns tBTA_STATUS +** +** Returns tBTA_STATUS ** *******************************************************************************/ tBTA_STATUS BTA_DmVendorSpecificCommand (UINT16 opcode, UINT8 param_len, - UINT8 *p_param_buf, + UINT8 *p_param_buf, tBTA_VENDOR_CMPL_CBACK *p_cback) { tBTA_DM_API_VENDOR_SPECIFIC_COMMAND *p_msg; UINT16 size; - + /* If p_cback is NULL, Notify application */ if (p_cback == NULL) { @@ -353,19 +353,19 @@ tBTA_STATUS BTA_DmVendorSpecificCommand (UINT16 opcode, UINT8 param_len, ** ** Function BTA_DmSearch ** -** Description This function searches for peer Bluetooth devices. It performs -** an inquiry and gets the remote name for devices. Service +** Description This function searches for peer Bluetooth devices. It performs +** an inquiry and gets the remote name for devices. Service ** discovery is done if services is non zero -** ** -** Returns void +** +** Returns void ** *******************************************************************************/ void BTA_DmSearch(tBTA_DM_INQ *p_dm_inq, tBTA_SERVICE_MASK services, tBTA_DM_SEARCH_CBACK *p_cback) { - tBTA_DM_API_SEARCH *p_msg; - + tBTA_DM_API_SEARCH *p_msg; + if ((p_msg = (tBTA_DM_API_SEARCH *) GKI_getbuf(sizeof(tBTA_DM_API_SEARCH))) != NULL) { memset(p_msg, 0, sizeof(tBTA_DM_API_SEARCH)); @@ -385,16 +385,16 @@ void BTA_DmSearch(tBTA_DM_INQ *p_dm_inq, tBTA_SERVICE_MASK services, tBTA_DM_SEA ** ** Function BTA_DmSearchCancel ** -** Description This function cancels a search initiated by BTA_DmSearch +** Description This function cancels a search initiated by BTA_DmSearch ** ** -** Returns void +** Returns void ** *******************************************************************************/ void BTA_DmSearchCancel(void) { - BT_HDR *p_msg; - + BT_HDR *p_msg; + if ((p_msg = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL) { p_msg->event = BTA_DM_API_SEARCH_CANCEL_EVT; @@ -407,18 +407,18 @@ void BTA_DmSearchCancel(void) ** ** Function BTA_DmDiscover ** -** Description This function does service discovery for services of a +** Description This function does service discovery for services of a ** peer device ** ** -** Returns void +** Returns void ** *******************************************************************************/ -void BTA_DmDiscover(BD_ADDR bd_addr, tBTA_SERVICE_MASK services, +void BTA_DmDiscover(BD_ADDR bd_addr, tBTA_SERVICE_MASK services, tBTA_DM_SEARCH_CBACK *p_cback, BOOLEAN sdp_search) { - tBTA_DM_API_DISCOVER *p_msg; - + tBTA_DM_API_DISCOVER *p_msg; + if ((p_msg = (tBTA_DM_API_DISCOVER *) GKI_getbuf(sizeof(tBTA_DM_API_DISCOVER))) != NULL) { memset(p_msg, 0, sizeof(tBTA_DM_API_DISCOVER)); @@ -499,13 +499,13 @@ BOOLEAN BTA_DmIsMaster(BD_ADDR bd_addr) ** device ** ** -** Returns void +** Returns void ** *******************************************************************************/ void BTA_DmBond(BD_ADDR bd_addr) { - tBTA_DM_API_BOND *p_msg; - + tBTA_DM_API_BOND *p_msg; + if ((p_msg = (tBTA_DM_API_BOND *) GKI_getbuf(sizeof(tBTA_DM_API_BOND))) != NULL) { p_msg->hdr.event = BTA_DM_API_BOND_EVT; @@ -524,13 +524,13 @@ void BTA_DmBond(BD_ADDR bd_addr) ** device ** ** -** Returns void +** Returns void ** *******************************************************************************/ void BTA_DmBondCancel(BD_ADDR bd_addr) { - tBTA_DM_API_BOND_CANCEL *p_msg; - + tBTA_DM_API_BOND_CANCEL *p_msg; + if ((p_msg = (tBTA_DM_API_BOND_CANCEL *) GKI_getbuf(sizeof(tBTA_DM_API_BOND_CANCEL))) != NULL) { p_msg->hdr.event = BTA_DM_API_BOND_CANCEL_EVT; @@ -549,14 +549,14 @@ void BTA_DmBondCancel(BD_ADDR bd_addr) ** one is requested by DM through BTA_DM_PIN_REQ_EVT ** ** -** Returns void +** Returns void ** *******************************************************************************/ void BTA_DmPinReply(BD_ADDR bd_addr, BOOLEAN accept, UINT8 pin_len, UINT8 *p_pin) { - tBTA_DM_API_PIN_REPLY *p_msg; - + tBTA_DM_API_PIN_REPLY *p_msg; + if ((p_msg = (tBTA_DM_API_PIN_REPLY *) GKI_getbuf(sizeof(tBTA_DM_API_PIN_REPLY))) != NULL) { p_msg->hdr.event = BTA_DM_API_PIN_REPLY_EVT; @@ -587,8 +587,8 @@ void BTA_DmPinReply(BD_ADDR bd_addr, BOOLEAN accept, UINT8 pin_len, UINT8 *p_pin void BTA_DmLinkPolicy(BD_ADDR bd_addr, tBTA_DM_LP_MASK policy_mask, BOOLEAN set) { - tBTA_DM_API_LINK_POLICY *p_msg; - + tBTA_DM_API_LINK_POLICY *p_msg; + if ((p_msg = (tBTA_DM_API_LINK_POLICY *) GKI_getbuf(sizeof(tBTA_DM_API_LINK_POLICY))) != NULL) { p_msg->hdr.event = BTA_DM_API_LINK_POLICY_EVT; @@ -608,13 +608,13 @@ void BTA_DmLinkPolicy(BD_ADDR bd_addr, tBTA_DM_LP_MASK policy_mask, ** Description This function retrieves the OOB data from local controller. ** The result is reported by bta_dm_co_loc_oob(). ** -** Returns void +** Returns void ** *******************************************************************************/ void BTA_DmLocalOob(void) { - tBTA_DM_API_LOC_OOB *p_msg; - + tBTA_DM_API_LOC_OOB *p_msg; + if ((p_msg = (tBTA_DM_API_LOC_OOB *) GKI_getbuf(sizeof(tBTA_DM_API_LOC_OOB))) != NULL) { p_msg->hdr.event = BTA_DM_API_LOC_OOB_EVT; @@ -629,13 +629,13 @@ void BTA_DmLocalOob(void) ** Description This function accepts or rejects the numerical value of the ** Simple Pairing process on BTA_DM_SP_CFM_REQ_EVT ** -** Returns void +** Returns void ** *******************************************************************************/ void BTA_DmConfirm(BD_ADDR bd_addr, BOOLEAN accept) { - tBTA_DM_API_CONFIRM *p_msg; - + tBTA_DM_API_CONFIRM *p_msg; + if ((p_msg = (tBTA_DM_API_CONFIRM *) GKI_getbuf(sizeof(tBTA_DM_API_CONFIRM))) != NULL) { p_msg->hdr.event = BTA_DM_API_CONFIRM_EVT; @@ -652,14 +652,14 @@ void BTA_DmConfirm(BD_ADDR bd_addr, BOOLEAN accept) ** Description This function is called to cancel the simple pairing process ** reported by BTA_DM_SP_KEY_NOTIF_EVT ** -** Returns void +** Returns void ** *******************************************************************************/ #if (BTM_LOCAL_IO_CAPS != BTM_IO_CAP_NONE) void BTA_DmPasskeyCancel(BD_ADDR bd_addr) { - tBTA_DM_API_PASKY_CANCEL *p_msg; - + tBTA_DM_API_PASKY_CANCEL *p_msg; + if ((p_msg = (tBTA_DM_API_PASKY_CANCEL *) \ GKI_getbuf(sizeof(tBTA_DM_API_PASKY_CANCEL))) != NULL) { @@ -675,11 +675,11 @@ void BTA_DmPasskeyCancel(BD_ADDR bd_addr) ** ** Function BTA_DmAddDevice ** -** Description This function adds a device to the security database list of +** Description This function adds a device to the security database list of ** peer device ** ** -** Returns void +** Returns void ** *******************************************************************************/ void BTA_DmAddDevice(BD_ADDR bd_addr, DEV_CLASS dev_class, LINK_KEY link_key, @@ -687,8 +687,8 @@ void BTA_DmAddDevice(BD_ADDR bd_addr, DEV_CLASS dev_class, LINK_KEY link_key, UINT8 key_type, tBTA_IO_CAP io_cap) { - tBTA_DM_API_ADD_DEVICE *p_msg; - + tBTA_DM_API_ADD_DEVICE *p_msg; + if ((p_msg = (tBTA_DM_API_ADD_DEVICE *) GKI_getbuf(sizeof(tBTA_DM_API_ADD_DEVICE))) != NULL) { memset (p_msg, 0, sizeof(tBTA_DM_API_ADD_DEVICE)); @@ -725,11 +725,11 @@ void BTA_DmAddDevice(BD_ADDR bd_addr, DEV_CLASS dev_class, LINK_KEY link_key, ** ** Function BTA_DmRemoveDevice ** -** Description This function removes a device fromthe security database list of +** Description This function removes a device fromthe security database list of ** peer device ** ** -** Returns void +** Returns void ** *******************************************************************************/ tBTA_STATUS BTA_DmRemoveDevice(BD_ADDR bd_addr) @@ -760,7 +760,7 @@ tBTA_STATUS BTA_DmRemoveDevice(BD_ADDR bd_addr) ** which added bd_name and features as input parameters. ** ** -** Returns void +** Returns void ** *******************************************************************************/ void BTA_DmAddDevWithName (BD_ADDR bd_addr, DEV_CLASS dev_class, @@ -769,7 +769,7 @@ void BTA_DmAddDevWithName (BD_ADDR bd_addr, DEV_CLASS dev_class, BOOLEAN is_trusted, UINT8 key_type, tBTA_IO_CAP io_cap) { tBTA_DM_API_ADD_DEVICE *p_msg; - + if ((p_msg = (tBTA_DM_API_ADD_DEVICE *) GKI_getbuf(sizeof(tBTA_DM_API_ADD_DEVICE))) != NULL) { memset (p_msg, 0, sizeof(tBTA_DM_API_ADD_DEVICE)); @@ -808,18 +808,18 @@ void BTA_DmAddDevWithName (BD_ADDR bd_addr, DEV_CLASS dev_class, ** ** Function BTA_DmAuthorizeReply ** -** Description This function provides an authorization reply when authorization +** Description This function provides an authorization reply when authorization ** is requested by BTA through BTA_DM_AUTHORIZE_EVT ** ** -** Returns tBTA_STATUS +** Returns tBTA_STATUS ** *******************************************************************************/ void BTA_DmAuthorizeReply(BD_ADDR bd_addr, tBTA_SERVICE_ID service, tBTA_AUTH_RESP response) { - tBTA_DM_API_AUTH_REPLY *p_msg; - + tBTA_DM_API_AUTH_REPLY *p_msg; + if ((p_msg = (tBTA_DM_API_AUTH_REPLY *) GKI_getbuf(sizeof(tBTA_DM_API_AUTH_REPLY))) != NULL) { p_msg->hdr.event = BTA_DM_API_AUTH_REPLY_EVT; @@ -836,11 +836,11 @@ void BTA_DmAuthorizeReply(BD_ADDR bd_addr, tBTA_SERVICE_ID service, tBTA_AUTH_RE ** ** Function BTA_DmSignalStrength ** -** Description This function initiates RSSI and channnel quality +** Description This function initiates RSSI and channnel quality ** measurments. BTA_DM_SIG_STRENGTH_EVT is sent to ** application with the values of RSSI and channel ** quality -** +** ** ** Returns void ** @@ -848,8 +848,8 @@ void BTA_DmAuthorizeReply(BD_ADDR bd_addr, tBTA_SERVICE_ID service, tBTA_AUTH_RE void BTA_DmSignalStrength(tBTA_SIG_STRENGTH_MASK mask, UINT16 period, BOOLEAN start) { - tBTA_API_DM_SIG_STRENGTH *p_msg; - + tBTA_API_DM_SIG_STRENGTH *p_msg; + if ((p_msg = (tBTA_API_DM_SIG_STRENGTH *) GKI_getbuf(sizeof(tBTA_API_DM_SIG_STRENGTH))) != NULL) { p_msg->hdr.event = BTA_API_DM_SIG_STRENGTH_EVT; @@ -867,8 +867,8 @@ void BTA_DmSignalStrength(tBTA_SIG_STRENGTH_MASK mask, UINT16 period, BOOLEAN st ** ** Function BTA_DmWriteInqTxPower ** -** Description This command is used to write the inquiry transmit power level -** used to transmit the inquiry (ID) data packets. +** Description This command is used to write the inquiry transmit power level +** used to transmit the inquiry (ID) data packets. ** ** Parameters tx_power - tx inquiry power to use, valid value is -70 ~ 20 @@ -878,8 +878,8 @@ void BTA_DmSignalStrength(tBTA_SIG_STRENGTH_MASK mask, UINT16 period, BOOLEAN st void BTA_DmWriteInqTxPower(INT8 tx_power) { - tBTA_API_DM_TX_INQPWR *p_msg; - + tBTA_API_DM_TX_INQPWR *p_msg; + if ((p_msg = (tBTA_API_DM_TX_INQPWR *) GKI_getbuf(sizeof(tBTA_API_DM_TX_INQPWR))) != NULL) { p_msg->hdr.event = BTA_DM_API_TX_INQPWR_EVT; @@ -898,14 +898,14 @@ void BTA_DmWriteInqTxPower(INT8 tx_power) ** ** Parameters tBT_UUID - UUID ** -** Returns None +** Returns None ** *******************************************************************************/ void BTA_DmEirAddUUID (tBT_UUID *p_uuid) { #if ( BTM_EIR_SERVER_INCLUDED == TRUE )&&( BTA_EIR_CANNED_UUID_LIST != TRUE )&&(BTA_EIR_SERVER_NUM_CUSTOM_UUID > 0) - tBTA_DM_API_UPDATE_EIR_UUID *p_msg; - + tBTA_DM_API_UPDATE_EIR_UUID *p_msg; + if ((p_msg = (tBTA_DM_API_UPDATE_EIR_UUID *) GKI_getbuf(sizeof(tBTA_DM_API_UPDATE_EIR_UUID))) != NULL) { p_msg->hdr.event = BTA_DM_API_UPDATE_EIR_UUID_EVT; @@ -925,14 +925,14 @@ void BTA_DmEirAddUUID (tBT_UUID *p_uuid) ** ** Parameters tBT_UUID - UUID ** -** Returns None +** Returns None ** *******************************************************************************/ void BTA_DmEirRemoveUUID (tBT_UUID *p_uuid) { #if ( BTM_EIR_SERVER_INCLUDED == TRUE )&&( BTA_EIR_CANNED_UUID_LIST != TRUE )&&(BTA_EIR_SERVER_NUM_CUSTOM_UUID > 0) - tBTA_DM_API_UPDATE_EIR_UUID *p_msg; - + tBTA_DM_API_UPDATE_EIR_UUID *p_msg; + if ((p_msg = (tBTA_DM_API_UPDATE_EIR_UUID *) GKI_getbuf(sizeof(tBTA_DM_API_UPDATE_EIR_UUID))) != NULL) { p_msg->hdr.event = BTA_DM_API_UPDATE_EIR_UUID_EVT; @@ -954,14 +954,14 @@ void BTA_DmEirRemoveUUID (tBT_UUID *p_uuid) ** ** Parameters Pointer to User defined EIR config ** -** Returns None +** Returns None ** *******************************************************************************/ void BTA_DmSetEIRConfig (tBTA_DM_EIR_CONF *p_eir_cfg) { #if (BTM_EIR_SERVER_INCLUDED == TRUE) - tBTA_DM_API_SET_EIR_CONFIG *p_msg; - + tBTA_DM_API_SET_EIR_CONFIG *p_msg; + if ((p_msg = (tBTA_DM_API_SET_EIR_CONFIG *) GKI_getbuf(sizeof(tBTA_DM_API_SET_EIR_CONFIG))) != NULL) { p_msg->hdr.event = BTA_DM_API_SET_EIR_CONFIG_EVT; @@ -982,7 +982,7 @@ void BTA_DmSetEIRConfig (tBTA_DM_EIR_CONF *p_eir_cfg) ** type - finding EIR data type ** p_length - return the length of EIR data ** -** Returns pointer of EIR data +** Returns pointer of EIR data ** *******************************************************************************/ UINT8 *BTA_CheckEirData( UINT8 *p_eir, UINT8 type, UINT8 *p_length ) @@ -1003,7 +1003,7 @@ UINT8 *BTA_CheckEirData( UINT8 *p_eir, UINT8 type, UINT8 *p_length ) ** Parameters p_eir - pointer of EIR significant part ** p_services - return the BTA service mask ** -** Returns None +** Returns None ** *******************************************************************************/ extern const UINT16 bta_service_id_to_uuid_lkup_tbl []; @@ -1033,6 +1033,12 @@ void BTA_GetEirService( UINT8 *p_eir, tBTA_SERVICE_MASK *p_services ) /* for HSP v1.2 only device */ if (*(p_uuid16 + xx) == UUID_SERVCLASS_HEADSET_HS) *p_services |= BTA_HSP_SERVICE_MASK; + + if (*(p_uuid16 + xx) == UUID_SERVCLASS_HDP_SOURCE) + *p_services |= BTA_HL_SERVICE_MASK; + + if (*(p_uuid16 + xx) == UUID_SERVCLASS_HDP_SINK) + *p_services |= BTA_HL_SERVICE_MASK; } #endif } @@ -1068,8 +1074,8 @@ BOOLEAN BTA_DmUseSsr( BD_ADDR bd_addr ) ** Returns BTA_SUCCESS if record set sucessfully, otherwise error code. ** *******************************************************************************/ -tBTA_STATUS BTA_DmSetLocalDiRecord( tBTA_DI_RECORD *p_device_info, - UINT32 *p_handle ) +tBTA_STATUS BTA_DmSetLocalDiRecord( tBTA_DI_RECORD *p_device_info, + UINT32 *p_handle ) { tBTA_STATUS status = BTA_FAILURE; @@ -1095,9 +1101,9 @@ tBTA_STATUS BTA_DmSetLocalDiRecord( tBTA_DI_RECORD *p_device_info, ** ** Function BTA_DmGetLocalDiRecord ** -** Description Get a specified DI record to the local SDP database. If no -** record handle is provided, the primary DI record will be -** returned. +** Description Get a specified DI record to the local SDP database. If no +** record handle is provided, the primary DI record will be +** returned. ** ** Fills in the device information of the record ** p_handle - if p_handle == 0, the primary record is returned @@ -1105,8 +1111,8 @@ tBTA_STATUS BTA_DmSetLocalDiRecord( tBTA_DI_RECORD *p_device_info, ** Returns BTA_SUCCESS if record set sucessfully, otherwise error code. ** *******************************************************************************/ -tBTA_STATUS BTA_DmGetLocalDiRecord( tBTA_DI_GET_RECORD *p_device_info, - UINT32 *p_handle ) +tBTA_STATUS BTA_DmGetLocalDiRecord( tBTA_DI_GET_RECORD *p_device_info, + UINT32 *p_handle ) { UINT16 status; @@ -1135,8 +1141,8 @@ tBTA_STATUS BTA_DmGetLocalDiRecord( tBTA_DI_GET_RECORD *p_device_info, void BTA_DmDiDiscover( BD_ADDR remote_device, tBTA_DISCOVERY_DB *p_db, UINT32 len, tBTA_DM_SEARCH_CBACK *p_cback ) { - tBTA_DM_API_DI_DISC *p_msg; - + tBTA_DM_API_DI_DISC *p_msg; + if ((p_msg = (tBTA_DM_API_DI_DISC *) GKI_getbuf(sizeof(tBTA_DM_API_DI_DISC))) != NULL) { bdcpy(p_msg->bd_addr, remote_device); @@ -1193,13 +1199,13 @@ void BTA_SysFeatures (UINT16 sys_features) ** This API was named in lower case because it is only intended ** for the internal customers(like BTIF). ** -** Returns void +** Returns void ** *******************************************************************************/ void bta_dmexecutecallback (tBTA_DM_EXEC_CBACK* p_callback, void * p_param) { - tBTA_DM_API_EXECUTE_CBACK *p_msg; - + tBTA_DM_API_EXECUTE_CBACK *p_msg; + if ((p_msg = (tBTA_DM_API_EXECUTE_CBACK *) GKI_getbuf(sizeof(tBTA_DM_MSG))) != NULL) { p_msg->hdr.event = BTA_DM_API_EXECUTE_CBACK_EVT; @@ -1213,8 +1219,8 @@ void bta_dmexecutecallback (tBTA_DM_EXEC_CBACK* p_callback, void * p_param) ** ** Function BTA_DmAddBleKey ** -** Description Add/modify LE device information. This function will be -** normally called during host startup to restore all required +** Description Add/modify LE device information. This function will be +** normally called during host startup to restore all required ** information stored in the NVRAM. ** ** Parameters: bd_addr - BD address of the peer @@ -1228,8 +1234,8 @@ void BTA_DmAddBleKey (BD_ADDR bd_addr, tBTA_LE_KEY_VALUE *p_le_key, tBTA_LE_KEY_ { #if BLE_INCLUDED == TRUE - tBTA_DM_API_ADD_BLEKEY *p_msg; - + tBTA_DM_API_ADD_BLEKEY *p_msg; + if ((p_msg = (tBTA_DM_API_ADD_BLEKEY *) GKI_getbuf(sizeof(tBTA_DM_API_ADD_BLEKEY))) != NULL) { memset (p_msg, 0, sizeof(tBTA_DM_API_ADD_BLEKEY)); @@ -1263,8 +1269,8 @@ void BTA_DmAddBleKey (BD_ADDR bd_addr, tBTA_LE_KEY_VALUE *p_le_key, tBTA_LE_KEY_ void BTA_DmAddBleDevice(BD_ADDR bd_addr, tBLE_ADDR_TYPE addr_type, tBT_DEVICE_TYPE dev_type) { #if BLE_INCLUDED == TRUE - tBTA_DM_API_ADD_BLE_DEVICE *p_msg; - + tBTA_DM_API_ADD_BLE_DEVICE *p_msg; + if ((p_msg = (tBTA_DM_API_ADD_BLE_DEVICE *) GKI_getbuf(sizeof(tBTA_DM_API_ADD_BLE_DEVICE))) != NULL) { memset (p_msg, 0, sizeof(tBTA_DM_API_ADD_BLE_DEVICE)); @@ -1286,7 +1292,7 @@ void BTA_DmAddBleDevice(BD_ADDR bd_addr, tBLE_ADDR_TYPE addr_type, tBT_DEVICE_TY ** ** Parameters: bd_addr - BD address of the peer ** accept - passkey entry sucessful or declined. -** passkey - passkey value, must be a 6 digit number, +** passkey - passkey value, must be a 6 digit number, ** can be lead by 0. ** ** Returns void @@ -1295,12 +1301,12 @@ void BTA_DmAddBleDevice(BD_ADDR bd_addr, tBLE_ADDR_TYPE addr_type, tBT_DEVICE_TY void BTA_DmBlePasskeyReply(BD_ADDR bd_addr, BOOLEAN accept, UINT32 passkey) { #if BLE_INCLUDED == TRUE - tBTA_DM_API_PASSKEY_REPLY *p_msg; - + tBTA_DM_API_PASSKEY_REPLY *p_msg; + if ((p_msg = (tBTA_DM_API_PASSKEY_REPLY *) GKI_getbuf(sizeof(tBTA_DM_API_PASSKEY_REPLY))) != NULL) { memset(p_msg, 0, sizeof(tBTA_DM_API_PASSKEY_REPLY)); - + p_msg->hdr.event = BTA_DM_API_BLE_PASSKEY_REPLY_EVT; bdcpy(p_msg->bd_addr, bd_addr); p_msg->accept = accept; @@ -1328,12 +1334,12 @@ void BTA_DmBlePasskeyReply(BD_ADDR bd_addr, BOOLEAN accept, UINT32 passkey) void BTA_DmBleSecurityGrant(BD_ADDR bd_addr, tBTA_DM_BLE_SEC_GRANT res) { #if BLE_INCLUDED == TRUE - tBTA_DM_API_BLE_SEC_GRANT *p_msg; - + tBTA_DM_API_BLE_SEC_GRANT *p_msg; + if ((p_msg = (tBTA_DM_API_BLE_SEC_GRANT *) GKI_getbuf(sizeof(tBTA_DM_API_BLE_SEC_GRANT))) != NULL) { memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_SEC_GRANT)); - + p_msg->hdr.event = BTA_DM_API_BLE_SEC_GRANT_EVT; bdcpy(p_msg->bd_addr, bd_addr); p_msg->res = res; @@ -1346,7 +1352,7 @@ void BTA_DmBleSecurityGrant(BD_ADDR bd_addr, tBTA_DM_BLE_SEC_GRANT res) ** ** Function BTA_DmSetBlePrefConnParams ** -** Description This function is called to set the preferred connection +** Description This function is called to set the preferred connection ** parameters when default connection parameter is not desired. ** ** Parameters: bd_addr - BD address of the peripheral @@ -1357,21 +1363,21 @@ void BTA_DmBleSecurityGrant(BD_ADDR bd_addr, tBTA_DM_BLE_SEC_GRANT res) ** slave_latency - preferred slave latency ** supervision_tout - preferred supervision timeout ** -** +** ** Returns void ** *******************************************************************************/ -void BTA_DmSetBlePrefConnParams(BD_ADDR bd_addr, +void BTA_DmSetBlePrefConnParams(BD_ADDR bd_addr, UINT16 min_conn_int, UINT16 max_conn_int, UINT16 slave_latency, UINT16 supervision_tout ) { #if BLE_INCLUDED == TRUE - tBTA_DM_API_BLE_CONN_PARAMS *p_msg; - + tBTA_DM_API_BLE_CONN_PARAMS *p_msg; + if ((p_msg = (tBTA_DM_API_BLE_CONN_PARAMS *) GKI_getbuf(sizeof(tBTA_DM_API_BLE_CONN_PARAMS))) != NULL) { memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_CONN_PARAMS)); - + p_msg->hdr.event = BTA_DM_API_BLE_CONN_PARAM_EVT; memcpy(p_msg->peer_bda, bd_addr, BD_ADDR_LEN); @@ -1390,24 +1396,24 @@ void BTA_DmSetBlePrefConnParams(BD_ADDR bd_addr, ** ** Function BTA_DmSetBleConnScanParams ** -** Description This function is called to set scan parameters used in +** Description This function is called to set scan parameters used in ** BLE connection request ** ** Parameters: scan_interval - scan interval ** scan_window - scan window -** +** ** Returns void ** *******************************************************************************/ void BTA_DmSetBleConnScanParams(UINT16 scan_interval, UINT16 scan_window ) { #if BLE_INCLUDED == TRUE - tBTA_DM_API_BLE_SCAN_PARAMS *p_msg; - + tBTA_DM_API_BLE_SCAN_PARAMS *p_msg; + if ((p_msg = (tBTA_DM_API_BLE_SCAN_PARAMS *) GKI_getbuf(sizeof(tBTA_DM_API_BLE_SCAN_PARAMS))) != NULL) { memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_SCAN_PARAMS)); - + p_msg->hdr.event = BTA_DM_API_BLE_SCAN_PARAM_EVT; p_msg->scan_int = scan_interval; @@ -1421,11 +1427,11 @@ void BTA_DmSetBleConnScanParams(UINT16 scan_interval, UINT16 scan_window ) /******************************************************************************* ** ** Function BTA_DmBleSetBgConnType -** -** Description This function is called to set BLE connectable mode for a +** +** Description This function is called to set BLE connectable mode for a ** peripheral device. ** -** Parameters bg_conn_type: it can be auto connection, or selective connection. +** Parameters bg_conn_type: it can be auto connection, or selective connection. ** p_select_cback: callback function when selective connection procedure ** is being used. ** @@ -1435,12 +1441,12 @@ void BTA_DmSetBleConnScanParams(UINT16 scan_interval, UINT16 scan_window ) void BTA_DmBleSetBgConnType(tBTA_DM_BLE_CONN_TYPE bg_conn_type, tBTA_DM_BLE_SEL_CBACK *p_select_cback) { #if BLE_INCLUDED == TRUE - tBTA_DM_API_BLE_SET_BG_CONN_TYPE *p_msg; - + tBTA_DM_API_BLE_SET_BG_CONN_TYPE *p_msg; + if ((p_msg = (tBTA_DM_API_BLE_SET_BG_CONN_TYPE *) GKI_getbuf(sizeof(tBTA_DM_API_BLE_SET_BG_CONN_TYPE))) != NULL) { memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_SET_BG_CONN_TYPE)); - + p_msg->hdr.event = BTA_DM_API_BLE_SET_BG_CONN_TYPE; p_msg->bg_conn_type = bg_conn_type; p_msg->p_select_cback = p_select_cback; @@ -1453,22 +1459,22 @@ void BTA_DmBleSetBgConnType(tBTA_DM_BLE_CONN_TYPE bg_conn_type, tBTA_DM_BLE_SEL_ ** ** Function BTA_DmDiscoverExt ** -** Description This function does service discovery for services of a +** Description This function does service discovery for services of a ** peer device. When services.num_uuid is 0, it indicates all ** GATT based services are to be searched; other wise a list of -** UUID of interested services should be provided through +** UUID of interested services should be provided through ** p_services->p_uuid. -** ** ** -** Returns void +** +** Returns void ** *******************************************************************************/ -void BTA_DmDiscoverExt(BD_ADDR bd_addr, tBTA_SERVICE_MASK_EXT *p_services, +void BTA_DmDiscoverExt(BD_ADDR bd_addr, tBTA_SERVICE_MASK_EXT *p_services, tBTA_DM_SEARCH_CBACK *p_cback, BOOLEAN sdp_search) { #if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE - tBTA_DM_API_DISCOVER *p_msg; + tBTA_DM_API_DISCOVER *p_msg; UINT16 len = p_services ? (sizeof(tBTA_DM_API_DISCOVER) + sizeof(tBT_UUID) * p_services->num_uuid) : sizeof(tBTA_DM_API_DISCOVER); @@ -1503,25 +1509,25 @@ void BTA_DmDiscoverExt(BD_ADDR bd_addr, tBTA_SERVICE_MASK_EXT *p_services, ** ** Function BTA_DmSearchExt ** -** Description This function searches for peer Bluetooth devices. It performs -** an inquiry and gets the remote name for devices. Service +** Description This function searches for peer Bluetooth devices. It performs +** an inquiry and gets the remote name for devices. Service ** discovery is done if services is non zero -** +** ** Parameters p_dm_inq: inquiry conditions ** p_services: if service is not empty, service discovery will be done. -** for all GATT based service condition, put num_uuid, and +** for all GATT based service condition, put num_uuid, and ** p_uuid is the pointer to the list of UUID values. -** p_cback: callback functino when search is completed. -** -** +** p_cback: callback functino when search is completed. ** -** Returns void +** +** +** Returns void ** *******************************************************************************/ void BTA_DmSearchExt(tBTA_DM_INQ *p_dm_inq, tBTA_SERVICE_MASK_EXT *p_services, tBTA_DM_SEARCH_CBACK *p_cback) { #if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE - tBTA_DM_API_SEARCH *p_msg; + tBTA_DM_API_SEARCH *p_msg; UINT16 len = p_services ? (sizeof(tBTA_DM_API_SEARCH) + sizeof(tBT_UUID) * p_services->num_uuid) : sizeof(tBTA_DM_API_SEARCH); @@ -1567,19 +1573,19 @@ void BTA_DmSearchExt(tBTA_DM_INQ *p_dm_inq, tBTA_SERVICE_MASK_EXT *p_services, t ** Parameters: bd_addr - Address of the peer device ** p_callback - Pointer to callback function to indicat the ** link encryption status -** sec_act - This is the security action to indicate +** sec_act - This is the security action to indicate ** what knid of BLE security level is required for -** the BLE link if the BLE is supported +** the BLE link if the BLE is supported ** Note: This parameter is ignored for the BR/EDR link -** or the BLE is not supported -** -** Returns void +** or the BLE is not supported +** +** Returns void ** *******************************************************************************/ void BTA_DmSetEncryption(BD_ADDR bd_addr, tBTA_DM_ENCRYPT_CBACK *p_callback, tBTA_DM_BLE_SEC_ACT sec_act) { - tBTA_DM_API_SET_ENCRYPTION *p_msg; + tBTA_DM_API_SET_ENCRYPTION *p_msg; APPL_TRACE_API0("BTA_DmSetEncryption"); //todo if ((p_msg = (tBTA_DM_API_SET_ENCRYPTION *) GKI_getbuf(sizeof(tBTA_DM_API_SET_ENCRYPTION))) != NULL) diff --git a/btif/co/bta_hl_co.c b/btif/co/bta_hl_co.c index c851807..1cfbc81 100644 --- a/btif/co/bta_hl_co.c +++ b/btif/co/bta_hl_co.c @@ -258,35 +258,35 @@ void bta_hl_co_delete_mdl(UINT8 app_id, UINT8 item_idx) BOOLEAN bta_hl_co_load_mdl_config (UINT8 app_id, UINT8 buffer_size, tBTA_HL_MDL_CFG *p_mdl_buf ) { - tBTA_HL_MDL_CFG *p; - BOOLEAN success = TRUE; + BOOLEAN result = TRUE; UINT8 i; + tBTA_HL_MDL_CFG *p; - - BTIF_TRACE_DEBUG3("%s app_id=%d, buffer_size=%d", + BTIF_TRACE_DEBUG3("%s app_id=%d, num_items=%d", __FUNCTION__, app_id, buffer_size); - if (buffer_size > BTA_HL_NUM_MDL_CFGS) { - success= FALSE; - return success; + result = FALSE; + return result; } + result = btif_hl_load_mdl_config(app_id, buffer_size, p_mdl_buf); - p = p_mdl_buf; - - for (i=0; i < buffer_size; i++, p++) + if (result) { - memset(p, 0, sizeof(tBTA_HL_MDL_CFG)); - /* todo load from NV */ + for (i=0, p=p_mdl_buf; i<buffer_size; i++, p++ ) + { + if (p->active) + { + BTIF_TRACE_DEBUG6("i=%d mdl_id=0x%x dch_mode=%d local mdep_role=%d mdep_id=%d mtu=%d", + i, p->mdl_id, p->dch_mode, p->local_mdep_role, p->local_mdep_role, p->mtu); + } + } } + BTIF_TRACE_DEBUG3("%s success=%d num_items=%d", __FUNCTION__, result, buffer_size); - BTIF_TRACE_DEBUG3("%s success=%d num_items=%d", - __FUNCTION__, success, buffer_size); - - - return success; + return result; } /******************************************************************************* diff --git a/btif/include/btif_hl.h b/btif/include/btif_hl.h index 2328609..cac6eb2 100644..100755 --- a/btif/include/btif_hl.h +++ b/btif/include/btif_hl.h @@ -73,6 +73,67 @@ #define BTIF_HL_APPLICATION_NAME_LEN 512 +#define BTIF_HL_NV_MAX_APPS 16 + +typedef struct +{ + UINT8 mdep_cfg_idx; + int data_type; + tBTA_HL_MDEP_ID peer_mdep_id; +} btif_hl_extra_mdl_cfg_t; + + +typedef struct +{ + tBTA_HL_MDL_CFG base; + btif_hl_extra_mdl_cfg_t extra; +} btif_hl_mdl_cfg_t; + +typedef struct +{ + btif_hl_mdl_cfg_t mdl_cfg[BTA_HL_NUM_MDL_CFGS]; +}btif_hl_nv_mdl_data_t; + + +typedef struct +{ + tBTA_HL_SUP_FEATURE sup_feature; + tBTA_HL_DCH_CFG channel_type[BTA_HL_NUM_MDEPS]; + char srv_name[BTA_SERVICE_NAME_LEN +1]; + char srv_desp[BTA_SERVICE_DESP_LEN +1]; + char provider_name[BTA_PROVIDER_NAME_LEN +1]; + char application_name[BTIF_HL_APPLICATION_NAME_LEN +1]; +}btif_hl_nv_app_data_t; + + +typedef struct +{ + BOOLEAN in_use; + UINT16 use_freq; +}btif_hl_nv_app_t; + +typedef struct +{ + btif_hl_nv_app_t app[BTIF_HL_NV_MAX_APPS]; +}btif_hl_nv_app_cb_t; + + + +typedef struct +{ + UINT8 app_nv_idx; + BOOLEAN active; + UINT8 app_idx; + btif_hl_nv_app_data_t app_data; +}btif_hl_app_data_t; + +typedef struct +{ + BOOLEAN is_app_read; + btif_hl_nv_app_cb_t app_cb; + BUFFER_Q app_queue; +}btif_hl_nv_cb_t; + typedef enum { BTIF_HL_SOC_STATE_IDLE, @@ -193,6 +254,7 @@ typedef struct btif_hl_chan_cb_state_t cb_state; btif_hl_pend_dch_op_t op; BD_ADDR bd_addr; + BOOLEAN abort_pending; }btif_hl_pending_chan_cb_t; typedef struct @@ -208,34 +270,16 @@ typedef struct tBTA_SEC sec_mask; tBTA_HL_MCL_HANDLE mcl_handle; btif_hl_pending_chan_cb_t pcb; - - BOOLEAN valid_sdp_idx; UINT8 sdp_idx; - tBTA_HL_SDP sdp; btif_hl_cch_op_t cch_oper; + BOOLEAN cch_timer_active; + TIMER_LIST_ENT cch_timer; }btif_hl_mcl_cb_t; typedef struct { - UINT8 mdep_cfg_idx; - int data_type; - int channel_id; - UINT8 app_idx; - BOOLEAN app_active; - //UINT8 app_nv_idx; /* one base */ -} btif_hl_extra_mdl_cfg_t; - - -typedef struct -{ - tBTA_HL_MDL_CFG base; - btif_hl_extra_mdl_cfg_t extra; -} btif_hl_mdl_cfg_t; - -typedef struct -{ BOOLEAN active; UINT16 mdl_id; UINT8 mdep_cfg_idx; @@ -247,6 +291,9 @@ typedef struct { btif_hl_mcl_cb_t mcb[BTA_HL_NUM_MCLS]; /* application Control Blocks */ BOOLEAN in_use; /* this CB is in use*/ + BOOLEAN reg_pending; + BOOLEAN is_new_app; + UINT8 app_nv_idx; UINT8 app_id; //UINT32 sdp_handle; /* SDP record handle */ tBTA_HL_SUP_FEATURE sup_feature; @@ -254,16 +301,13 @@ typedef struct tBTA_HL_SDP_INFO_IND sdp_info_ind; btif_hl_cch_filter_t filter; - btif_hl_mdl_cfg_t mdl_cfg[BTA_HL_NUM_MDL_CFGS]; + btif_hl_mdl_cfg_t mdl_cfg[BTA_HL_NUM_MDL_CFGS]; + int mdl_cfg_channel_id[BTA_HL_NUM_MDL_CFGS]; btif_hl_delete_mdl_t delete_mdl; tBTA_HL_DEVICE_TYPE dev_type; tBTA_HL_APP_HANDLE app_handle; - - //UINT16 data_mtu; /* L2CAP MTU of the MCAP data channel */ UINT16 sec_mask; /* Security mask for BTM_SetSecurityLevel() */ - - char srv_name[BTA_SERVICE_NAME_LEN +1]; /* service name to be used in the SDP; null terminated*/ char srv_desp[BTA_SERVICE_DESP_LEN +1]; /* service description to be used in the SDP; null terminated */ char provider_name[BTA_PROVIDER_NAME_LEN +1]; /* provide name to be used in the SDP; null terminated */ @@ -280,12 +324,11 @@ typedef struct typedef struct { btif_hl_app_cb_t acb[BTA_HL_NUM_APPS]; /* HL Control Blocks */ - btif_hl_pending_reg_cb_t pcb[BTA_HL_NUM_APPS]; tBTA_HL_CTRL_CBACK *p_ctrl_cback; /* pointer to control callback function */ UINT8 next_app_id; UINT16 next_channel_id; btif_hl_state_t state; - + btif_hl_nv_cb_t ncb; } btif_hl_cb_t; @@ -293,6 +336,9 @@ enum { BTIF_HL_SEND_CONNECTED_CB, BTIF_HL_SEND_DISCONNECTED_CB, + BTIF_HL_REG_APP, + BTIF_HL_UNREG_APP, + BTIF_HL_UPDATE_MDL, }; typedef UINT8 btif_hl_evt_t; @@ -306,8 +352,27 @@ typedef struct int fd; }btif_hl_send_chan_state_cb_t; + +typedef struct +{ + UINT8 app_idx; +}btif_hl_reg_t; +typedef btif_hl_reg_t btif_hl_unreg_t; +typedef btif_hl_reg_t btif_hl_update_mdl_t; + +typedef union +{ + btif_hl_send_chan_state_cb_t chan_cb; + btif_hl_reg_t reg; + btif_hl_unreg_t unreg; + btif_hl_update_mdl_t update_mdl; +}btif_hl_evt_cb_t; + + + extern btif_hl_cb_t btif_hl_cb; extern btif_hl_cb_t *p_btif_hl_cb; +extern btif_hl_nv_cb_t *p_ncb; #define BTIF_HL_GET_CB_PTR() &(btif_hl_cb) #define BTIF_HL_GET_APP_CB_PTR(app_idx) &(btif_hl_cb.acb[(app_idx)]) @@ -315,6 +380,7 @@ extern btif_hl_cb_t *p_btif_hl_cb; #define BTIF_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx) &(btif_hl_cb.acb[(app_idx)].mcb[(mcl_idx)].mdl[mdl_idx]) #define BTIF_HL_GET_PCB_PTR(app_idx, mcl_idx) &(btif_hl_cb.acb[app_idx].mcb[mcl_idx].pcb) #define BTIF_HL_GET_MDL_CFG_PTR(app_idx, item_idx) &(btif_hl_cb.acb[(app_idx)].mdl_cfg[(item_idx)]) +#define BTIF_HL_GET_MDL_CFG_CHANNEL_ID_PTR(app_idx, item_idx) &(btif_hl_cb.acb[(app_idx)].mdl_cfg_channel_id[(item_idx)]) extern BOOLEAN btif_hl_find_mcl_idx(UINT8 app_idx, BD_ADDR p_bd_addr, UINT8 *p_mcl_idx); extern BOOLEAN btif_hl_find_app_idx(UINT8 app_id, UINT8 *p_app_idx); extern BOOLEAN btif_hl_find_avail_mcl_idx(UINT8 app_idx, UINT8 *p_mcl_idx); @@ -331,4 +397,6 @@ extern BOOLEAN btif_hl_find_mdl_idx_using_handle(tBTA_HL_MDL_HANDLE mdl_handle, UINT8 *p_mdl_idx); extern void btif_hl_abort_pending_chan_setup(UINT8 app_idx, UINT8 mcl_idx); extern BOOLEAN btif_hl_proc_pending_op(UINT8 app_idx, UINT8 mcl_idx); +extern BOOLEAN btif_hl_load_mdl_config (UINT8 app_id, UINT8 buffer_size, + tBTA_HL_MDL_CFG *p_mdl_buf ); #endif diff --git a/btif/include/btif_storage.h b/btif/include/btif_storage.h index 6aaa10f..59cad1f 100644 --- a/btif/include/btif_storage.h +++ b/btif/include/btif_storage.h @@ -65,7 +65,7 @@ ** Constants & Macros ************************************************************************************/ #define BTIF_STORAGE_FILL_PROPERTY(p_prop, t, l, p_v) \ - (p_prop)->type = t;(p_prop)->len = l; (p_prop)->val = (p_v); + (p_prop)->type = t;(p_prop)->len = l; (p_prop)->val = (p_v); /************************************************************************************ ** Type definitions for callback functions @@ -184,6 +184,73 @@ bt_status_t btif_storage_remove_bonded_device(bt_bdaddr_t *remote_bd_addr); ** *******************************************************************************/ bt_status_t btif_storage_load_bonded_devices(void); +/******************************************************************************* +** +** Function btif_storage_read_hl_apps_cb +** +** Description BTIF storage API - Read HL application control block from NVRAM +** +** Returns BT_STATUS_SUCCESS if the operation was successful, +** BT_STATUS_FAIL otherwise +** +*******************************************************************************/ +bt_status_t btif_storage_read_hl_apps_cb(char *value, int value_size); + +/******************************************************************************* +** +** Function btif_storage_write_hl_apps_cb +** +** Description BTIF storage API - Write HL application control block to NVRAM +** +** Returns BT_STATUS_SUCCESS if the operation was successful, +** BT_STATUS_FAIL otherwise +** +*******************************************************************************/ +bt_status_t btif_storage_write_hl_apps_cb(char *value, int value_size); +/******************************************************************************* +** +** Function btif_storage_read_hl_apps_cb +** +** Description BTIF storage API - Read HL application configuration from NVRAM +** +** Returns BT_STATUS_SUCCESS if the operation was successful, +** BT_STATUS_FAIL otherwise +** +*******************************************************************************/ +bt_status_t btif_storage_read_hl_app_data(UINT8 app_idx, char *value, int value_size); +/******************************************************************************* +** +** Function btif_storage_write_hl_app_data +** +** Description BTIF storage API - Write HL application configuration to NVRAM +** +** Returns BT_STATUS_SUCCESS if the operation was successful, +** BT_STATUS_FAIL otherwise +** +*******************************************************************************/ +bt_status_t btif_storage_write_hl_app_data(UINT8 app_idx, char *value, int value_size); +/******************************************************************************* +** +** Function btif_storage_read_hl_mdl_data +** +** Description BTIF storage API - Read HL application MDL configuration from NVRAM +** +** Returns BT_STATUS_SUCCESS if the operation was successful, +** BT_STATUS_FAIL otherwise +** +*******************************************************************************/ +bt_status_t btif_storage_read_hl_mdl_data(UINT8 app_idx, char *value, int value_size); +/******************************************************************************* +** +** Function btif_storage_write_hl_mdl_data +** +** Description BTIF storage API - Write HL application MDL configuration from NVRAM +** +** Returns BT_STATUS_SUCCESS if the operation was successful, +** BT_STATUS_FAIL otherwise +** +*******************************************************************************/ +bt_status_t btif_storage_write_hl_mdl_data(UINT8 app_idx, char *value, int value_size); /******************************************************************************* ** diff --git a/btif/src/btif_hl.c b/btif/src/btif_hl.c index 1e4ffaf..2f2821f 100644..100755 --- a/btif/src/btif_hl.c +++ b/btif/src/btif_hl.c @@ -74,17 +74,16 @@ #include <hardware/bluetooth.h> #include <hardware/bt_hl.h> -//#define LOG_TAG "BTIF_HL" #include "btif_common.h" #include "btif_util.h" - +#include "gki.h" #include "bd.h" #include "bta_api.h" #include "bta_hl_api.h" #include "mca_api.h" #include "btif_hl.h" -#include "gki.h" - +#include "btif_storage.h" +#include "btu.h" extern int btif_hl_update_maxfd( int max_org_s); @@ -100,7 +99,7 @@ extern void btif_hl_release_socket(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx); btif_hl_cb_t btif_hl_cb; btif_hl_cb_t *p_btif_hl_cb = &btif_hl_cb; - +btif_hl_nv_cb_t *p_ncb = &btif_hl_cb.ncb; /************************************************************************************ ** Static variables ************************************************************************************/ @@ -129,6 +128,8 @@ static void btif_hl_init_next_channel_id(void); static void btif_hl_ctrl_cback(tBTA_HL_CTRL_EVT event, tBTA_HL_CTRL *p_data); static void btif_hl_set_state(btif_hl_state_t state); static btif_hl_state_t btif_hl_get_state(void); +static void btif_hl_cback(tBTA_HL_EVT event, tBTA_HL *p_data); +static void btif_hl_proc_cb_evt(UINT16 event, char* p_param); #define CHECK_CALL_CBACK(P_CB, P_CBACK, ...)\ if (P_CB && P_CB->P_CBACK) { \ @@ -174,12 +175,178 @@ static const btif_hl_data_type_cfg_t data_type_table[] = { }; #define BTIF_HL_DATA_TABLE_SIZE (sizeof(data_type_table) / sizeof(btif_hl_data_type_cfg_t)) -#define BTIF_HL_DEFAULT_SRC_TX_APDU_SIZE 10240 /* use this size if the data type is not defined in the table; for futur proof */ -#define BTIF_HL_DEFAULT_SRC_RX_APDU_SIZE 512 /* use this size if the data type is not defined in the table; for futur proof */ +#define BTIF_HL_DEFAULT_SRC_TX_APDU_SIZE 10240 /* use this size if the data type is not + defined in the table; for future proof */ +#define BTIF_HL_DEFAULT_SRC_RX_APDU_SIZE 512 /* use this size if the data type is not + defined in the table; for future proof */ + +#define BTIF_HL_ECHO_MAX_TX_RX_APDU_SIZE 1024 + /************************************************************************************ ** Static utility functions ************************************************************************************/ +#define BTIF_IF_GET_NAME 16 +void btif_hl_display_calling_process_name(void) +{ + char name[16]; + prctl(BTIF_IF_GET_NAME, name, 0, 0, 0); + BTIF_TRACE_DEBUG1("Process name (%s)", name); +} +#define BTIF_TIMEOUT_CCH_NO_DCH_SECS 10 +/******************************************************************************* +** +** Function btif_hl_if_channel_setup_pending +** +** Description check whether channel id is in setup pending state or not +** +** Returns BOOLEAN +** +*******************************************************************************/ +BOOLEAN btif_hl_if_channel_setup_pending(int channel_id, UINT8 *p_app_idx, UINT8 *p_mcl_idx) +{ + btif_hl_app_cb_t *p_acb; + btif_hl_mcl_cb_t *p_mcb; + UINT8 i, j; + BOOLEAN found=FALSE; + for (i=0; i < BTA_HL_NUM_APPS ; i ++) + { + p_acb =BTIF_HL_GET_APP_CB_PTR(i); + if (p_acb->in_use) + { + for (j=0; j< BTA_HL_NUM_MCLS; j++) + { + p_mcb = BTIF_HL_GET_MCL_CB_PTR(i, j); + if (p_mcb->in_use && + p_mcb->is_connected && p_mcb->pcb.channel_id == channel_id ) + { + found = TRUE; + *p_app_idx = i; + *p_mcl_idx = j; + break; + } + } + } + if (found) + break; + } + BTIF_TRACE_DEBUG5("%s found=%d channel_id=0x%08x", __FUNCTION__, found, channel_id, *p_app_idx, *p_mcl_idx); + return found; + +} +/******************************************************************************* +** +** Function btif_hl_num_dchs_in_use +** +** Description find number of DCHs in use +** +** Returns UINT8 +*******************************************************************************/ +UINT8 btif_hl_num_dchs_in_use(UINT8 app_idx,UINT8 mcl_idx){ + + btif_hl_mcl_cb_t *p_mcb = BTIF_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + UINT8 i; + UINT8 cnt=0; + + for (i=0; i < BTA_HL_NUM_MDLS_PER_MCL ; i ++) + { + if (p_mcb->mdl[i].in_use) + cnt++; + } + BTIF_TRACE_DEBUG2("%s dch in use count=%d", __FUNCTION__, cnt); + return cnt; +} +/******************************************************************************* +** +** Function btif_hl_tmr_hdlr +** +** Description Process timer timeout +** +** Returns void +*******************************************************************************/ +void btif_hl_tmr_hdlr(TIMER_LIST_ENT *tle) +{ + btif_hl_mcl_cb_t *p_mcb; + UINT8 i,j; + BTIF_TRACE_DEBUG2("%s timer_in_use=%d", __FUNCTION__, tle->in_use ); + + for (i=0; i < BTA_HL_NUM_APPS ; i ++) + { + for (j=0; j< BTA_HL_NUM_MCLS; j++) + { + p_mcb =BTIF_HL_GET_MCL_CB_PTR(i,j); + + if (p_mcb->cch_timer_active) + { + BTIF_TRACE_DEBUG5("%app_idx=%d, mcl_idx=%d timer_active=%d cch_time.in_use=%d mcl-connected=%d", + i, j, p_mcb->cch_timer_active, p_mcb->cch_timer.in_use, p_mcb->is_connected); + p_mcb->cch_timer_active = FALSE; + if (p_mcb->is_connected) + { + BTIF_TRACE_DEBUG3("CCH idle timeout Close CCH app_idx=%d mcl_idx=%d mcl_handle=%d",i ,j, p_mcb->mcl_handle); + BTA_HlCchClose(p_mcb->mcl_handle); + } + else + { + BTIF_TRACE_DEBUG2("CCH idle timeout But CCH not connected app_idx=%d mcl_idx=%d ",i,j); + } + } + } + } +} +/******************************************************************************* +** +** Function btif_hl_stop_cch_timer +** +** Description stop CCH timer +** +** Returns void +*******************************************************************************/ +void btif_hl_stop_cch_timer(UINT8 app_idx, UINT8 mcl_idx) +{ + btif_hl_mcl_cb_t *p_mcb = BTIF_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + BTIF_TRACE_DEBUG4("%s app_idx=%d, mcl_idx=%d timer_in_use=%d", + __FUNCTION__,app_idx, mcl_idx, p_mcb->cch_timer.in_use); + + p_mcb->cch_timer_active = FALSE; + if (p_mcb->cch_timer.in_use) + { + BTIF_TRACE_DEBUG0("stop CCH timer "); + btu_stop_timer(&p_mcb->cch_timer); + } +} +/******************************************************************************* +** +** Function btif_hl_start_cch_timer +** +** Description start CCH timer +** +** Returns void +*******************************************************************************/ +void btif_hl_start_cch_timer(UINT8 app_idx, UINT8 mcl_idx) +{ + btif_hl_mcl_cb_t *p_mcb = BTIF_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + BTIF_TRACE_DEBUG5("%s app_idx=%d, mcl_idx=%d timer_active=%d timer_in_use=%d", + __FUNCTION__,app_idx, mcl_idx, p_mcb->cch_timer_active, p_mcb->cch_timer.in_use); + + p_mcb->cch_timer_active = TRUE; + if (!p_mcb->cch_timer.in_use) + { + BTIF_TRACE_DEBUG0("Start CCH timer "); + memset(&p_mcb->cch_timer, 0, sizeof(TIMER_LIST_ENT)); + p_mcb->cch_timer.param = (UINT32)btif_hl_tmr_hdlr; + btu_start_timer(&p_mcb->cch_timer, BTU_TTYPE_USER_FUNC, + BTIF_TIMEOUT_CCH_NO_DCH_SECS); + } + else + { + BTIF_TRACE_DEBUG0("Restart CCH timer "); + btu_stop_timer(&p_mcb->cch_timer); + btu_start_timer(&p_mcb->cch_timer, BTU_TTYPE_USER_FUNC, + BTIF_TIMEOUT_CCH_NO_DCH_SECS); + } + +} /******************************************************************************* ** ** Function btif_hl_find_mdl_idx @@ -242,7 +409,15 @@ void * btif_hl_get_buf(UINT16 size) return p_new; } - +/******************************************************************************* +** +** Function btif_hl_free_buf +** +** Description free buffer +** +** Return void +** +*******************************************************************************/ void btif_hl_free_buf(void **p) { if (*p != NULL) @@ -283,9 +458,6 @@ BOOLEAN btif_hl_is_the_first_reliable_existed(UINT8 app_idx, UINT8 mcl_idx ) BTIF_TRACE_DEBUG1("bta_hl_is_the_first_reliable_existed is_existed=%d ",is_existed ); return is_existed; } - - - /******************************************************************************* ** ** Function btif_hl_clean_delete_mdl @@ -445,6 +617,120 @@ static BOOLEAN btif_hl_find_sdp_idx_using_mdep_filter(UINT8 app_idx, UINT8 mcl_i return found; } +/******************************************************************************* +** +** Function btif_hl_is_reconnect_possible +** +** Description check reconnect is possible or not +** +** Returns BOOLEAN +** +*******************************************************************************/ +BOOLEAN btif_hl_is_reconnect_possible(UINT8 app_idx, UINT8 mcl_idx, int mdep_cfg_idx, + tBTA_HL_DCH_OPEN_PARAM *p_dch_open_api, tBTA_HL_MDL_ID *p_mdl_id) +{ + btif_hl_app_cb_t *p_acb = BTIF_HL_GET_APP_CB_PTR(app_idx); + btif_hl_mcl_cb_t *p_mcb = BTIF_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + tBTA_HL_DCH_CFG local_cfg = p_dch_open_api->local_cfg; + tBTA_HL_DCH_MODE dch_mode = BTA_HL_DCH_MODE_RELIABLE; + BOOLEAN use_mdl_dch_mode=FALSE; + btif_hl_mdl_cfg_t *p_mdl; + btif_hl_mdl_cfg_t *p_mdl1; + UINT8 i, j; + BOOLEAN is_reconnect_ok=FALSE; + BOOLEAN stream_mode_avail=FALSE; + UINT16 data_type = p_acb->sup_feature.mdep[mdep_cfg_idx].mdep_cfg.data_cfg[0].data_type; + tBTA_HL_MDEP_ID peer_mdep_id = p_dch_open_api->peer_mdep_id; + + BTIF_TRACE_DEBUG4("%s app_idx=%d mcl_idx=%d mdep_cfg_idx=%d", + __FUNCTION__, app_idx, mcl_idx, mdep_cfg_idx ); + switch (local_cfg) + { + case BTA_HL_DCH_CFG_NO_PREF: + if (!btif_hl_is_the_first_reliable_existed(app_idx, mcl_idx)) + { + dch_mode = BTA_HL_DCH_MODE_RELIABLE; + } + else + { + use_mdl_dch_mode = TRUE; + } + break; + case BTA_HL_DCH_CFG_RELIABLE: + dch_mode = BTA_HL_DCH_MODE_RELIABLE; + break; + case BTA_HL_DCH_CFG_STREAMING: + dch_mode = BTA_HL_DCH_MODE_STREAMING; + break; + default: + BTIF_TRACE_ERROR1("Invalid local_cfg=%d",local_cfg ); + return is_reconnect_ok; + break; + + } + + BTIF_TRACE_DEBUG3("local_cfg=%d use_mdl_dch_mode=%d dch_mode=%d ", + local_cfg, use_mdl_dch_mode, dch_mode ); + + for (i=0, p_mdl=&p_acb->mdl_cfg[0] ; i< BTA_HL_NUM_MDL_CFGS; i++, p_mdl++ ) + { + if (p_mdl->base.active && + p_mdl->extra.data_type ==data_type && + (p_mdl->extra.peer_mdep_id != BTA_HL_INVALID_MDEP_ID && p_mdl->extra.peer_mdep_id == peer_mdep_id) && + memcpy(p_mdl->base.peer_bd_addr, p_mcb->bd_addr,sizeof(BD_ADDR) )) + { + BTIF_TRACE_DEBUG2("i=%d active=%d match step1", i, p_mdl->base.active ); + if (!use_mdl_dch_mode) + { + if (p_mdl->base.dch_mode == dch_mode) + { + is_reconnect_ok = TRUE; + *p_mdl_id = p_mdl->base.mdl_id; + BTIF_TRACE_DEBUG2("reconnect is possible dch_mode=%d mdl_id=%d", dch_mode, p_mdl->base.mdl_id ); + break; + } + } + else + { + is_reconnect_ok = TRUE; + for (j=i, p_mdl1=&p_acb->mdl_cfg[i]; j< BTA_HL_NUM_MDL_CFGS; j++, p_mdl1++) + { + if (p_mdl1->base.active && + p_mdl1->extra.data_type == data_type && + (p_mdl1->extra.peer_mdep_id != BTA_HL_INVALID_MDEP_ID && p_mdl1->extra.peer_mdep_id == peer_mdep_id) && + memcpy(p_mdl1->base.peer_bd_addr, p_mcb->bd_addr,sizeof(BD_ADDR)) && + p_mdl1->base.dch_mode == BTA_HL_DCH_MODE_STREAMING) + { + stream_mode_avail = TRUE; + BTIF_TRACE_DEBUG1("found streaming mode mdl index=%d", j); + break; + } + } + + if (stream_mode_avail) + { + dch_mode = BTA_HL_DCH_MODE_STREAMING; + *p_mdl_id = p_mdl1->base.mdl_id; + BTIF_TRACE_DEBUG2("reconnect is ok index=%d dch_mode=streaming mdl_id=%d", j, *p_mdl_id); + break; + } + else + { + dch_mode= p_mdl->base.dch_mode; + *p_mdl_id = p_mdl->base.mdl_id; + BTIF_TRACE_DEBUG3("reconnect is ok index=%d dch_mode=%d mdl_id=%d", i, p_mdl->base.dch_mode, *p_mdl_id); + break; + + } + } + + } + + } + + BTIF_TRACE_DEBUG3("is_reconnect_ok dch_mode=%d mdl_id=%d",is_reconnect_ok, dch_mode, *p_mdl_id); + return is_reconnect_ok; +} /******************************************************************************* ** @@ -455,15 +741,23 @@ static BOOLEAN btif_hl_find_sdp_idx_using_mdep_filter(UINT8 app_idx, UINT8 mcl_i ** Returns BOOLEAN ** *******************************************************************************/ -BOOLEAN btif_hl_dch_open(UINT8 app_id, BD_ADDR bd_addr, tBTA_HL_DCH_OPEN_PARAM *p_dch_open_api, +BOOLEAN btif_hl_dch_open(UINT8 app_id, BD_ADDR bd_addr, + tBTA_HL_DCH_OPEN_PARAM *p_dch_open_api, int mdep_cfg_idx, - btif_hl_pend_dch_op_t op, int *channel_id) -{ - btif_hl_app_cb_t *p_acb; - btif_hl_mcl_cb_t *p_mcb; - btif_hl_pending_chan_cb_t *p_pcb; - UINT8 app_idx, mcl_idx; - BOOLEAN status = FALSE; + btif_hl_pend_dch_op_t op, int *channel_id){ + btif_hl_app_cb_t *p_acb; + btif_hl_mcl_cb_t *p_mcb; + btif_hl_pending_chan_cb_t *p_pcb; + UINT8 app_idx, mcl_idx; + BOOLEAN status = FALSE; + tBTA_HL_MDL_ID mdl_id; + tBTA_HL_DCH_RECONNECT_PARAM reconnect_param; + + BTIF_TRACE_DEBUG2("%s app_id=%d ", + __FUNCTION__, app_id ); + BTIF_TRACE_DEBUG6("DB [%02x:%02x:%02x:%02x:%02x:%02x]", + bd_addr[0], bd_addr[1],bd_addr[2], bd_addr[3], bd_addr[4], bd_addr[5]); + if (btif_hl_find_app_idx(app_id, &app_idx)) { if (btif_hl_find_mcl_idx(app_idx, bd_addr , &mcl_idx)) @@ -488,7 +782,21 @@ BOOLEAN btif_hl_dch_open(UINT8 app_id, BD_ADDR bd_addr, tBTA_HL_DCH_OPEN_PARAM * { p_dch_open_api->ctrl_psm = p_mcb->ctrl_psm; } - BTA_HlDchOpen(p_mcb->mcl_handle, p_dch_open_api); + + if (!btif_hl_is_reconnect_possible(app_idx, mcl_idx, mdep_cfg_idx, p_dch_open_api, &mdl_id )) + { + + BTIF_TRACE_DEBUG0("Issue DCH open" ); + BTA_HlDchOpen(p_mcb->mcl_handle, p_dch_open_api); + } + else + { + reconnect_param.ctrl_psm = p_mcb->ctrl_psm; + reconnect_param.mdl_id = mdl_id;; + BTIF_TRACE_DEBUG2("Issue Reconnect ctrl_psm=0x%x mdl_id=0x%x",reconnect_param.ctrl_psm, reconnect_param.mdl_id ); + BTA_HlDchReconnect(p_mcb->mcl_handle, &reconnect_param); + } + status = TRUE; } else @@ -505,19 +813,32 @@ BOOLEAN btif_hl_dch_open(UINT8 app_id, BD_ADDR bd_addr, tBTA_HL_DCH_OPEN_PARAM * BTIF_TRACE_DEBUG1("status=%d ", status); return status; } - -void btif_hl_copy_bda(bt_bdaddr_t *bd_addr, BD_ADDR bda) -{ +/******************************************************************************* +** +** Function btif_hl_copy_bda +** +** Description copy bt_bdaddr_t to BD_ADDR format +** +** Returns void +** +*******************************************************************************/ +void btif_hl_copy_bda(bt_bdaddr_t *bd_addr, BD_ADDR bda){ UINT8 i; for (i=0; i<6; i++) { bd_addr->address[i] = bda[i] ; } - } - -void btif_hl_display_bt_bda(bt_bdaddr_t *bd_addr) -{ +/******************************************************************************* +** +** Function btif_hl_copy_bda +** +** Description display bt_bdaddr_t +** +** Returns BOOLEAN +** +*******************************************************************************/ +void btif_hl_display_bt_bda(bt_bdaddr_t *bd_addr){ BTIF_TRACE_DEBUG6("DB [%02x:%02x:%02x:%02x:%02x:%02x]", bd_addr->address[0], bd_addr->address[1], bd_addr->address[2], bd_addr->address[3], bd_addr->address[4], bd_addr->address[5]); @@ -532,21 +853,20 @@ void btif_hl_display_bt_bda(bt_bdaddr_t *bd_addr) ** Returns Nothing ** *******************************************************************************/ -void btif_hl_dch_abort(UINT8 app_id, - BD_ADDR bd_addr) -{ -/* todo */ -// UINT8 app_idx, mcl_idx; -// btif_hl_mcl_cb_t *p_mcb; -// -// if (btif_hl_find_app_idx(app_id, &app_idx)) -// { -// if (btif_hl_find_mcl_idx(app_idx, bd_addr, &mcl_idx)) -// { -// p_mcb = BTIF_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); -// BTA_HlDchAbort(p_mcb->mcl_handle); -// } -// } +void btif_hl_dch_abort(UINT8 app_idx, UINT8 mcl_idx){ + btif_hl_mcl_cb_t *p_mcb; + + BTIF_TRACE_DEBUG3("%s app_idx=%d mcl_idx=%d",__FUNCTION__, app_idx, mcl_idx ); + p_mcb = BTIF_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + if (p_mcb->is_connected) + { + BTA_HlDchAbort(p_mcb->mcl_handle); + } + else + { + p_mcb->pcb.abort_pending = TRUE; + } + } /******************************************************************************* ** @@ -559,8 +879,7 @@ void btif_hl_dch_abort(UINT8 app_id, *******************************************************************************/ BOOLEAN btif_hl_cch_open(UINT8 app_id, BD_ADDR bd_addr, UINT16 ctrl_psm, int mdep_cfg_idx, - btif_hl_pend_dch_op_t op, int *channel_id) -{ + btif_hl_pend_dch_op_t op, int *channel_id){ btif_hl_app_cb_t *p_acb; btif_hl_mcl_cb_t *p_mcb; @@ -617,7 +936,6 @@ BOOLEAN btif_hl_cch_open(UINT8 app_id, BD_ADDR bd_addr, UINT16 ctrl_psm, break; } BTA_HlSdpQuery(p_acb->app_handle, bd_addr); - } else { @@ -660,12 +978,12 @@ BOOLEAN btif_hl_cch_open(UINT8 app_id, BD_ADDR bd_addr, UINT16 ctrl_psm, *******************************************************************************/ BOOLEAN btif_hl_find_mdl_cfg_idx_using_channel_id(int channel_id, UINT8 *p_app_idx, - UINT8 *p_mdl_cfg_idx) -{ + UINT8 *p_mdl_cfg_idx){ btif_hl_app_cb_t *p_acb; btif_hl_mdl_cfg_t *p_mdl; BOOLEAN found=FALSE; UINT8 i,j; + int mdl_cfg_channel_id; for (i=0; i < BTA_HL_NUM_APPS ; i ++) { @@ -673,9 +991,10 @@ BOOLEAN btif_hl_find_mdl_cfg_idx_using_channel_id(int channel_id, for (j=0; j< BTA_HL_NUM_MDL_CFGS; j++) { p_mdl =BTIF_HL_GET_MDL_CFG_PTR(i,j); + mdl_cfg_channel_id = *(BTIF_HL_GET_MDL_CFG_CHANNEL_ID_PTR(i,j)); if (p_acb->in_use && p_mdl->base.active && - (p_mdl->extra.channel_id == channel_id)) + (mdl_cfg_channel_id == channel_id)) { found = TRUE; *p_app_idx = i; @@ -700,8 +1019,7 @@ BOOLEAN btif_hl_find_mdl_cfg_idx_using_channel_id(int channel_id, *******************************************************************************/ BOOLEAN btif_hl_find_mdl_idx_using_channel_id(int channel_id, UINT8 *p_app_idx,UINT8 *p_mcl_idx, - UINT8 *p_mdl_idx) -{ + UINT8 *p_mdl_idx){ btif_hl_app_cb_t *p_acb; btif_hl_mcl_cb_t *p_mcb; btif_hl_mdl_cb_t *p_dcb; @@ -747,8 +1065,7 @@ BOOLEAN btif_hl_find_mdl_idx_using_channel_id(int channel_id, *******************************************************************************/ BOOLEAN btif_hl_find_mdl_idx_using_handle(tBTA_HL_MDL_HANDLE mdl_handle, UINT8 *p_app_idx,UINT8 *p_mcl_idx, - UINT8 *p_mdl_idx) -{ + UINT8 *p_mdl_idx){ btif_hl_app_cb_t *p_acb; btif_hl_mcl_cb_t *p_mcb; btif_hl_mdl_cb_t *p_dcb; @@ -796,8 +1113,7 @@ BOOLEAN btif_hl_find_mdl_idx_using_handle(tBTA_HL_MDL_HANDLE mdl_handle, static BOOLEAN btif_hl_find_peer_mdep_id(UINT8 app_id, BD_ADDR bd_addr, tBTA_HL_MDEP_ROLE local_mdep_role, UINT16 data_type, - tBTA_HL_MDEP_ID *p_peer_mdep_id) -{ + tBTA_HL_MDEP_ID *p_peer_mdep_id){ UINT8 app_idx, mcl_idx; btif_hl_app_cb_t *p_acb; btif_hl_mcl_cb_t *p_mcb; @@ -832,21 +1148,24 @@ static BOOLEAN btif_hl_find_peer_mdep_id(UINT8 app_id, BD_ADDR bd_addr, p_mcb =BTIF_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); BTIF_TRACE_DEBUG2("app_idx=%d mcl_idx=%d",app_idx, mcl_idx); - BTIF_TRACE_DEBUG1("sdp_idx=%d",p_mcb->sdp_idx); - p_rec = &p_mcb->sdp.sdp_rec[p_mcb->sdp_idx]; - num_mdeps = p_rec->num_mdeps; - BTIF_TRACE_DEBUG1("num_mdeps=%d", num_mdeps); - - for (i=0; i< num_mdeps; i++) + BTIF_TRACE_DEBUG2("valid_spd_idx=%d sdp_idx=%d",p_mcb->valid_sdp_idx, p_mcb->sdp_idx); + if (p_mcb->valid_sdp_idx) { - BTIF_TRACE_DEBUG2("p_rec->mdep_cfg[%d].mdep_role=%d",i, p_rec->mdep_cfg[i].mdep_role); - BTIF_TRACE_DEBUG2("p_rec->mdep_cfg[%d].data_type =%d",i, p_rec->mdep_cfg[i].data_type ); - if ((p_rec->mdep_cfg[i].mdep_role == peer_mdep_role) && - (p_rec->mdep_cfg[i].data_type == data_type)) + p_rec = &p_mcb->sdp.sdp_rec[p_mcb->sdp_idx]; + num_mdeps = p_rec->num_mdeps; + BTIF_TRACE_DEBUG1("num_mdeps=%d", num_mdeps); + + for (i=0; i< num_mdeps; i++) { - found = TRUE; - *p_peer_mdep_id = p_rec->mdep_cfg[i].mdep_id; - break; + BTIF_TRACE_DEBUG2("p_rec->mdep_cfg[%d].mdep_role=%d",i, p_rec->mdep_cfg[i].mdep_role); + BTIF_TRACE_DEBUG2("p_rec->mdep_cfg[%d].data_type =%d",i, p_rec->mdep_cfg[i].data_type ); + if ((p_rec->mdep_cfg[i].mdep_role == peer_mdep_role) && + (p_rec->mdep_cfg[i].data_type == data_type)) + { + found = TRUE; + *p_peer_mdep_id = p_rec->mdep_cfg[i].mdep_id; + break; + } } } } @@ -896,15 +1215,12 @@ static BOOLEAN btif_hl_find_local_mdep_id(UINT8 app_id, } } + } BTIF_TRACE_DEBUG2("found=%d local mdep id=%d", found, *p_local_mdep_id ); return found; } - - - - /******************************************************************************* ** ** Function btif_hl_find_mdep_cfg_idx @@ -915,8 +1231,7 @@ static BOOLEAN btif_hl_find_local_mdep_id(UINT8 app_id, ** *******************************************************************************/ static BOOLEAN btif_hl_find_mdep_cfg_idx(UINT8 app_idx, tBTA_HL_MDEP_ID local_mdep_id, - UINT8 *p_mdep_cfg_idx) -{ + UINT8 *p_mdep_cfg_idx){ btif_hl_app_cb_t *p_acb =BTIF_HL_GET_APP_CB_PTR(app_idx); tBTA_HL_SUP_FEATURE *p_sup_feature= &p_acb->sup_feature; BOOLEAN found =FALSE; @@ -948,8 +1263,7 @@ static BOOLEAN btif_hl_find_mdep_cfg_idx(UINT8 app_idx, tBTA_HL_MDEP_ID local_ ** Returns BOOLEAN ** *******************************************************************************/ -BOOLEAN btif_hl_find_mcl_idx(UINT8 app_idx, BD_ADDR p_bd_addr, UINT8 *p_mcl_idx) -{ +BOOLEAN btif_hl_find_mcl_idx(UINT8 app_idx, BD_ADDR p_bd_addr, UINT8 *p_mcl_idx){ BOOLEAN found=FALSE; UINT8 i; btif_hl_app_cb_t *p_acb =BTIF_HL_GET_APP_CB_PTR(app_idx); @@ -980,16 +1294,11 @@ BOOLEAN btif_hl_find_mcl_idx(UINT8 app_idx, BD_ADDR p_bd_addr, UINT8 *p_mcl_idx) ** Returns void ** *******************************************************************************/ -static void btif_hl_init(void) -{ +static void btif_hl_init(void){ BTIF_TRACE_DEBUG1("%s", __FUNCTION__); memset(p_btif_hl_cb, 0, sizeof(btif_hl_cb_t)); btif_hl_init_next_app_id(); btif_hl_init_next_channel_id(); - /* todo load existing app and mdl configuration */ - - btif_hl_set_state(BTIF_HL_STATE_ENABLING); - BTA_HlEnable(btif_hl_ctrl_cback); } /******************************************************************************* ** @@ -1000,8 +1309,7 @@ static void btif_hl_init(void) ** Returns void ** *******************************************************************************/ -static void btif_hl_disable(void) -{ +static void btif_hl_disable(void){ BTIF_TRACE_DEBUG1("%s", __FUNCTION__); if ((p_btif_hl_cb->state != BTIF_HL_STATE_DISABLING) && @@ -1020,8 +1328,7 @@ static void btif_hl_disable(void) ** Returns BOOLEAN ** *******************************************************************************/ -static BOOLEAN btif_hl_is_no_active_app(void) -{ +static BOOLEAN btif_hl_is_no_active_app(void){ BOOLEAN no_active_app = TRUE; UINT8 i; @@ -1038,19 +1345,16 @@ static BOOLEAN btif_hl_is_no_active_app(void) return no_active_app; } -static void btif_hl_free_pending_reg_idx(UINT8 reg_idx) -{ - - - if ((reg_idx < BTA_HL_NUM_APPS) && btif_hl_cb.pcb[reg_idx].in_use ) - { - btif_hl_cb.pcb[reg_idx].in_use = FALSE; - memset (&btif_hl_cb.pcb[reg_idx], 0, sizeof(btif_hl_pending_reg_cb_t)); - } -} - -static void btif_hl_free_app_idx(UINT8 app_idx) -{ +/******************************************************************************* +** +** Function btif_hl_free_app_idx +** +** Description free an application control block +** +** Returns void +** +*******************************************************************************/ +static void btif_hl_free_app_idx(UINT8 app_idx){ if ((app_idx < BTA_HL_NUM_APPS) && btif_hl_cb.acb[app_idx].in_use ) { @@ -1058,15 +1362,31 @@ static void btif_hl_free_app_idx(UINT8 app_idx) memset (&btif_hl_cb.acb[app_idx], 0, sizeof(btif_hl_app_cb_t)); } } - -static void btif_hl_set_state(btif_hl_state_t state) -{ +/******************************************************************************* +** +** Function btif_hl_set_state +** +** Description set HL state +** +** Returns void +** +*******************************************************************************/ +static void btif_hl_set_state(btif_hl_state_t state){ BTIF_TRACE_DEBUG2("btif_hl_set_state: %d ---> %d ", p_btif_hl_cb->state, state); p_btif_hl_cb->state = state; } -static btif_hl_state_t btif_hl_get_state(void) -{ +/******************************************************************************* +** +** Function btif_hl_set_state +** +** Description get HL state +** +** Returns btif_hl_state_t +** +*******************************************************************************/ + +static btif_hl_state_t btif_hl_get_state(void){ BTIF_TRACE_DEBUG1("btif_hl_get_state: %d ", p_btif_hl_cb->state); return p_btif_hl_cb->state; } @@ -1080,8 +1400,7 @@ static btif_hl_state_t btif_hl_get_state(void) ** Returns BOOLEAN ** *******************************************************************************/ -static BOOLEAN btif_hl_find_data_type_idx(UINT16 data_type, UINT8 *p_idx) -{ +static BOOLEAN btif_hl_find_data_type_idx(UINT16 data_type, UINT8 *p_idx){ BOOLEAN found = FALSE; UINT8 i; @@ -1110,8 +1429,7 @@ static BOOLEAN btif_hl_find_data_type_idx(UINT16 data_type, UINT8 *p_idx) ** *******************************************************************************/ UINT16 btif_hl_get_max_tx_apdu_size(tBTA_HL_MDEP_ROLE mdep_role, - UINT16 data_type ) -{ + UINT16 data_type ){ UINT8 idx; UINT16 max_tx_apdu_size =0; @@ -1137,6 +1455,7 @@ UINT16 btif_hl_get_max_tx_apdu_size(tBTA_HL_MDEP_ROLE mdep_role, max_tx_apdu_size = BTIF_HL_DEFAULT_SRC_RX_APDU_SIZE; } + } BTIF_TRACE_DEBUG4("%s mdep_role=%d data_type=0x%4x size=%d", @@ -1156,8 +1475,7 @@ UINT16 btif_hl_get_max_tx_apdu_size(tBTA_HL_MDEP_ROLE mdep_role, ** *******************************************************************************/ UINT16 btif_hl_get_max_rx_apdu_size(tBTA_HL_MDEP_ROLE mdep_role, - UINT16 data_type ) -{ + UINT16 data_type ){ UINT8 idx; UINT16 max_rx_apdu_size =0; @@ -1189,14 +1507,19 @@ UINT16 btif_hl_get_max_rx_apdu_size(tBTA_HL_MDEP_ROLE mdep_role, __FUNCTION__, mdep_role, data_type, max_rx_apdu_size); return max_rx_apdu_size; - } +/******************************************************************************* +** +** Function btif_hl_if_channel_setup_pending +** +** Description +** +** Returns BOOLEAN +** +*******************************************************************************/ - - -static BOOLEAN btif_hl_get_bta_mdep_role(bthl_mdep_role_t mdep, tBTA_HL_MDEP_ROLE *p) -{ +static BOOLEAN btif_hl_get_bta_mdep_role(bthl_mdep_role_t mdep, tBTA_HL_MDEP_ROLE *p){ BOOLEAN status = TRUE; switch (mdep) { @@ -1211,13 +1534,21 @@ static BOOLEAN btif_hl_get_bta_mdep_role(bthl_mdep_role_t mdep, tBTA_HL_MDEP_ROL break; } - BTIF_TRACE_DEBUG3("%s status = %d BTA mdep_role=%d ", - __FUNCTION__, status, *p); + BTIF_TRACE_DEBUG4("%s status=%d bta_mdep_role=%d (%d:btif)", + __FUNCTION__, status, *p, mdep); return status; } +/******************************************************************************* +** +** Function btif_hl_get_bta_channel_type +** +** Description convert bthl channel type to BTA DCH channel type +** +** Returns BOOLEAN +** +*******************************************************************************/ -static BOOLEAN btif_hl_get_bta_channel_type(bthl_channel_type_t channel_type, tBTA_HL_DCH_CFG *p) -{ +static BOOLEAN btif_hl_get_bta_channel_type(bthl_channel_type_t channel_type, tBTA_HL_DCH_CFG *p){ BOOLEAN status = TRUE; switch (channel_type) { @@ -1238,54 +1569,80 @@ static BOOLEAN btif_hl_get_bta_channel_type(bthl_channel_type_t channel_type, tB __FUNCTION__, status, *p); return status; } +/******************************************************************************* +** +** Function btif_hl_get_next_app_id +** +** Description get next applcation id +** +** Returns UINT8 +** +*******************************************************************************/ - - - -static UINT8 btif_hl_get_next_app_id() -{ +static UINT8 btif_hl_get_next_app_id(){ UINT8 next_app_id = btif_hl_cb.next_app_id; btif_hl_cb.next_app_id++; - /* todo check the new channel_is is in use or not if in use go to next channel id and repeat the checking */ - return next_app_id; } - -static int btif_hl_get_next_channel_id(UINT8 app_id) -{ +/******************************************************************************* +** +** Function btif_hl_get_next_channel_id +** +** Description get next channel id +** +** Returns int +** +*******************************************************************************/ +static int btif_hl_get_next_channel_id(UINT8 app_id){ UINT16 next_channel_id = btif_hl_cb.next_channel_id; int channel_id; btif_hl_cb.next_channel_id++; - channel_id = (app_id << 16) + next_channel_id; - BTIF_TRACE_DEBUG4("%s channel_id=0x%08x, app_id=0x%02x0000 next_channel_id=0x%04x", __FUNCTION__, channel_id, app_id, next_channel_id); - /* todo check the new channel_is is in use or not if in use go to next channel id and repeat the checking */ return channel_id; } +/******************************************************************************* +** +** Function btif_hl_get_app_id +** +** Description get the applicaiton id associated with the channel id +** +** Returns UINT8 +** +*******************************************************************************/ - -static UINT8 btif_hl_get_app_id(int channel_id) -{ +static UINT8 btif_hl_get_app_id(int channel_id){ UINT8 app_id =(UINT8) (channel_id >> 16); - BTIF_TRACE_DEBUG3("%s channel_id=0x%08x, app_id=0x%02x ", __FUNCTION__,channel_id, app_id); return app_id; } - -static void btif_hl_init_next_app_id(void) -{ - btif_hl_cb.next_app_id = 1; /* todo check existing app_ids and initialize next avail app_id */ +/******************************************************************************* +** +** Function btif_hl_init_next_app_id +** +** Description initialize the application id +** +** Returns void +** +*******************************************************************************/ +static void btif_hl_init_next_app_id(void){ + btif_hl_cb.next_app_id = 1; } - -static void btif_hl_init_next_channel_id(void) -{ - btif_hl_cb.next_channel_id = 1; /* todo check existing app_ids and initialize next avail app_id */ +/******************************************************************************* +** +** Function btif_hl_init_next_channel_id +** +** Description initialize the channel id +** +** Returns void +** +*******************************************************************************/ +static void btif_hl_init_next_channel_id(void){ + btif_hl_cb.next_channel_id = 1; } - /******************************************************************************* ** ** Function btif_hl_save_mdl_cfg @@ -1296,47 +1653,65 @@ static void btif_hl_init_next_channel_id(void) ** *******************************************************************************/ BOOLEAN btif_hl_save_mdl_cfg(UINT8 app_id, UINT8 item_idx, - tBTA_HL_MDL_CFG *p_mdl_cfg) -{ - btif_hl_mdl_cfg_t *p_mdl=NULL; + tBTA_HL_MDL_CFG *p_mdl_cfg){ + btif_hl_mdl_cfg_t *p_mdl=NULL; BOOLEAN success = FALSE; - btif_hl_app_cb_t *p_acb; - btif_hl_mcl_cb_t *p_mcb; - UINT8 app_idx, mcl_idx, mdl_idx; + btif_hl_app_cb_t *p_acb; + btif_hl_mcl_cb_t *p_mcb; + UINT8 app_idx, mcl_idx, mdl_idx, len; + bt_status_t bt_status; + btif_hl_evt_cb_t evt_param; + int *p_channel_id; - BTIF_TRACE_DEBUG5("%s app_ids=%d item_idx=%d, local_mdep_id=%d mdl_id=%d",__FUNCTION__, app_id, item_idx, p_mdl_cfg->local_mdep_id, p_mdl_cfg->mdl_id ); + BTIF_TRACE_DEBUG6("%s app_ids=%d item_idx=%d, local_mdep_id=%d mdl_id=0x%x dch_mode=%d", + __FUNCTION__, app_id, item_idx, p_mdl_cfg->local_mdep_id, + p_mdl_cfg->mdl_id, p_mdl_cfg->dch_mode ); if (btif_hl_find_app_idx(app_id, &app_idx)) { p_acb = BTIF_HL_GET_APP_CB_PTR(app_idx); p_mdl = BTIF_HL_GET_MDL_CFG_PTR(app_idx, item_idx); + p_channel_id = BTIF_HL_GET_MDL_CFG_CHANNEL_ID_PTR(app_idx, item_idx); if (p_mdl) { memcpy(&p_mdl->base, p_mdl_cfg, sizeof(tBTA_HL_MDL_CFG)); if (btif_hl_find_mcl_idx(app_idx, p_mdl->base.peer_bd_addr , &mcl_idx)) { p_mcb = BTIF_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); - p_mdl->extra.app_active = TRUE; - p_mdl->extra.app_idx = app_idx; - p_mdl->extra.channel_id = p_mcb->pcb.channel_id ; + *p_channel_id = p_mcb->pcb.channel_id ; p_mdl->extra.mdep_cfg_idx = p_mcb->pcb.mdep_cfg_idx; p_mdl->extra.data_type = p_acb->sup_feature.mdep[p_mcb->pcb.mdep_cfg_idx].mdep_cfg.data_cfg[0].data_type; - BTIF_TRACE_DEBUG3("channel_id=0x%08x mdep_cfg_idx=%d, data_type=0x%04x",p_mdl->extra.channel_id, p_mdl->extra.mdep_cfg_idx, p_mdl->extra.data_type ); - /* todo update NV */ - success = TRUE; + if (!btif_hl_find_peer_mdep_id(p_acb->app_id, p_mcb->bd_addr, + p_acb->sup_feature.mdep[p_mcb->pcb.mdep_cfg_idx].mdep_cfg.mdep_role, + p_acb->sup_feature.mdep[p_mcb->pcb.mdep_cfg_idx].mdep_cfg.data_cfg[0].data_type, &p_mdl->extra.peer_mdep_id)) + { + p_mdl->extra.peer_mdep_id = BTA_HL_INVALID_MDEP_ID; + } + BTIF_TRACE_DEBUG6("channel_id=0x%08x mdep_cfg_idx=%d, data_type=0x%04x mdep_role=%d local_mdep_id=%d peer_mdep_id=%d", + *p_channel_id, + p_mdl->extra.mdep_cfg_idx, + p_mdl->extra.data_type, + p_mdl->base.local_mdep_role, + p_mdl->base.local_mdep_id, + p_mdl->extra.peer_mdep_id); + evt_param.update_mdl.app_idx = app_idx; + len = sizeof(btif_hl_update_mdl_t); + BTIF_TRACE_DEBUG1("send BTIF_HL_UPDATE_MDL event app_idx=%d ",app_idx); + if ((bt_status = btif_transfer_context (btif_hl_proc_cb_evt, BTIF_HL_UPDATE_MDL, + (char*) &evt_param, len, NULL)) == BT_STATUS_SUCCESS) + { + success = TRUE; + } + ASSERTC(bt_status == BT_STATUS_SUCCESS, "context transfer failed", bt_status); } } } - - BTIF_TRACE_DEBUG2("%s success=%d ",__FUNCTION__, success ); return success; } - - /******************************************************************************* ** ** Function btif_hl_delete_mdl_cfg @@ -1346,12 +1721,13 @@ BOOLEAN btif_hl_save_mdl_cfg(UINT8 app_id, UINT8 item_idx, ** Returns BOOLEAN ** *******************************************************************************/ -BOOLEAN btif_hl_delete_mdl_cfg(UINT8 app_id, UINT8 item_idx) -{ +BOOLEAN btif_hl_delete_mdl_cfg(UINT8 app_id, UINT8 item_idx){ btif_hl_mdl_cfg_t *p_mdl=NULL; BOOLEAN success = FALSE; btif_hl_app_cb_t *p_acb; - UINT8 app_idx; + UINT8 app_idx, len; + bt_status_t bt_status; + btif_hl_evt_cb_t evt_param; if (btif_hl_find_app_idx(app_id, &app_idx)) { @@ -1362,15 +1738,19 @@ BOOLEAN btif_hl_delete_mdl_cfg(UINT8 app_id, UINT8 item_idx) if (p_mdl) { memset(p_mdl, 0, sizeof(btif_hl_mdl_cfg_t)); - /* todo update NV */ - success = TRUE; + evt_param.update_mdl.app_idx = app_idx; + len = sizeof(btif_hl_update_mdl_t); + BTIF_TRACE_DEBUG1("send BTIF_HL_UPDATE_MDL event app_idx=%d ",app_idx); + if ((bt_status = btif_transfer_context (btif_hl_proc_cb_evt, BTIF_HL_UPDATE_MDL, + (char*) &evt_param, len, NULL)) == BT_STATUS_SUCCESS) + { + success = TRUE; + } + ASSERTC(bt_status == BT_STATUS_SUCCESS, "context transfer failed", bt_status); } } - BTIF_TRACE_DEBUG2("%s success=%d ",__FUNCTION__, success ); - - return success; } @@ -1384,8 +1764,7 @@ BOOLEAN btif_hl_delete_mdl_cfg(UINT8 app_id, UINT8 item_idx) ** *******************************************************************************/ BOOLEAN btif_hl_find_app_idx_using_handle(tBTA_HL_APP_HANDLE app_handle, - UINT8 *p_app_idx) -{ + UINT8 *p_app_idx){ BOOLEAN found=FALSE; UINT8 i; @@ -1416,8 +1795,7 @@ BOOLEAN btif_hl_find_app_idx_using_handle(tBTA_HL_APP_HANDLE app_handle, ** *******************************************************************************/ BOOLEAN btif_hl_find_mcl_idx_using_handle( tBTA_HL_MCL_HANDLE mcl_handle, - UINT8 *p_app_idx, UINT8 *p_mcl_idx) -{ + UINT8 *p_app_idx, UINT8 *p_mcl_idx){ btif_hl_app_cb_t *p_acb; BOOLEAN found=FALSE; UINT8 i,j; @@ -1437,7 +1815,6 @@ BOOLEAN btif_hl_find_mcl_idx_using_handle( tBTA_HL_MCL_HANDLE mcl_handle, } } } - BTIF_TRACE_DEBUG4("%s found=%d app_idx=%d mcl_idx=%d",__FUNCTION__, found, i, j); return found; @@ -1452,8 +1829,7 @@ BOOLEAN btif_hl_find_mcl_idx_using_handle( tBTA_HL_MCL_HANDLE mcl_handle, ** Returns BOOLEAN ** *******************************************************************************/ -BOOLEAN btif_hl_find_app_idx(UINT8 app_id, UINT8 *p_app_idx) -{ +BOOLEAN btif_hl_find_app_idx(UINT8 app_id, UINT8 *p_app_idx){ BOOLEAN found=FALSE; UINT8 i; @@ -1476,62 +1852,6 @@ BOOLEAN btif_hl_find_app_idx(UINT8 app_id, UINT8 *p_app_idx) /******************************************************************************* ** -** Function btif_hl_find_avail_app_idx -** -** Description Find a not in-use APP index -** -** Returns BOOLEAN -** -*******************************************************************************/ -static BOOLEAN btif_hl_find_avail_pending_reg_idx(UINT8 *p_idx) -{ - BOOLEAN found = FALSE; - UINT8 i; - - for (i=0; i < BTA_HL_NUM_APPS ; i ++) - { - if (!btif_hl_cb.pcb[i].in_use) - { - found = TRUE; - *p_idx = i; - break; - } - } - - BTIF_TRACE_DEBUG3("%s found=%d app_idx=%d", __FUNCTION__, found, i); - return found; -} - -/******************************************************************************* -** -** Function btif_hl_find_avail_pending_chan_idx -** -** Description Find a not in-use pending chan index -** -** Returns BOOLEAN -** -*******************************************************************************/ -/*static BOOLEAN btif_hl_find_avail_pending_chan_idx(UINT8 app_idx, UINT8 mcl_idx, UINT8 *p_idx) -{ - BOOLEAN found = FALSE; - UINT8 i; - - for (i=0; i < BTA_HL_NUM_MDLS_PER_MCL ; i ++) - { - if (!btif_hl_cb.acb[app_idx].mcb[mcl_idx].pcb[i].in_use) - { - found = TRUE; - *p_idx = i; - break; - } - } - - BTIF_TRACE_DEBUG3("%s found=%d app_idx=%d", __FUNCTION__, found, i); - return found; -} -*/ -/******************************************************************************* -** ** Function btif_hl_find_avail_mdl_idx ** ** Description Find a not in-use MDL index @@ -1540,8 +1860,7 @@ static BOOLEAN btif_hl_find_avail_pending_reg_idx(UINT8 *p_idx) ** *******************************************************************************/ BOOLEAN btif_hl_find_avail_mdl_idx(UINT8 app_idx, UINT8 mcl_idx, - UINT8 *p_mdl_idx) -{ + UINT8 *p_mdl_idx){ btif_hl_mcl_cb_t *p_mcb = BTIF_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); BOOLEAN found=FALSE; UINT8 i; @@ -1561,7 +1880,6 @@ BOOLEAN btif_hl_find_avail_mdl_idx(UINT8 app_idx, UINT8 mcl_idx, return found; } - /******************************************************************************* ** ** Function btif_hl_find_avail_mcl_idx @@ -1571,8 +1889,7 @@ BOOLEAN btif_hl_find_avail_mdl_idx(UINT8 app_idx, UINT8 mcl_idx, ** Returns BOOLEAN ** *******************************************************************************/ -BOOLEAN btif_hl_find_avail_mcl_idx(UINT8 app_idx, UINT8 *p_mcl_idx) -{ +BOOLEAN btif_hl_find_avail_mcl_idx(UINT8 app_idx, UINT8 *p_mcl_idx){ BOOLEAN found=FALSE; UINT8 i; @@ -1598,8 +1915,7 @@ BOOLEAN btif_hl_find_avail_mcl_idx(UINT8 app_idx, UINT8 *p_mcl_idx) ** Returns BOOLEAN ** *******************************************************************************/ -static BOOLEAN btif_hl_find_avail_app_idx(UINT8 *p_idx) -{ +static BOOLEAN btif_hl_find_avail_app_idx(UINT8 *p_idx){ BOOLEAN found = FALSE; UINT8 i; @@ -1618,11 +1934,6 @@ static BOOLEAN btif_hl_find_avail_app_idx(UINT8 *p_idx) } - -/************************************************************************************ -** Functions -************************************************************************************/ - /******************************************************************************* ** ** Function btif_hl_proc_dereg_cfm @@ -1644,28 +1955,161 @@ static void btif_hl_proc_dereg_cfm(tBTA_HL *p_data) if (btif_hl_find_app_idx_using_handle(p_data->dereg_cfm.app_handle, &app_idx)) { p_acb = BTIF_HL_GET_APP_CB_PTR(app_idx); + app_id = (int) p_acb->app_id; if (p_data->dereg_cfm.status == BTA_HL_STATUS_OK) - { - app_id = (int) p_acb->app_id; memset(p_acb, 0,sizeof(btif_hl_app_cb_t)); - } else - { state = BTHL_APP_REG_STATE_DEREG_FAILED; - } - BTIF_TRACE_DEBUG2("app_id=%d state=%d", app_id, state); + BTIF_TRACE_DEBUG2("call reg state callback app_id=%d state=%d", app_id, state); BTIF_HL_CALL_CBACK(bt_hl_callbacks, app_reg_state_cb, app_id, state ); if (btif_hl_is_no_active_app()) { btif_hl_disable(); } + } +} + +/******************************************************************************* +** +** Function btif_hl_find_non_ative_app_nv_idx +** +** Description find a non-active applicaiton NV index +** +** Returns BOOLEAN TRUE-found +** +*******************************************************************************/ + +BOOLEAN btif_hl_find_non_ative_app_nv_idx(UINT8 *p_idx){ + BOOLEAN found = FALSE; + UINT8 i, cur_nv_idx=0; + UINT16 cur_use_freq =0xFFFF; + btif_hl_app_data_t *p_data; + + BTIF_TRACE_DEBUG1("%s", __FUNCTION__); + if (!GKI_queue_is_empty(&p_ncb->app_queue)) + { + p_data = (btif_hl_app_data_t *)GKI_getfirst((void *)&p_ncb->app_queue); + while (p_data != NULL) + { + if (!p_data->active) + { + found = TRUE; + /* find least used app_nv_idx */ + if (cur_use_freq >= p_ncb->app_cb.app[p_data->app_nv_idx].use_freq) + { + cur_use_freq = p_ncb->app_cb.app[p_data->app_nv_idx].use_freq; + *p_idx = p_data->app_nv_idx; + } + } + p_data = (btif_hl_app_data_t *)GKI_getnext((void *)p_data); + } } + + BTIF_TRACE_DEBUG2(" found=%d idx=%d", found , *p_idx); + return found; } +/******************************************************************************* +** +** Function btif_hl_find_avail_app_nv_idx +** +** Description find a not in use applicaiton NV index +** +** Returns BOOLEAN +** +*******************************************************************************/ +BOOLEAN btif_hl_find_avail_app_nv_idx(UINT8 *p_idx){ + BOOLEAN found = FALSE; + UINT8 i, first_idx; + BTIF_TRACE_DEBUG1("%s", __FUNCTION__); + + for (i=0;i<BTIF_HL_NV_MAX_APPS; i++) + { + if (!p_ncb->app_cb.app[i].in_use) + { + found = TRUE; + *p_idx = i; + break; + } + } + + if (!found ) + btif_hl_find_non_ative_app_nv_idx (p_idx); + + BTIF_TRACE_DEBUG2(" found=%d idx=%d", found , *p_idx); + return found; +} + +/******************************************************************************* +** +** Function btif_hl_save_app_data +** +** Description Save an applicaiton registration data into NV +** +** Returns BOOLEAN +** +*******************************************************************************/ +BOOLEAN btif_hl_save_app_data(UINT8 app_idx){ + BOOLEAN status = FALSE; + btif_hl_app_cb_t *p_acb = BTIF_HL_GET_APP_CB_PTR(app_idx); + btif_hl_app_data_t *p_data = GKI_getbuf((UINT16)sizeof( btif_hl_app_data_t)); + btif_hl_nv_app_data_t *p_app; + UINT8 app_nv_idx; + bt_status_t bt_status; + + BTIF_TRACE_DEBUG4("%s app_idx=%d p_acb=0x%x p_data=0x%x", __FUNCTION__, app_idx, p_acb, p_data); + + if (p_acb && p_data && btif_hl_find_avail_app_nv_idx(&app_nv_idx)) + { + BTIF_TRACE_DEBUG1("app_nv_idx=%d ",app_nv_idx ); + p_app = &p_data->app_data; + + memcpy(p_app->application_name, p_acb->application_name, (BTIF_HL_APPLICATION_NAME_LEN +1) ); + memcpy(p_app->provider_name, p_acb->provider_name, (BTA_PROVIDER_NAME_LEN +1) ); + memcpy(p_app->srv_name, p_acb->srv_name, (BTA_SERVICE_NAME_LEN +1) ); + memcpy(p_app->srv_desp, p_acb->srv_desp, (BTA_SERVICE_DESP_LEN +1) ); + memcpy(p_app->channel_type, p_acb->channel_type, (sizeof(tBTA_HL_DCH_CFG)*BTA_HL_NUM_MDEPS)); + memcpy((void *) &p_app->sup_feature, (void *) &p_acb->sup_feature, sizeof(tBTA_HL_SUP_FEATURE)); + + + if ((bt_status = btif_storage_write_hl_app_data(app_nv_idx,(char *) p_app, + sizeof(btif_hl_nv_app_data_t)))== BT_STATUS_SUCCESS) + { + if ((bt_status = btif_storage_write_hl_mdl_data(app_nv_idx,(char *) &p_acb->mdl_cfg[0], + sizeof(btif_hl_nv_mdl_data_t)))== BT_STATUS_SUCCESS) + { + p_ncb->app_cb.app[app_nv_idx].in_use = TRUE; + p_ncb->app_cb.app[app_nv_idx].use_freq = 1; + if ((bt_status = btif_storage_write_hl_apps_cb((char *) &p_ncb->app_cb, + sizeof(btif_hl_nv_app_cb_t)))== BT_STATUS_SUCCESS) + { + status = TRUE; + p_data->active = TRUE; + p_acb->app_nv_idx = + p_data->app_nv_idx = app_nv_idx; + p_data->app_idx = app_idx; + + BTIF_TRACE_DEBUG2("p_data active=TRUE app_nv_idx =%d app_idx=%d ",app_nv_idx, app_idx ); + GKI_enqueue(&p_ncb->app_queue,p_data); + + + } + else + { + p_ncb->app_cb.app[app_nv_idx].in_use = FALSE; + } + } + } + } + + if (!status) + btif_hl_free_buf((void **) &p_data); + return status; +} /******************************************************************************* ** @@ -1676,22 +2120,52 @@ static void btif_hl_proc_dereg_cfm(tBTA_HL *p_data) ** Returns Nothing ** *******************************************************************************/ -static void btif_hl_proc_reg_cfm(tBTA_HL *p_data) - -{ - btif_hl_app_cb_t *p_acb; - UINT8 app_idx; - bthl_app_reg_state_t state = BTHL_APP_REG_STATE_REG_SUCCESS; +static void btif_hl_proc_reg_cfm(tBTA_HL *p_data){ + btif_hl_app_cb_t *p_acb; + UINT8 app_idx; + bthl_app_reg_state_t state = BTHL_APP_REG_STATE_REG_SUCCESS; + bt_status_t bt_status; BTIF_TRACE_DEBUG3("%s reg status=%d app_handle=%d", __FUNCTION__, p_data->reg_cfm.status, p_data->reg_cfm.app_handle); if (btif_hl_find_app_idx(p_data->reg_cfm.app_id, &app_idx)) { - p_acb =BTIF_HL_GET_APP_CB_PTR(app_idx); + p_acb = BTIF_HL_GET_APP_CB_PTR(app_idx); if (p_data->reg_cfm.status == BTA_HL_STATUS_OK) { p_acb->app_handle = p_data->reg_cfm.app_handle; + BTIF_TRACE_DEBUG1("is_new_app=%d", p_acb->is_new_app); + if (p_acb->is_new_app) + { + p_acb->is_new_app = FALSE; + if (!btif_hl_save_app_data(app_idx)) + { + ASSERTC(FALSE, "Unable to save app data app_idx=%d", app_idx); + state = BTHL_APP_REG_STATE_REG_FAILED; + } + } + else + { + BTIF_TRACE_DEBUG3("Increase the use freq app_idx=%d app_nv_idx=%d cur_use_freq=%d", + app_idx, p_acb->app_nv_idx, p_ncb->app_cb.app[p_acb->app_nv_idx].use_freq); + if (p_ncb->app_cb.app[p_acb->app_nv_idx].use_freq != 0xFFFF ) + p_ncb->app_cb.app[p_acb->app_nv_idx].use_freq ++; + + p_ncb->app_cb.app[p_acb->app_nv_idx].in_use = TRUE; + if ((bt_status = btif_storage_write_hl_apps_cb((char *) &p_ncb->app_cb, + sizeof(btif_hl_nv_app_cb_t)))!= BT_STATUS_SUCCESS) + { + ASSERTC(bt_status == BT_STATUS_SUCCESS, "Unable to save app_cb into NV app_nv_idx=%d ", p_acb->app_nv_idx); + state = BTHL_APP_REG_STATE_REG_FAILED; + } + } + + if (state == BTHL_APP_REG_STATE_REG_FAILED) + { + BTA_HlDeregister(p_acb->app_handle); + btif_hl_free_app_idx(app_idx); + } } else { @@ -1699,7 +2173,7 @@ static void btif_hl_proc_reg_cfm(tBTA_HL *p_data) state = BTHL_APP_REG_STATE_REG_FAILED; } - BTIF_TRACE_DEBUG3("%s app_id=%d reg state=%d", __FUNCTION__, p_data->reg_cfm.app_id, state); + BTIF_TRACE_DEBUG3("%s call reg state callback app_id=%d reg state=%d", __FUNCTION__, p_data->reg_cfm.app_id, state); BTIF_HL_CALL_CBACK(bt_hl_callbacks, app_reg_state_cb, ((int) p_data->reg_cfm.app_id), state ); } } @@ -1726,9 +2200,16 @@ static void btif_hl_proc_sdp_info_ind(tBTA_HL *p_data) memcpy(&p_acb->sdp_info_ind, &p_data->sdp_info_ind, sizeof(tBTA_HL_SDP_INFO_IND)); } } - -void btif_hl_set_chan_cb_state(UINT8 app_idx, UINT8 mcl_idx, btif_hl_chan_cb_state_t state) -{ +/******************************************************************************* +** +** Function btif_hl_set_chan_cb_state +** +** Description set the channel callback state +** +** Returns void +** +*******************************************************************************/ +void btif_hl_set_chan_cb_state(UINT8 app_idx, UINT8 mcl_idx, btif_hl_chan_cb_state_t state){ btif_hl_pending_chan_cb_t *p_pcb = BTIF_HL_GET_PCB_PTR(app_idx, mcl_idx); btif_hl_chan_cb_state_t cur_state = p_pcb->cb_state; @@ -1738,16 +2219,24 @@ void btif_hl_set_chan_cb_state(UINT8 app_idx, UINT8 mcl_idx, btif_hl_chan_cb_sta BTIF_TRACE_DEBUG3("%s state %d--->%d",__FUNCTION__, cur_state, state); } -} -void btif_hl_send_destroyed_cb(btif_hl_app_cb_t *p_acb ) -{ +} +/******************************************************************************* +** +** Function btif_hl_send_destroyed_cb +** +** Description send the channel destroyed callback +** +** Returns void +** +*******************************************************************************/ +void btif_hl_send_destroyed_cb(btif_hl_app_cb_t *p_acb ){ bt_bdaddr_t bd_addr; int app_id = (int) btif_hl_get_app_id(p_acb->delete_mdl.channel_id); btif_hl_copy_bda(&bd_addr, p_acb->delete_mdl.bd_addr); BTIF_TRACE_DEBUG1("%s",__FUNCTION__); - BTIF_TRACE_DEBUG4("channel_id=0x%08x mdep_cfg_idx=%d, state=%d fd=%d",p_acb->delete_mdl.channel_id, + BTIF_TRACE_DEBUG4("call channel state callback channel_id=0x%08x mdep_cfg_idx=%d, state=%d fd=%d",p_acb->delete_mdl.channel_id, p_acb->delete_mdl.mdep_cfg_idx, BTHL_CONN_STATE_DESTROYED, 0); btif_hl_display_bt_bda(&bd_addr); @@ -1755,10 +2244,16 @@ void btif_hl_send_destroyed_cb(btif_hl_app_cb_t *p_acb ) &bd_addr, p_acb->delete_mdl.mdep_cfg_idx, p_acb->delete_mdl.channel_id, BTHL_CONN_STATE_DESTROYED, 0 ); } - - -void btif_hl_send_disconnecting_cb(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx) -{ +/******************************************************************************* +** +** Function btif_hl_send_disconnecting_cb +** +** Description send a channel disconnecting callback +** +** Returns void +** +*******************************************************************************/ +void btif_hl_send_disconnecting_cb(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx){ btif_hl_mdl_cb_t *p_dcb = BTIF_HL_GET_MDL_CB_PTR( app_idx, mcl_idx, mdl_idx); btif_hl_soc_cb_t *p_scb = p_dcb->p_scb; bt_bdaddr_t bd_addr; @@ -1767,50 +2262,22 @@ void btif_hl_send_disconnecting_cb(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx) btif_hl_copy_bda(&bd_addr, p_scb->bd_addr); BTIF_TRACE_DEBUG1("%s",__FUNCTION__); - BTIF_TRACE_DEBUG4("channel_id=0x%08x mdep_cfg_idx=%d, state=%d fd=%d",p_scb->channel_id, + BTIF_TRACE_DEBUG4("call channel state callback channel_id=0x%08x mdep_cfg_idx=%d, state=%d fd=%d",p_scb->channel_id, p_scb->mdep_cfg_idx, BTHL_CONN_STATE_DISCONNECTING, p_scb->socket_id[0]); btif_hl_display_bt_bda(&bd_addr); BTIF_HL_CALL_CBACK(bt_hl_callbacks, channel_state_cb, app_id, &bd_addr, p_scb->mdep_cfg_idx, p_scb->channel_id, BTHL_CONN_STATE_DISCONNECTING, p_scb->socket_id[0] ); } - -void btif_hl_send_disconnected_cb( btif_hl_soc_cb_t *p_scb) -{ - bt_bdaddr_t bd_addr; - int app_id = (int) btif_hl_get_app_id(p_scb->channel_id); - - btif_hl_copy_bda(&bd_addr, p_scb->bd_addr); - - BTIF_TRACE_DEBUG1("%s",__FUNCTION__); - BTIF_TRACE_DEBUG4("channel_id=0x%08x mdep_cfg_idx=%d, state=%d fd=%d",p_scb->channel_id, - p_scb->mdep_cfg_idx, BTHL_CONN_STATE_DISCONNECTED, p_scb->socket_id[0]); - btif_hl_display_bt_bda(&bd_addr); - - BTIF_HL_CALL_CBACK(bt_hl_callbacks, channel_state_cb, app_id, - &bd_addr, p_scb->mdep_cfg_idx, - p_scb->channel_id, BTHL_CONN_STATE_DISCONNECTED, p_scb->socket_id[0] ); -} - - -void btif_hl_send_connected_cb(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx) -{ - btif_hl_mcl_cb_t *p_mcb = BTIF_HL_GET_MCL_CB_PTR( app_idx, mcl_idx); - btif_hl_mdl_cb_t *p_dcb = BTIF_HL_GET_MDL_CB_PTR( app_idx, mcl_idx, mdl_idx); - btif_hl_soc_cb_t *p_scb = p_dcb->p_scb; - bt_bdaddr_t bd_addr; - int app_id = (int) btif_hl_get_app_id(p_dcb->channel_id); - - btif_hl_copy_bda(&bd_addr, p_mcb->bd_addr); - BTIF_TRACE_DEBUG1("%s",__FUNCTION__); - BTIF_TRACE_DEBUG4("channel_id=0x%08x mdep_cfg_idx=%d, state=%d fd=%d",p_dcb->channel_id, - p_dcb->local_mdep_cfg_idx, BTHL_CONN_STATE_DISCONNECTED, p_scb->socket_id[0]); - btif_hl_display_bt_bda(&bd_addr); - BTIF_HL_CALL_CBACK(bt_hl_callbacks, channel_state_cb, app_id, - &bd_addr, p_dcb->local_mdep_cfg_idx, - p_dcb->channel_id, BTHL_CONN_STATE_CONNECTED, p_scb->socket_id[0] ); -} - +/******************************************************************************* +** +** Function btif_hl_send_setup_connecting_cb +** +** Description send a channel connecting callback +** +** Returns void +** +*******************************************************************************/ void btif_hl_send_setup_connecting_cb(UINT8 app_idx, UINT8 mcl_idx){ btif_hl_pending_chan_cb_t *p_pcb = BTIF_HL_GET_PCB_PTR(app_idx, mcl_idx); bt_bdaddr_t bd_addr; @@ -1821,7 +2288,7 @@ void btif_hl_send_setup_connecting_cb(UINT8 app_idx, UINT8 mcl_idx){ if (p_pcb->in_use && p_pcb->cb_state == BTIF_HL_CHAN_CB_STATE_CONNECTING_PENDING) { BTIF_TRACE_DEBUG1("%s",__FUNCTION__); - BTIF_TRACE_DEBUG4("channel_id=0x%08x mdep_cfg_idx=%d state=%d fd=%d",p_pcb->channel_id, + BTIF_TRACE_DEBUG4("call channel state callback channel_id=0x%08x mdep_cfg_idx=%d state=%d fd=%d",p_pcb->channel_id, p_pcb->mdep_cfg_idx, BTHL_CONN_STATE_CONNECTING, 0); btif_hl_display_bt_bda(&bd_addr); @@ -1831,7 +2298,15 @@ void btif_hl_send_setup_connecting_cb(UINT8 app_idx, UINT8 mcl_idx){ btif_hl_set_chan_cb_state(app_idx, mcl_idx, BTIF_HL_CHAN_CB_STATE_CONNECTED_PENDING); } } - +/******************************************************************************* +** +** Function btif_hl_send_setup_disconnected_cb +** +** Description send a channel disconnected callback +** +** Returns void +** +*******************************************************************************/ void btif_hl_send_setup_disconnected_cb(UINT8 app_idx, UINT8 mcl_idx){ btif_hl_pending_chan_cb_t *p_pcb = BTIF_HL_GET_PCB_PTR(app_idx, mcl_idx); bt_bdaddr_t bd_addr; @@ -1845,14 +2320,14 @@ void btif_hl_send_setup_disconnected_cb(UINT8 app_idx, UINT8 mcl_idx){ BTIF_TRACE_DEBUG1("%p_pcb->cb_state=%d",p_pcb->cb_state); if (p_pcb->cb_state == BTIF_HL_CHAN_CB_STATE_CONNECTING_PENDING) { - BTIF_TRACE_DEBUG4("channel_id=0x%08x mdep_cfg_idx=%d state=%d fd=%d",p_pcb->channel_id, + BTIF_TRACE_DEBUG4("call channel state callback channel_id=0x%08x mdep_cfg_idx=%d state=%d fd=%d",p_pcb->channel_id, p_pcb->mdep_cfg_idx, BTHL_CONN_STATE_CONNECTING, 0); btif_hl_display_bt_bda(&bd_addr); BTIF_HL_CALL_CBACK(bt_hl_callbacks, channel_state_cb, app_id, &bd_addr, p_pcb->mdep_cfg_idx, p_pcb->channel_id, BTHL_CONN_STATE_CONNECTING, 0 ); - BTIF_TRACE_DEBUG4("channel_id=0x%08x mdep_cfg_idx=%d state=%d fd=%d",p_pcb->channel_id, + BTIF_TRACE_DEBUG4("call channel state callback channel_id=0x%08x mdep_cfg_idx=%d state=%d fd=%d",p_pcb->channel_id, p_pcb->mdep_cfg_idx, BTHL_CONN_STATE_DISCONNECTED, 0); btif_hl_display_bt_bda(&bd_addr); BTIF_HL_CALL_CBACK(bt_hl_callbacks, channel_state_cb, app_id, @@ -1861,7 +2336,7 @@ void btif_hl_send_setup_disconnected_cb(UINT8 app_idx, UINT8 mcl_idx){ } else if (p_pcb->cb_state == BTIF_HL_CHAN_CB_STATE_CONNECTED_PENDING) { - BTIF_TRACE_DEBUG4("channel_id=0x%08x mdep_cfg_idx=%d state=%d fd=%d",p_pcb->channel_id, + BTIF_TRACE_DEBUG4("call channel state callback channel_id=0x%08x mdep_cfg_idx=%d state=%d fd=%d",p_pcb->channel_id, p_pcb->mdep_cfg_idx, BTHL_CONN_STATE_DISCONNECTED, 0); btif_hl_display_bt_bda(&bd_addr); BTIF_HL_CALL_CBACK(bt_hl_callbacks, channel_state_cb, app_id, @@ -1942,26 +2417,32 @@ static BOOLEAN btif_hl_proc_sdp_query_cfm(tBTA_HL *p_data){ p_mcb->valid_sdp_idx = TRUE; p_mcb->ctrl_psm = p_mcb->sdp.sdp_rec[sdp_idx].ctrl_psm; - switch (old_cch_oper) { case BTIF_HL_CCH_OP_MDEP_FILTERING: p_pcb = BTIF_HL_GET_PCB_PTR(app_idx, mcl_idx); if (p_pcb->in_use) { - switch (p_pcb->op) + if (!p_pcb->abort_pending) + { + switch (p_pcb->op) + { + case BTIF_HL_PEND_DCH_OP_OPEN: + btif_hl_send_setup_connecting_cb(app_idx, mcl_idx); + break; + case BTIF_HL_PEND_DCH_OP_DELETE_MDL: + default: + break; + } + open_param.ctrl_psm = p_mcb->ctrl_psm; + bdcpy(open_param.bd_addr, p_mcb->bd_addr); + open_param.sec_mask = (BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT); + BTA_HlCchOpen(p_acb->app_handle, &open_param); + } + else { - case BTIF_HL_PEND_DCH_OP_OPEN: - btif_hl_send_setup_connecting_cb(app_idx, mcl_idx); - break; - case BTIF_HL_PEND_DCH_OP_DELETE_MDL: - default: - break; + BTIF_TRACE_DEBUG0("channel abort pending"); } - open_param.ctrl_psm = p_mcb->ctrl_psm; - bdcpy(open_param.bd_addr, p_mcb->bd_addr); - open_param.sec_mask = (BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT); - BTA_HlCchOpen(p_acb->app_handle, &open_param); } break; @@ -1969,17 +2450,12 @@ static BOOLEAN btif_hl_proc_sdp_query_cfm(tBTA_HL *p_data){ status = btif_hl_proc_pending_op(app_idx,mcl_idx); break; - case BTIF_HL_CCH_OP_DCH_RECONNECT: - //reconnect_param.ctrl_psm = p_mcb->ctrl_psm; - //reconnect_param.mdl_id = p_mcb->acquire.acquire_info.mdl_id; - //BTA_HlDchReconnect(p_mcb->mcl_handle, &reconnect_param); - break; - default: BTIF_TRACE_ERROR1("Invalid CCH oper %d", old_cch_oper); break; } + } else { @@ -2021,6 +2497,7 @@ static void btif_hl_proc_cch_open_ind(tBTA_HL *p_data) p_mcb->is_connected = TRUE; p_mcb->mcl_handle = p_data->cch_open_ind.mcl_handle; bdcpy(p_mcb->bd_addr, p_data->cch_open_ind.bd_addr); + btif_hl_start_cch_timer(app_idx, mcl_idx); } } else @@ -2048,6 +2525,8 @@ BOOLEAN btif_hl_proc_pending_op(UINT8 app_idx, UINT8 mcl_idx) btif_hl_pending_chan_cb_t *p_pcb; BOOLEAN status = FALSE; tBTA_HL_DCH_OPEN_PARAM dch_open; + tBTA_HL_MDL_ID mdl_id; + tBTA_HL_DCH_RECONNECT_PARAM reconnect_param; p_pcb = BTIF_HL_GET_PCB_PTR(app_idx, mcl_idx); if (p_pcb->in_use) @@ -2055,25 +2534,43 @@ BOOLEAN btif_hl_proc_pending_op(UINT8 app_idx, UINT8 mcl_idx) switch (p_pcb->op) { case BTIF_HL_PEND_DCH_OP_OPEN: - BTIF_TRACE_DEBUG0("op BTIF_HL_PEND_DCH_OP_OPEN"); - dch_open.ctrl_psm = p_mcb->ctrl_psm; - dch_open.local_mdep_id = p_acb->sup_feature.mdep[p_pcb->mdep_cfg_idx].mdep_id; - if (btif_hl_find_peer_mdep_id(p_acb->app_id, p_mcb->bd_addr, - p_acb->sup_feature.mdep[p_pcb->mdep_cfg_idx].mdep_cfg.mdep_role, - p_acb->sup_feature.mdep[p_pcb->mdep_cfg_idx].mdep_cfg.data_cfg[0].data_type, &dch_open.peer_mdep_id )) + if (!p_pcb->abort_pending) { - dch_open.local_cfg = p_acb->channel_type[p_pcb->mdep_cfg_idx]; - if ((p_acb->sup_feature.mdep[p_pcb->mdep_cfg_idx].mdep_cfg.mdep_role == BTA_HL_MDEP_ROLE_SOURCE) - && !btif_hl_is_the_first_reliable_existed(app_idx, mcl_idx)) + BTIF_TRACE_DEBUG0("op BTIF_HL_PEND_DCH_OP_OPEN"); + dch_open.ctrl_psm = p_mcb->ctrl_psm; + dch_open.local_mdep_id = p_acb->sup_feature.mdep[p_pcb->mdep_cfg_idx].mdep_id; + if (btif_hl_find_peer_mdep_id(p_acb->app_id, p_mcb->bd_addr, + p_acb->sup_feature.mdep[p_pcb->mdep_cfg_idx].mdep_cfg.mdep_role, + p_acb->sup_feature.mdep[p_pcb->mdep_cfg_idx].mdep_cfg.data_cfg[0].data_type, &dch_open.peer_mdep_id )) { - dch_open.local_cfg = BTA_HL_DCH_CFG_RELIABLE; - } - dch_open.sec_mask = (BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT); + dch_open.local_cfg = p_acb->channel_type[p_pcb->mdep_cfg_idx]; + if ((p_acb->sup_feature.mdep[p_pcb->mdep_cfg_idx].mdep_cfg.mdep_role == BTA_HL_MDEP_ROLE_SOURCE) + && !btif_hl_is_the_first_reliable_existed(app_idx, mcl_idx)) + { + dch_open.local_cfg = BTA_HL_DCH_CFG_RELIABLE; + } + dch_open.sec_mask = (BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT); + BTIF_TRACE_DEBUG1("dch_open.local_cfg=%d ", dch_open.local_cfg); + btif_hl_send_setup_connecting_cb(app_idx,mcl_idx); - BTIF_TRACE_DEBUG1("dch_open.local_cfg=%d ", dch_open.local_cfg); - BTIF_TRACE_DEBUG0("calling BTA_HlDchOpen"); - btif_hl_send_setup_connecting_cb(app_idx,mcl_idx); - BTA_HlDchOpen(p_mcb->mcl_handle, &dch_open); + if (!btif_hl_is_reconnect_possible(app_idx, mcl_idx, p_pcb->mdep_cfg_idx, &dch_open, &mdl_id )) + { + BTIF_TRACE_DEBUG0("Issue DCH open" ); + BTA_HlDchOpen(p_mcb->mcl_handle, &dch_open); + } + else + { + reconnect_param.ctrl_psm = p_mcb->ctrl_psm; + reconnect_param.mdl_id = mdl_id;; + BTIF_TRACE_DEBUG2("Issue Reconnect ctrl_psm=0x%x mdl_id=0x%x",reconnect_param.ctrl_psm, reconnect_param.mdl_id); + BTA_HlDchReconnect(p_mcb->mcl_handle, &reconnect_param); + } + status = TRUE; + } + } + else + { + btif_hl_send_setup_disconnected_cb(app_idx, mcl_idx); status = TRUE; } break; @@ -2085,15 +2582,10 @@ BOOLEAN btif_hl_proc_pending_op(UINT8 app_idx, UINT8 mcl_idx) default: break; } - - } return status; } - - - /******************************************************************************* ** ** Function btif_hl_proc_cch_open_cfm @@ -2126,10 +2618,9 @@ static BOOLEAN btif_hl_proc_cch_open_cfm(tBTA_HL *p_data) BTIF_TRACE_DEBUG1("mcl_idx=%d", mcl_idx); p_mcb->mcl_handle = p_data->cch_open_cfm.mcl_handle; p_mcb->is_connected = TRUE; - status = btif_hl_proc_pending_op(app_idx, mcl_idx); - - + if (status) + btif_hl_start_cch_timer(app_idx, mcl_idx); } } @@ -2154,6 +2645,7 @@ static void btif_hl_proc_cch_close_ind(tBTA_HL *p_data) if (btif_hl_find_mcl_idx_using_handle(p_data->cch_close_ind.mcl_handle, &app_idx, &mcl_idx)) { + btif_hl_stop_cch_timer(app_idx, mcl_idx); btif_hl_send_setup_disconnected_cb(app_idx, mcl_idx); btif_hl_release_mcl_sockets(app_idx, mcl_idx); btif_hl_clean_mcl_cb(app_idx, mcl_idx); @@ -2171,13 +2663,13 @@ static void btif_hl_proc_cch_close_ind(tBTA_HL *p_data) ** *******************************************************************************/ static void btif_hl_proc_cch_close_cfm(tBTA_HL *p_data) - { UINT8 app_idx, mcl_idx; BTIF_TRACE_DEBUG1("%s", __FUNCTION__); if (btif_hl_find_mcl_idx_using_handle(p_data->cch_close_cfm.mcl_handle, &app_idx, &mcl_idx)) { + btif_hl_stop_cch_timer(app_idx, mcl_idx); btif_hl_send_setup_disconnected_cb(app_idx, mcl_idx); btif_hl_release_mcl_sockets(app_idx, mcl_idx); btif_hl_clean_mcl_cb(app_idx, mcl_idx); @@ -2406,7 +2898,80 @@ static BOOLEAN btif_hl_proc_dch_open_cfm(tBTA_HL *p_data) return status; } +/******************************************************************************* +** +** Function btif_hl_proc_dch_reconnect_cfm +** +** Description Process the DCH reconnect indication +** +** Returns Nothing +** +*******************************************************************************/ +static BOOLEAN btif_hl_proc_dch_reconnect_cfm(tBTA_HL *p_data) +{ + btif_hl_app_cb_t *p_acb; + btif_hl_mcl_cb_t *p_mcb; + btif_hl_mdl_cb_t *p_dcb; + btif_hl_pending_chan_cb_t *p_pcb; + UINT8 app_idx, mcl_idx, mdl_idx, mdep_cfg_idx; + BOOLEAN status = FALSE; + BOOLEAN close_dch = FALSE; + + BTIF_TRACE_DEBUG1("%s", __FUNCTION__); + + if (btif_hl_find_mcl_idx_using_handle(p_data->dch_open_cfm.mcl_handle, &app_idx, &mcl_idx )) + { + p_acb = BTIF_HL_GET_APP_CB_PTR(app_idx); + p_mcb = BTIF_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + p_pcb = BTIF_HL_GET_PCB_PTR(app_idx, mcl_idx); + + if (btif_hl_find_avail_mdl_idx(app_idx, mcl_idx, &mdl_idx)) + { + p_dcb = BTIF_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); + + if (btif_hl_find_mdep_cfg_idx(app_idx, p_data->dch_reconnect_cfm.local_mdep_id, &mdep_cfg_idx)) + { + p_dcb->in_use = TRUE; + p_dcb->mdl_handle = p_data->dch_reconnect_cfm.mdl_handle; + p_dcb->local_mdep_cfg_idx = mdep_cfg_idx; + p_dcb->local_mdep_id = p_data->dch_reconnect_cfm.local_mdep_id; + p_dcb->mdl_id = p_data->dch_reconnect_cfm.mdl_id; + p_dcb->dch_mode = p_data->dch_reconnect_cfm.dch_mode; + p_dcb->is_the_first_reliable= p_data->dch_reconnect_cfm.first_reliable; + p_dcb->mtu = p_data->dch_reconnect_cfm.mtu; + p_dcb->channel_id = p_pcb->channel_id; + BTIF_TRACE_DEBUG3("app_idx=%d mcl_idx=%d mdl_idx=%d", app_idx, mcl_idx, mdl_idx ); + btif_hl_send_setup_connecting_cb(app_idx, mcl_idx); + if (btif_hl_create_socket(app_idx, mcl_idx, mdl_idx)) + { + status = TRUE; + BTIF_TRACE_DEBUG4("app_idx=%d mcl_idx=%d mdl_idx=%d p_dcb->channel_id=0x%08x", app_idx, mcl_idx, mdl_idx, p_dcb->channel_id); + btif_hl_clean_pcb(p_pcb); + } + else + { + BTIF_TRACE_ERROR0("Unable to create socket"); + close_dch = TRUE; + } + } + else + { + BTIF_TRACE_ERROR1("INVALID_LOCAL_MDEP_ID mdep_id=%d",p_data->dch_open_cfm.local_mdep_id); + close_dch = TRUE; + } + + if (close_dch) + { + btif_hl_clean_mdl_cb(p_dcb); + BTA_HlDchClose(p_data->dch_reconnect_cfm.mdl_handle); + } + } + } + + return status; + +} /******************************************************************************* ** ** Function btif_hl_proc_dch_reconnect_ind @@ -2474,13 +3039,10 @@ static void btif_hl_proc_dch_reconnect_ind(tBTA_HL *p_data) close_dch = TRUE; if (close_dch) - BTA_HlDchClose(p_data->dch_reconnect_ind.local_mdep_id); - + BTA_HlDchClose(p_data->dch_reconnect_ind.mdl_handle); } - - /******************************************************************************* ** ** Function btif_hl_proc_dch_close_ind @@ -2503,6 +3065,8 @@ static void btif_hl_proc_dch_close_ind(tBTA_HL *p_data) p_dcb = BTIF_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); btif_hl_release_socket(app_idx,mcl_idx, mdl_idx); btif_hl_clean_mdl_cb(p_dcb); + if (!btif_hl_num_dchs_in_use(app_idx, mcl_idx)) + btif_hl_start_cch_timer(app_idx, mcl_idx); BTIF_TRACE_DEBUG1("remote DCH close success mdl_idx=%d", mdl_idx); } } @@ -2529,6 +3093,8 @@ static void btif_hl_proc_dch_close_cfm(tBTA_HL *p_data) p_dcb = BTIF_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); btif_hl_release_socket(app_idx,mcl_idx,mdl_idx); btif_hl_clean_mdl_cb(p_dcb); + if (!btif_hl_num_dchs_in_use(app_idx, mcl_idx)) + btif_hl_start_cch_timer(app_idx, mcl_idx); BTIF_TRACE_DEBUG1("BTAPP local DCH close success mdl_idx=%d", mdl_idx); } } @@ -2549,13 +3115,10 @@ static void btif_hl_proc_abort_ind(tBTA_HL_MCL_HANDLE mcl_handle){ BTIF_TRACE_DEBUG1("%s", __FUNCTION__ ); if (btif_hl_find_mcl_idx_using_handle(mcl_handle, &app_idx, &mcl_idx)) { - /* tod0 */ + btif_hl_send_setup_disconnected_cb(app_idx, mcl_idx); } } - - - /******************************************************************************* ** ** Function btif_hl_proc_abort_cfm @@ -2571,12 +3134,10 @@ static void btif_hl_proc_abort_cfm(tBTA_HL_MCL_HANDLE mcl_handle){ BTIF_TRACE_DEBUG1("%s", __FUNCTION__ ); if (btif_hl_find_mcl_idx_using_handle(mcl_handle, &app_idx, &mcl_idx)) { - /* tod0 */ + btif_hl_send_setup_disconnected_cb(app_idx,mcl_idx); } } - - /******************************************************************************* ** ** Function btif_hl_proc_send_data_cfm @@ -2602,8 +3163,6 @@ static void btif_hl_proc_send_data_cfm(tBTA_HL_MDL_HANDLE mdl_handle, } } - - /******************************************************************************* ** ** Function btif_hl_proc_dch_cong_ind @@ -2629,56 +3188,345 @@ static void btif_hl_proc_dch_cong_ind(tBTA_HL *p_data) } } + /******************************************************************************* ** -** Function btif_hl_send_chan_state_cb_evt +** Function btif_hl_proc_app_data ** -** Description Process send channel state callback event in the btif task context +** Description Process registration request ** ** Returns void ** *******************************************************************************/ -static void btif_hl_send_chan_state_cb_evt(UINT16 event, char* p_param) -{ +static BOOLEAN btif_hl_proc_app_data(UINT8 app_idx){ + btif_hl_app_cb_t *p_acb = BTIF_HL_GET_APP_CB_PTR(app_idx); + btif_hl_app_data_t *p_data; + btif_hl_nv_app_data_t *p_nv; + BOOLEAN is_match; + UINT8 num_mdeps, i; + tBTA_HL_MDEP_CFG *p_cfg; + tBTA_HL_MDEP_CFG *p_nv_cfg; + BOOLEAN status = TRUE; + bt_status_t bt_status; + + BTIF_TRACE_DEBUG2("%s app_idx=%d ", __FUNCTION__, app_idx ); + + if (!GKI_queue_is_empty(&p_ncb->app_queue)) + { + p_data = (btif_hl_app_data_t *)GKI_getfirst((void *)&p_ncb->app_queue); + while (p_data != NULL) + { + is_match = FALSE; + p_nv = &p_data->app_data; + BTIF_TRACE_DEBUG1("compare with nv idx=%d", p_data->app_nv_idx); + if (p_nv->application_name != NULL && + memcmp((void *)p_acb->application_name, p_nv->application_name,(BTIF_HL_APPLICATION_NAME_LEN +1)) != 0 ) + { + BTIF_TRACE_DEBUG1("application_name mismatch NV(%s)",p_nv->application_name); + } + else if (p_nv->provider_name != NULL && + memcmp((void *)p_acb->provider_name, p_nv->provider_name,(BTA_PROVIDER_NAME_LEN +1)) != 0) + { + BTIF_TRACE_DEBUG1("provider_name mismatch NV(%s)",p_nv->provider_name); + } + else if (p_nv->srv_name != NULL && + memcmp((void *)p_acb->srv_name, p_nv->srv_name,(BTA_SERVICE_NAME_LEN +1)) != 0) + { + BTIF_TRACE_DEBUG1("srv_name mismatch NV(%s)",p_nv->srv_name); + } + else if (p_nv->srv_desp != NULL && + memcmp((void *)p_acb->srv_desp, p_nv->srv_desp,(BTA_SERVICE_DESP_LEN +1)) != 0) + { + BTIF_TRACE_DEBUG1("srv_desp mismatch NV(%s)",p_nv->srv_desp); + } + else if (p_acb->sup_feature.app_role_mask != p_nv->sup_feature.app_role_mask) + { + BTIF_TRACE_DEBUG1("app_role_mask mismatch app_role_mask=0x%x", p_nv->sup_feature.app_role_mask); + } + else if (p_acb->sup_feature.advertize_source_sdp != p_nv->sup_feature.advertize_source_sdp) + { + BTIF_TRACE_DEBUG1("advertize_source_sdp mismatch advertize_source_sdp=0x%x", p_nv->sup_feature.advertize_source_sdp); + } + else if (p_acb->sup_feature.num_of_mdeps != p_nv->sup_feature.num_of_mdeps) + { + BTIF_TRACE_DEBUG1("num_of_mdeps mismatch num_of_mdeps=0x%x", p_nv->sup_feature.num_of_mdeps); + } + else + { + BTIF_TRACE_DEBUG1("Step1 match for app_idx=%d now check mdep cfg", app_idx); + is_match = TRUE; + num_mdeps = p_acb->sup_feature.num_of_mdeps; + BTIF_TRACE_DEBUG1("num of medeps num_mdeps=%d ", num_mdeps); + for (i=0; i< num_mdeps; i++) + { + p_cfg = &p_acb->sup_feature.mdep[i].mdep_cfg; + p_nv_cfg = &p_nv->sup_feature.mdep[i].mdep_cfg; + + BTIF_TRACE_DEBUG2("mdep-role=%d data_type=%d ", p_cfg->mdep_role,p_cfg->data_cfg[0].data_type ); + BTIF_TRACE_DEBUG2("from NV mdep-role=%d data_type=%d ",p_nv_cfg->mdep_role,p_nv_cfg->data_cfg[0].data_type ); + if (p_cfg->mdep_role != p_nv_cfg->mdep_role || + p_cfg->data_cfg[0].data_type != p_nv_cfg->data_cfg[0].data_type ) + { + is_match = FALSE; + BTIF_TRACE_DEBUG0("Not Match" ); + break; + } + } + } + + if (!is_match) + { + p_data = (btif_hl_app_data_t *)GKI_getnext((void *)p_data); + } + else + { + BTIF_TRACE_DEBUG1("Match is found app_nv_idx=%d",p_data->app_nv_idx ); + break; + } + } + } + + if (is_match) + { + if ((bt_status = btif_storage_read_hl_mdl_data(p_data->app_nv_idx, (char *) &p_acb->mdl_cfg, sizeof(btif_hl_nv_mdl_data_t))) + == BT_STATUS_SUCCESS) + { + p_data->app_idx = app_idx; + p_acb->is_new_app = FALSE; + p_acb->app_nv_idx = p_data->app_nv_idx; + BTIF_TRACE_DEBUG2("btif_storage_read_hl_mdl_data OK app_idx=%d app_nv_idx=%d",app_idx, p_data->app_nv_idx ); + + for (i=0; i<BTA_HL_NUM_MDL_CFGS; i++) + { + if (p_acb->mdl_cfg[i].base.active) + { + BTIF_TRACE_DEBUG6("i=%d mdl_id=0x%x dch_mode=%d local_mdep_role=%d local_mdep_id=%d peer_mdep_id=%d", + i, + p_acb->mdl_cfg[i].base.mdl_id, + p_acb->mdl_cfg[i].base.dch_mode, + p_acb->mdl_cfg[i].base.local_mdep_role, + p_acb->mdl_cfg[i].base.local_mdep_id, + p_acb->mdl_cfg[i].extra.peer_mdep_id ); + BTIF_TRACE_DEBUG3("data type=0x%08x mdep_cfg_idx=%d channel_id=0x%08x ", + p_acb->mdl_cfg[i].extra.data_type, + p_acb->mdl_cfg[i].extra.mdep_cfg_idx, + p_acb->mdl_cfg_channel_id[i]); + BTIF_TRACE_DEBUG6("BD ADDR 0x%02x-%02x-%02x-%02x-%02x-%02x", + p_acb->mdl_cfg[i].base.peer_bd_addr[0], + p_acb->mdl_cfg[i].base.peer_bd_addr[1], + p_acb->mdl_cfg[i].base.peer_bd_addr[2], + p_acb->mdl_cfg[i].base.peer_bd_addr[3], + p_acb->mdl_cfg[i].base.peer_bd_addr[4], + p_acb->mdl_cfg[i].base.peer_bd_addr[5]); + } + + } + } + else + { + status= FALSE; + } + } + else + { + memset(&p_acb->mdl_cfg, 0, sizeof(btif_hl_nv_mdl_data_t)); + p_acb->is_new_app = TRUE; + BTIF_TRACE_DEBUG0("No Match this is a new app set is_new_app=TRUE"); + } + + BTIF_TRACE_DEBUG1("status=%d ",status ); + return status; + + +} + +/******************************************************************************* +** +** Function btif_hl_proc_cb_evt +** +** Description Process registration request +** +** Returns void +** +*******************************************************************************/ +static void btif_hl_proc_reg_request(UINT8 app_idx, UINT8 app_id, + tBTA_HL_REG_PARAM *p_reg_param, + tBTA_HL_CBACK *p_cback){ + bt_status_t status= BT_STATUS_SUCCESS; + UINT8 i; + btif_hl_app_data_t *p_data; + btif_hl_nv_app_cb_t *p_app_cb; + BTIF_TRACE_DEBUG4("%s app_idx=%d app_id=%d is_app_read=%d", __FUNCTION__, app_idx, app_id,p_ncb->is_app_read ); + + if (!p_ncb->is_app_read) + { + if ((status = btif_storage_read_hl_apps_cb((char *)&p_ncb->app_cb, sizeof(btif_hl_nv_app_cb_t))) == BT_STATUS_SUCCESS) + { + p_app_cb = &p_ncb->app_cb; + for (i=0; i< BTIF_HL_NV_MAX_APPS; i++) + { + if (p_app_cb->app[i].in_use ) + { + BTIF_TRACE_DEBUG1("app_nv_idx=%d in_use=TRUE",i); + if ( (p_data = (btif_hl_app_data_t *)GKI_getbuf((UINT16)sizeof(btif_hl_app_data_t)))!=NULL) + { + BTIF_TRACE_DEBUG1("load app_nv_idx=%d ", i ); + p_data->active = FALSE; + p_data->app_idx = 0; + p_data->app_nv_idx = i; + if ((status = btif_storage_read_hl_app_data(i, (char *)&p_data->app_data, sizeof(btif_hl_nv_app_data_t))) + == BT_STATUS_SUCCESS) + { + BTIF_TRACE_DEBUG0("enuque app_data"); + GKI_enqueue(&p_ncb->app_queue, (void *) p_data); + } + else + { + BTIF_TRACE_DEBUG0("btif_storage_read_hl_app_data failed"); + status = BT_STATUS_FAIL; + btif_hl_free_buf((void **)&p_data); + break; + } + } + else + { + BTIF_TRACE_DEBUG0("GKI_getbuf failed"); + status = BT_STATUS_FAIL; + btif_hl_free_buf((void **)&p_data); + break; + } + } + } + + BTIF_TRACE_DEBUG1("app data load status=%d (0-BT_STATUS_SUCCESS) ", status ); + if ( status == BT_STATUS_SUCCESS) + { + p_ncb->is_app_read = TRUE; + } + else + { + BTIF_TRACE_DEBUG0("status=failed remove all elements in app_queue"); + if (!GKI_queue_is_empty(&p_ncb->app_queue)) + { + p_data = (btif_hl_app_data_t *)GKI_getfirst((void *)&p_ncb->app_queue); + while (p_data != NULL) + { + GKI_remove_from_queue((void *)&p_ncb->app_queue, p_data); + p_data = (btif_hl_app_data_t *)GKI_getfirst((void *)&p_ncb->app_queue); + } + } + } + } + else + { + BTIF_TRACE_DEBUG0("btif_storage_read_hl_apps_cb failed"); + } + } + + if (status == BT_STATUS_SUCCESS) + { + if (!btif_hl_proc_app_data(app_idx)) + { + btif_hl_free_app_idx(app_idx); + BTIF_TRACE_DEBUG2("call reg state callback app_id=%d state=%d", app_id, BTHL_APP_REG_STATE_REG_FAILED); + BTIF_HL_CALL_CBACK(bt_hl_callbacks, app_reg_state_cb, (int) app_id, + BTHL_APP_REG_STATE_REG_FAILED ); + } + else + { + BTA_HlRegister(app_id, p_reg_param, btif_hl_cback); + } + } +} - btif_hl_send_chan_state_cb_t *p_data = (btif_hl_send_chan_state_cb_t *)p_param; + +/******************************************************************************* +** +** Function btif_hl_proc_cb_evt +** +** Description Process HL callback events +** +** Returns void +** +*******************************************************************************/ +static void btif_hl_proc_cb_evt(UINT16 event, char* p_param){ + + btif_hl_evt_cb_t *p_data = (btif_hl_evt_cb_t *)p_param; bt_bdaddr_t bd_addr; bthl_channel_state_t state=BTHL_CONN_STATE_DISCONNECTED; - BOOLEAN send_cb=TRUE; - + BOOLEAN send_chan_cb=TRUE; + tBTA_HL_REG_PARAM reg_param; + btif_hl_app_cb_t *p_acb; + bthl_app_reg_state_t reg_state = BTHL_APP_REG_STATE_REG_FAILED; + int app_id; + UINT8 preg_idx; + bt_status_t bt_status; BTIF_TRACE_DEBUG2("%s event %d", __FUNCTION__, event); - btif_hl_copy_bda(&bd_addr, p_data->bd_addr); + btif_hl_display_calling_process_name(); switch (event) { case BTIF_HL_SEND_CONNECTED_CB: + case BTIF_HL_SEND_DISCONNECTED_CB: + if (p_data->chan_cb.cb_state == BTIF_HL_CHAN_CB_STATE_CONNECTED_PENDING) + state = BTHL_CONN_STATE_CONNECTED; + else if (p_data->chan_cb.cb_state == BTIF_HL_CHAN_CB_STATE_DISCONNECTED_PENDING) + state = BTHL_CONN_STATE_DISCONNECTED; + else + send_chan_cb = FALSE; - if (p_data->cb_state == BTIF_HL_CHAN_CB_STATE_CONNECTED_PENDING) + if (send_chan_cb) { - state = BTHL_CONN_STATE_CONNECTED; + btif_hl_copy_bda(&bd_addr, p_data->chan_cb.bd_addr); + BTIF_TRACE_DEBUG5("call channel state callback channel_id=0x%08x mdep_cfg_idx=%d,cb_state=%d state=%d fd=%d",p_data->chan_cb.channel_id, + p_data->chan_cb.mdep_cfg_index, p_data->chan_cb.cb_state, state, p_data->chan_cb.fd); + btif_hl_display_bt_bda(&bd_addr); + BTIF_HL_CALL_CBACK(bt_hl_callbacks, channel_state_cb, p_data->chan_cb.app_id, + &bd_addr, p_data->chan_cb.mdep_cfg_index, + p_data->chan_cb.channel_id, state, p_data->chan_cb.fd ); } + break; - case BTIF_HL_SEND_DISCONNECTED_CB: - if (p_data->cb_state == BTIF_HL_CHAN_CB_STATE_DISCONNECTED_PENDING) + case BTIF_HL_REG_APP: + p_acb = BTIF_HL_GET_APP_CB_PTR(p_data->reg.app_idx); + app_id = (int) p_acb->app_id; + BTIF_TRACE_DEBUG2("Rcv BTIF_HL_REG_APP app_idx=%d reg_pending=%d", p_data->reg.app_idx, p_acb->reg_pending); + if (btif_hl_get_state() == BTIF_HL_STATE_ENABLED && p_acb->reg_pending ) { - state = BTHL_CONN_STATE_DISCONNECTED; + p_acb->reg_pending = FALSE; + + reg_param.dev_type = p_acb->dev_type; + reg_param.sec_mask = BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT; + reg_param.p_srv_name = p_acb->srv_name; + reg_param.p_srv_desp = p_acb->srv_desp; + reg_param.p_provider_name = p_acb->provider_name; + btif_hl_proc_reg_request (p_data->reg.app_idx, p_acb->app_id, ®_param, btif_hl_cback); } + else + { + BTIF_TRACE_DEBUG2("reg request is processed state=%d reg_pending=%d", btif_hl_get_state(), p_acb->reg_pending); + } + break; - default: - send_cb = FALSE; + case BTIF_HL_UNREG_APP: + BTIF_TRACE_DEBUG1("Rcv BTIF_HL_UNREG_APP app_idx=%d", p_data->unreg.app_idx ); + p_acb = BTIF_HL_GET_APP_CB_PTR(p_data->unreg.app_idx); + BTA_HlDeregister(p_acb->app_handle); + break; + case BTIF_HL_UPDATE_MDL: + BTIF_TRACE_DEBUG1("Rcv BTIF_HL_UPDATE_MDL app_idx=%d", p_data->update_mdl.app_idx ); + p_acb = BTIF_HL_GET_APP_CB_PTR(p_data->update_mdl.app_idx); + BTIF_TRACE_DEBUG1("app_nv_idx=%d", p_acb->app_nv_idx ); + bt_status = btif_storage_write_hl_mdl_data(p_acb->app_nv_idx,(char *) &p_acb->mdl_cfg[0], + sizeof(btif_hl_nv_mdl_data_t)); + BTIF_TRACE_DEBUG1("bt_status=%d", bt_status); break; - } - if (send_cb) - { - BTIF_TRACE_DEBUG5("channel_id=0x%08x mdep_cfg_idx=%d,cb_state=%d state=%d fd=%d",p_data->channel_id, - p_data->mdep_cfg_index, p_data->cb_state, state, p_data->fd); - btif_hl_display_bt_bda(&bd_addr); - BTIF_HL_CALL_CBACK(bt_hl_callbacks, channel_state_cb, p_data->app_id, - &bd_addr, p_data->mdep_cfg_index, - p_data->channel_id, state, p_data->fd ); + default: + BTIF_TRACE_ERROR1("Unknown event %d", event); + break; } } @@ -2701,9 +3549,9 @@ static void btif_hl_upstreams_evt(UINT16 event, char* p_param){ BOOLEAN status; BTIF_TRACE_DEBUG2("%s event %d", __FUNCTION__, event); + btif_hl_display_calling_process_name(); switch (event) { - case BTA_HL_REGISTER_CFM_EVT: BTIF_TRACE_DEBUG0("Rcv BTA_HL_REGISTER_CFM_EVT"); BTIF_TRACE_DEBUG3("app_id=%d app_handle=%d status=%d ", @@ -2862,7 +3710,6 @@ static void btif_hl_upstreams_evt(UINT16 event, char* p_param){ default: break; } - //todo start a timer to close cch if no dch } } break; @@ -2949,8 +3796,36 @@ static void btif_hl_upstreams_evt(UINT16 event, char* p_param){ p_data->dch_reconnect_cfm.dch_mode, p_data->dch_reconnect_cfm.mdl_id, p_data->dch_reconnect_cfm.mtu); - /* sot supported */ - /* will be supported in next phase */ + + + if (p_data->dch_reconnect_cfm.status == BTA_HL_STATUS_OK) + { + status = btif_hl_proc_dch_reconnect_cfm(p_data); + } + else + { + status = FALSE; + } + + if (!status) + { + if (btif_hl_find_mcl_idx_using_handle(p_data->dch_open_cfm.mcl_handle,&app_idx, &mcl_idx)) + { + p_mcb = BTIF_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + pending_op = p_mcb->pcb.op; + switch (pending_op) + { + case BTIF_HL_PEND_DCH_OP_OPEN: + btif_hl_send_setup_disconnected_cb(app_idx, mcl_idx); + break; + case BTIF_HL_PEND_DCH_OP_RECONNECT: + case BTIF_HL_PEND_DCH_OP_DELETE_MDL: + default: + break; + } + } + } + break; case BTA_HL_CCH_CLOSE_CFM_EVT: @@ -3063,8 +3938,6 @@ static void btif_hl_upstreams_evt(UINT16 event, char* p_param){ BTIF_TRACE_DEBUG1("Unknown Event (0x%02x)...", event); break; } - - } /******************************************************************************* @@ -3079,7 +3952,8 @@ static void btif_hl_upstreams_evt(UINT16 event, char* p_param){ static void btif_hl_cback(tBTA_HL_EVT event, tBTA_HL *p_data){ bt_status_t status; int param_len = 0; - + BTIF_TRACE_DEBUG2("%s event %d", __FUNCTION__, event); + btif_hl_display_calling_process_name(); switch (event) { case BTA_HL_REGISTER_CFM_EVT: @@ -3155,31 +4029,30 @@ static void btif_hl_cback(tBTA_HL_EVT event, tBTA_HL *p_data){ param_len = sizeof(tBTA_HL_MDL_IND); break; } - /* TODO: BTA sends the union members and not tBTA_HL. If using param_len=sizeof(tBTA_HL), we get a crash on memcpy */ - /* switch context to btif task context (copy full union size for convenience) */ status = btif_transfer_context(btif_hl_upstreams_evt, (uint16_t)event, (void*)p_data, param_len, NULL); /* catch any failed context transfers */ ASSERTC(status == BT_STATUS_SUCCESS, "context transfer failed", status); - - } /******************************************************************************* ** -** Function btif_hl_ctrl_cback +** Function btif_hl_upstreams_ctrl_evt ** -** Description Callback function for HL control events +** Description Callback function for HL control events in the BTIF task context ** ** Returns void ** *******************************************************************************/ -static void btif_hl_ctrl_cback(tBTA_HL_CTRL_EVT event, tBTA_HL_CTRL *p_data){ +static void btif_hl_upstreams_ctrl_evt(UINT16 event, char* p_param){ + tBTA_HL_CTRL *p_data = (tBTA_HL_CTRL *) p_param; UINT8 i; tBTA_HL_REG_PARAM reg_param; btif_hl_app_cb_t *p_acb; BTIF_TRACE_DEBUG2("%s event %d", __FUNCTION__, event); + btif_hl_display_calling_process_name(); + switch ( event ) { case BTA_HL_CTRL_ENABLE_CFM_EVT: @@ -3190,12 +4063,13 @@ static void btif_hl_ctrl_cback(tBTA_HL_CTRL_EVT event, tBTA_HL_CTRL *p_data){ { btif_hl_set_state(BTIF_HL_STATE_ENABLED); + for (i=0; i < BTA_HL_NUM_APPS ; i ++) { - if (btif_hl_cb.pcb[i].in_use) + p_acb = BTIF_HL_GET_APP_CB_PTR(i); + if (p_acb->in_use && p_acb->reg_pending) { - p_acb = BTIF_HL_GET_APP_CB_PTR(btif_hl_cb.pcb[i].app_idx); - btif_hl_free_pending_reg_idx(i); + p_acb->reg_pending = FALSE; reg_param.dev_type = p_acb->dev_type; reg_param.sec_mask = BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT; reg_param.p_srv_name = p_acb->srv_name; @@ -3203,8 +4077,7 @@ static void btif_hl_ctrl_cback(tBTA_HL_CTRL_EVT event, tBTA_HL_CTRL *p_data){ reg_param.p_provider_name = p_acb->provider_name; BTIF_TRACE_DEBUG1("Register pending app_id=%d", p_acb->app_id); - - BTA_HlRegister(p_acb->app_id, ®_param, btif_hl_cback); + btif_hl_proc_reg_request (i, p_acb->app_id, ®_param, btif_hl_cback); } } } @@ -3225,12 +4098,37 @@ static void btif_hl_ctrl_cback(tBTA_HL_CTRL_EVT event, tBTA_HL_CTRL *p_data){ default: break; } - - } +/******************************************************************************* +** +** Function btif_hl_ctrl_cback +** +** Description Callback function for HL control events +** +** Returns void +** +*******************************************************************************/ +static void btif_hl_ctrl_cback(tBTA_HL_CTRL_EVT event, tBTA_HL_CTRL *p_data){ + bt_status_t status; + int param_len = 0; + + BTIF_TRACE_DEBUG2("%s event %d", __FUNCTION__, event); + btif_hl_display_calling_process_name(); + switch ( event ) + { + case BTA_HL_CTRL_ENABLE_CFM_EVT: + case BTA_HL_CTRL_DISABLE_CFM_EVT: + param_len = sizeof(tBTA_HL_CTRL_ENABLE_DISABLE); + break; + default: + break; + } + status = btif_transfer_context(btif_hl_upstreams_ctrl_evt, (uint16_t)event, (void*)p_data, param_len, NULL); + ASSERTC(status == BT_STATUS_SUCCESS, "context transfer failed", status); +} /******************************************************************************* ** ** Function connect_channel @@ -3251,6 +4149,7 @@ static bt_status_t connect_channel(int app_id, bt_bdaddr_t *bd_addr, int mdep_cf CHECK_BTHL_INIT(); BTIF_TRACE_EVENT1("%s", __FUNCTION__); + btif_hl_display_calling_process_name(); for (i=0; i<6; i++) @@ -3263,7 +4162,6 @@ static bt_status_t connect_channel(int app_id, bt_bdaddr_t *bd_addr, int mdep_cf if (btif_hl_find_mcl_idx(app_idx, bda , &mcl_idx)) { p_mcb = BTIF_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); - if (p_mcb->is_connected) { dch_open.ctrl_psm = p_mcb->ctrl_psm; @@ -3337,67 +4235,75 @@ static bt_status_t destroy_channel(int channel_id){ CHECK_BTHL_INIT(); BTIF_TRACE_EVENT2("%s channel_id=0x%08x", __FUNCTION__, channel_id); + btif_hl_display_calling_process_name(); - if (btif_hl_find_mdl_cfg_idx_using_channel_id(channel_id, &app_idx, &mdl_cfg_idx)) + + if (btif_hl_if_channel_setup_pending(channel_id, &app_idx, &mcl_idx)) { - p_acb = BTIF_HL_GET_APP_CB_PTR(app_idx); - if (!p_acb->delete_mdl.active) + btif_hl_dch_abort(app_idx, mcl_idx); + } + else + { + if (btif_hl_find_mdl_cfg_idx_using_channel_id(channel_id, &app_idx, &mdl_cfg_idx)) { - p_mdl =BTIF_HL_GET_MDL_CFG_PTR(app_idx, mdl_cfg_idx); - p_acb->delete_mdl.active = TRUE; - p_acb->delete_mdl.mdl_id = p_mdl->base.mdl_id; - p_acb->delete_mdl.channel_id = channel_id; - p_acb->delete_mdl.mdep_cfg_idx = p_mdl->extra.mdep_cfg_idx; - memcpy(p_acb->delete_mdl.bd_addr, p_mdl->base.peer_bd_addr,sizeof(BD_ADDR)); - - if (btif_hl_find_mcl_idx(app_idx, p_mdl->base.peer_bd_addr, &mcl_idx)) + p_acb = BTIF_HL_GET_APP_CB_PTR(app_idx); + if (!p_acb->delete_mdl.active) { - p_mcb = BTIF_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); - if (p_mcb->is_connected) + p_mdl =BTIF_HL_GET_MDL_CFG_PTR(app_idx, mdl_cfg_idx); + p_acb->delete_mdl.active = TRUE; + p_acb->delete_mdl.mdl_id = p_mdl->base.mdl_id; + p_acb->delete_mdl.channel_id = channel_id; + p_acb->delete_mdl.mdep_cfg_idx = p_mdl->extra.mdep_cfg_idx; + memcpy(p_acb->delete_mdl.bd_addr, p_mdl->base.peer_bd_addr,sizeof(BD_ADDR)); + + if (btif_hl_find_mcl_idx(app_idx, p_mdl->base.peer_bd_addr, &mcl_idx)) { - BTIF_TRACE_DEBUG1("calling BTA_HlDeleteMdl mdl_id=%d",p_acb->delete_mdl.mdl_id ); - BTA_HlDeleteMdl(p_mcb->mcl_handle, p_acb->delete_mdl.mdl_id); + p_mcb = BTIF_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + if (p_mcb->is_connected) + { + BTIF_TRACE_DEBUG1("calling BTA_HlDeleteMdl mdl_id=%d",p_acb->delete_mdl.mdl_id ); + BTA_HlDeleteMdl(p_mcb->mcl_handle, p_acb->delete_mdl.mdl_id); + } + else + { + status = BT_STATUS_FAIL; + } } else { - status = BT_STATUS_FAIL; + BTIF_TRACE_DEBUG0("btif_hl_delete_mdl calling btif_hl_cch_open" ); + mdep_cfg_idx = p_mdl->extra.mdep_cfg_idx; + p_acb->filter.num_elems =1; + p_acb->filter.elem[0].data_type = p_acb->sup_feature.mdep[mdep_cfg_idx].mdep_cfg.data_cfg[mdep_cfg_idx].data_type; + if (p_acb->sup_feature.mdep[mdep_cfg_idx].mdep_cfg.mdep_role == BTA_HL_MDEP_ROLE_SINK) + p_acb->filter.elem[0].peer_mdep_role = BTA_HL_MDEP_ROLE_SOURCE; + else + p_acb->filter.elem[0].peer_mdep_role = BTA_HL_MDEP_ROLE_SINK; + if (btif_hl_cch_open(p_acb->app_id, p_acb->delete_mdl.bd_addr, 0, + mdep_cfg_idx, + BTIF_HL_PEND_DCH_OP_DELETE_MDL, NULL)) + { + status = BT_STATUS_FAIL; + } } - } - else - { - BTIF_TRACE_DEBUG0("btif_hl_delete_mdl calling btif_hl_cch_open" ); - mdep_cfg_idx = p_mdl->extra.mdep_cfg_idx; - p_acb->filter.num_elems =1; - p_acb->filter.elem[0].data_type = p_acb->sup_feature.mdep[mdep_cfg_idx].mdep_cfg.data_cfg[mdep_cfg_idx].data_type; - if (p_acb->sup_feature.mdep[mdep_cfg_idx].mdep_cfg.mdep_role == BTA_HL_MDEP_ROLE_SINK) - p_acb->filter.elem[0].peer_mdep_role = BTA_HL_MDEP_ROLE_SOURCE; - else - p_acb->filter.elem[0].peer_mdep_role = BTA_HL_MDEP_ROLE_SINK; - if (btif_hl_cch_open(p_acb->app_id, p_acb->delete_mdl.bd_addr, 0, - mdep_cfg_idx, - BTIF_HL_PEND_DCH_OP_DELETE_MDL, NULL)) + + if ( status == BT_STATUS_FAIL) { - status = BT_STATUS_FAIL; + /* fail for now */ + btif_hl_clean_delete_mdl(&p_acb->delete_mdl); } } - - if ( status == BT_STATUS_FAIL) + else { - /* fail for now */ - btif_hl_clean_delete_mdl(&p_acb->delete_mdl); + status = BT_STATUS_BUSY; } } else { - status = BT_STATUS_BUSY; + status = BT_STATUS_FAIL; } - } - else - { - /* todo fail for now later need to consider channel setup abort */ - status = BT_STATUS_FAIL; - } + } return status; } /******************************************************************************* @@ -3410,17 +4316,26 @@ static bt_status_t destroy_channel(int channel_id){ ** *******************************************************************************/ static bt_status_t unregister_application(int app_id){ - btif_hl_app_cb_t *p_acb; - UINT8 app_idx; - bt_status_t status = BT_STATUS_SUCCESS; + btif_hl_app_cb_t *p_acb; + UINT8 app_idx; + int len; + bt_status_t status = BT_STATUS_SUCCESS; + btif_hl_evt_cb_t evt_param; CHECK_BTHL_INIT(); BTIF_TRACE_EVENT2("%s app_id=%d", __FUNCTION__, app_id); + btif_hl_display_calling_process_name(); if (btif_hl_find_app_idx(((UINT8)app_id), &app_idx)) { - p_acb = BTIF_HL_GET_APP_CB_PTR(app_idx); - BTA_HlDeregister(p_acb->app_handle); + evt_param.unreg.app_idx = app_idx; + len = sizeof(btif_hl_unreg_t); + status = btif_transfer_context (btif_hl_proc_cb_evt, BTIF_HL_UNREG_APP, + (char*) &evt_param, len, NULL); + ASSERTC(status == BT_STATUS_SUCCESS, "context transfer failed", status); + + + } else { @@ -3429,8 +4344,6 @@ static bt_status_t unregister_application(int app_id){ BTIF_TRACE_DEBUG1("de-reg return status=%d", status); return status; - - } /******************************************************************************* ** @@ -3446,13 +4359,15 @@ static bt_status_t register_application(bthl_reg_param_t *p_reg_param, int *app_ tBTA_HL_SUP_FEATURE *p_sup; tBTA_HL_MDEP_CFG *p_cfg; tBTA_HL_MDEP_DATA_TYPE_CFG *p_data; - tBTA_HL_REG_PARAM reg_param; UINT8 app_idx=0, i=0, pending_reg_idx=0; bthl_mdep_cfg_t *p_mdep_cfg; bt_status_t status = BT_STATUS_SUCCESS; + btif_hl_evt_cb_t evt_param; + int len; CHECK_BTHL_INIT(); BTIF_TRACE_EVENT1("%s", __FUNCTION__); + btif_hl_display_calling_process_name(); if (btif_hl_get_state() == BTIF_HL_STATE_DISABLED) { @@ -3470,10 +4385,7 @@ static bt_status_t register_application(bthl_reg_param_t *p_reg_param, int *app_ p_acb = BTIF_HL_GET_APP_CB_PTR(app_idx); p_acb->in_use = TRUE; - /* todo - check whether this appication exists in the NV or not if it exists - then use its own app_id - */ + p_acb->app_id = btif_hl_get_next_app_id(); if (p_reg_param->application_name != NULL ) @@ -3490,8 +4402,8 @@ static bt_status_t register_application(bthl_reg_param_t *p_reg_param, int *app_ p_sup = &p_acb->sup_feature; p_sup->advertize_source_sdp = TRUE; - p_sup->echo_cfg.max_rx_apdu_size = 0; - p_sup->echo_cfg.max_tx_apdu_size = 0; + p_sup->echo_cfg.max_rx_apdu_size = BTIF_HL_ECHO_MAX_TX_RX_APDU_SIZE; + p_sup->echo_cfg.max_tx_apdu_size = BTIF_HL_ECHO_MAX_TX_RX_APDU_SIZE; p_sup->num_of_mdeps = p_reg_param->number_of_mdeps; for (i=0, p_mdep_cfg = p_reg_param->mdep_cfg ; i< p_sup->num_of_mdeps; i++, p_mdep_cfg++ ) @@ -3504,7 +4416,6 @@ static bt_status_t register_application(bthl_reg_param_t *p_reg_param, int *app_ { BTIF_TRACE_ERROR1("Invalid mdep_role=%d", p_mdep_cfg->mdep_role); status = BT_STATUS_FAIL; - break; } else @@ -3544,30 +4455,14 @@ static bt_status_t register_application(bthl_reg_param_t *p_reg_param, int *app_ if (status == BT_STATUS_SUCCESS) { *app_id = (int) p_acb->app_id; - if (btif_hl_get_state() == BTIF_HL_STATE_ENABLED ) - { - reg_param.dev_type = p_acb->dev_type; - reg_param.sec_mask = BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT; - reg_param.p_srv_name = p_acb->srv_name; - reg_param.p_srv_desp = p_acb->srv_desp; - reg_param.p_provider_name = p_acb->provider_name; - BTA_HlRegister(p_acb->app_id, ®_param, btif_hl_cback); - } - else - { - if ((btif_hl_get_state() == BTIF_HL_STATE_ENABLING) && btif_hl_find_avail_pending_reg_idx(&pending_reg_idx)) - { - BTIF_TRACE_DEBUG1("registration is delayed until HL is enabled app_id=%d", *app_id); - btif_hl_cb.pcb[i].in_use = TRUE; - btif_hl_cb.pcb[i].app_idx = app_idx; - } - else - { - BTIF_TRACE_ERROR0("Unable to enqueue this reg request"); - btif_hl_free_app_idx(app_idx); - status = BT_STATUS_FAIL; - } - } + evt_param.reg.app_idx = app_idx; + len = sizeof(btif_hl_reg_t); + p_acb->reg_pending = TRUE; + BTIF_TRACE_DEBUG2("calling btif_transfer_context status=%d app_id=%d", status, *app_id); + status = btif_transfer_context (btif_hl_proc_cb_evt, BTIF_HL_REG_APP, + (char*) &evt_param, len, NULL); + ASSERTC(status == BT_STATUS_SUCCESS, "context transfer failed", status); + } else { @@ -3588,8 +4483,9 @@ static bt_status_t register_application(bthl_reg_param_t *p_reg_param, int *app_ *******************************************************************************/ static bt_status_t init( bthl_callbacks_t* callbacks ){ bt_status_t status = BT_STATUS_SUCCESS; - BTIF_TRACE_EVENT1("%s", __FUNCTION__); + BTIF_TRACE_EVENT1("%s", __FUNCTION__); + btif_hl_display_calling_process_name(); bt_hl_callbacks_cb = *callbacks; bt_hl_callbacks = &bt_hl_callbacks_cb; btif_hl_soc_thread_init(); @@ -3607,6 +4503,7 @@ static bt_status_t init( bthl_callbacks_t* callbacks ){ *******************************************************************************/ static void cleanup( void ){ BTIF_TRACE_EVENT1("%s", __FUNCTION__); + btif_hl_display_calling_process_name(); if (bt_hl_callbacks) { btif_disable_service(BTA_HDP_SERVICE_ID); @@ -3641,6 +4538,15 @@ const bthl_interface_t *btif_hl_get_interface(){ return &bthlInterface; } +/******************************************************************************* +** +** Function btif_hl_update_maxfd +** +** Description Update the max fd if the input fd is greater than the current max fd +** +** Returns int +** +*******************************************************************************/ int btif_hl_update_maxfd( int max_org_s){ btif_hl_soc_cb_t *p_scb = NULL; int maxfd=0; @@ -3665,24 +4571,46 @@ int btif_hl_update_maxfd( int max_org_s){ } p_scb = (btif_hl_soc_cb_t *)GKI_getnext((void *)p_scb ); } - - } BTIF_TRACE_DEBUG1("btif_hl_update_maxfd final *p_max_s=%d", maxfd); return maxfd; } - +/******************************************************************************* +** +** Function btif_hl_get_socket_state +** +** Description get socket state +** +** Returns btif_hl_soc_state_t +** +*******************************************************************************/ btif_hl_soc_state_t btif_hl_get_socket_state(btif_hl_soc_cb_t *p_scb){ BTIF_TRACE_DEBUG1("btif_hl_get_socket_state state=%d", p_scb->state); return p_scb->state; } - +/******************************************************************************* +** +** Function btif_hl_set_socket_state +** +** Description set socket state +** +** Returns void +** +*******************************************************************************/ void btif_hl_set_socket_state(btif_hl_soc_cb_t *p_scb, btif_hl_soc_state_t new_state){ BTIF_TRACE_DEBUG2("btif_hl_set_socket_state %d---->%d", p_scb->state, new_state); p_scb->state = new_state; } - +/******************************************************************************* +** +** Function btif_hl_release_mcl_sockets +** +** Description Release all sockets on the MCL +** +** Returns void +** +*******************************************************************************/ void btif_hl_release_mcl_sockets(UINT8 app_idx, UINT8 mcl_idx){ btif_hl_soc_cb_t *p_scb = NULL; UINT8 i; @@ -3703,7 +4631,15 @@ void btif_hl_release_mcl_sockets(UINT8 app_idx, UINT8 mcl_idx){ if (found) btif_hl_select_close_connected(); } - +/******************************************************************************* +** +** Function btif_hl_release_socket +** +** Description release a specified socket +** +** Returns void +** +*******************************************************************************/ void btif_hl_release_socket(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx){ btif_hl_soc_cb_t *p_scb = NULL; btif_hl_mdl_cb_t *p_dcb = BTIF_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); @@ -3719,7 +4655,15 @@ void btif_hl_release_socket(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx){ btif_hl_select_close_connected(); } } - +/******************************************************************************* +** +** Function btif_hl_create_socket +** +** Description create a socket +** +** Returns BOOLEAN +** +*******************************************************************************/ BOOLEAN btif_hl_create_socket(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx){ btif_hl_mcl_cb_t *p_mcb = BTIF_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); btif_hl_mdl_cb_t *p_dcb = BTIF_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); @@ -3757,13 +4701,20 @@ BOOLEAN btif_hl_create_socket(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx){ BTIF_TRACE_DEBUG2("%s status=%d", __FUNCTION__, status); return status; } - -void btif_hl_add_socket_to_set( fd_set *p_org_set) -{ +/******************************************************************************* +** +** Function btif_hl_add_socket_to_set +** +** Description Add a socket +** +** Returns void +** +*******************************************************************************/ +void btif_hl_add_socket_to_set( fd_set *p_org_set){ btif_hl_soc_cb_t *p_scb = NULL; btif_hl_mdl_cb_t *p_dcb = NULL; btif_hl_mcl_cb_t *p_mcb = NULL; - btif_hl_send_chan_state_cb_t send_cb_param; + btif_hl_evt_cb_t evt_param; bt_status_t status; int len; @@ -3784,21 +4735,18 @@ void btif_hl_add_socket_to_set( fd_set *p_org_set) p_dcb = BTIF_HL_GET_MDL_CB_PTR(p_scb->app_idx, p_scb->mcl_idx, p_scb->mdl_idx); if (p_mcb && p_dcb) { - send_cb_param.app_id = (int) btif_hl_get_app_id(p_dcb->channel_id); - memcpy(send_cb_param.bd_addr, p_mcb->bd_addr, sizeof(BD_ADDR)); - send_cb_param.channel_id = p_dcb->channel_id; - send_cb_param.fd = p_scb->socket_id[0]; - send_cb_param.mdep_cfg_index = (int ) p_dcb->local_mdep_cfg_idx; - send_cb_param.cb_state = BTIF_HL_CHAN_CB_STATE_CONNECTED_PENDING; + btif_hl_stop_cch_timer(p_scb->app_idx, p_scb->mcl_idx); + evt_param.chan_cb.app_id = (int) btif_hl_get_app_id(p_dcb->channel_id); + memcpy(evt_param.chan_cb.bd_addr, p_mcb->bd_addr, sizeof(BD_ADDR)); + evt_param.chan_cb.channel_id = p_dcb->channel_id; + evt_param.chan_cb.fd = p_scb->socket_id[0]; + evt_param.chan_cb.mdep_cfg_index = (int ) p_dcb->local_mdep_cfg_idx; + evt_param.chan_cb.cb_state = BTIF_HL_CHAN_CB_STATE_CONNECTED_PENDING; len = sizeof(btif_hl_send_chan_state_cb_t); - status = btif_transfer_context (btif_hl_send_chan_state_cb_evt, BTIF_HL_SEND_CONNECTED_CB, - (char*) &send_cb_param, len, NULL); + status = btif_transfer_context (btif_hl_proc_cb_evt, BTIF_HL_SEND_CONNECTED_CB, + (char*) &evt_param, len, NULL); ASSERTC(status == BT_STATUS_SUCCESS, "context transfer failed", status); - - //btif_hl_send_connected_cb (p_scb->app_idx, p_scb->mcl_idx, p_scb->mdl_idx); } - - } p_scb = (btif_hl_soc_cb_t *)GKI_getnext((void *)p_scb ); BTIF_TRACE_DEBUG1("next p_scb=0x%x", p_scb); @@ -3807,12 +4755,20 @@ void btif_hl_add_socket_to_set( fd_set *p_org_set) BTIF_TRACE_DEBUG1("leaving %s",__FUNCTION__); } - +/******************************************************************************* +** +** Function btif_hl_close_socket +** +** Description close a socket +** +** Returns void +** +*******************************************************************************/ void btif_hl_close_socket( fd_set *p_org_set){ btif_hl_soc_cb_t *p_scb = NULL; BOOLEAN element_removed = FALSE; btif_hl_mdl_cb_t *p_dcb = NULL ; - btif_hl_send_chan_state_cb_t send_cb_param; + btif_hl_evt_cb_t evt_param; int len; bt_status_t status; @@ -3833,18 +4789,19 @@ void btif_hl_close_socket( fd_set *p_org_set){ shutdown(p_scb->socket_id[1], SHUT_RDWR); close(p_scb->socket_id[1]); - send_cb_param.app_id = (int) btif_hl_get_app_id(p_scb->channel_id); - memcpy(send_cb_param.bd_addr, p_scb->bd_addr, sizeof(BD_ADDR)); - send_cb_param.channel_id = p_scb->channel_id; - send_cb_param.fd = p_scb->socket_id[0]; - send_cb_param.mdep_cfg_index = (int ) p_scb->mdep_cfg_idx; - send_cb_param.cb_state = BTIF_HL_CHAN_CB_STATE_DISCONNECTED_PENDING; + evt_param.chan_cb.app_id = (int) btif_hl_get_app_id(p_scb->channel_id); + memcpy(evt_param.chan_cb.bd_addr, p_scb->bd_addr, sizeof(BD_ADDR)); + evt_param.chan_cb.channel_id = p_scb->channel_id; + evt_param.chan_cb.fd = p_scb->socket_id[0]; + evt_param.chan_cb.mdep_cfg_index = (int ) p_scb->mdep_cfg_idx; + evt_param.chan_cb.cb_state = BTIF_HL_CHAN_CB_STATE_DISCONNECTED_PENDING; len = sizeof(btif_hl_send_chan_state_cb_t); - status = btif_transfer_context (btif_hl_send_chan_state_cb_evt, BTIF_HL_SEND_DISCONNECTED_CB, - (char*) &send_cb_param, len, NULL); + status = btif_transfer_context (btif_hl_proc_cb_evt, BTIF_HL_SEND_DISCONNECTED_CB, + (char*) &evt_param, len, NULL); ASSERTC(status == BT_STATUS_SUCCESS, "context transfer failed", status); - //btif_hl_send_disconnected_cb(p_scb); + + } } p_scb = (btif_hl_soc_cb_t *)GKI_getnext((void *)p_scb ); @@ -3875,12 +4832,18 @@ void btif_hl_close_socket( fd_set *p_org_set){ BTIF_TRACE_DEBUG1("while loop p_scb=0x%x", p_scb); } - - } BTIF_TRACE_DEBUG1("leaving %s",__FUNCTION__); } - +/******************************************************************************* +** +** Function btif_hl_select_wakeup_callback +** +** Description Select wakup callback to add or close a socket +** +** Returns void +** +*******************************************************************************/ void btif_hl_select_wakeup_callback( fd_set *p_org_set , int wakeup_signal){ BTIF_TRACE_DEBUG2("entering %s wakeup_signal=0x%04x",__FUNCTION__, wakeup_signal); @@ -3896,7 +4859,15 @@ void btif_hl_select_wakeup_callback( fd_set *p_org_set , int wakeup_signal){ BTIF_TRACE_DEBUG1("leaving %s",__FUNCTION__); } - +/******************************************************************************* +** +** Function btif_hl_select_monitor_callback +** +** Description Select monitor callback to check pending socket actions +** +** Returns void +** +*******************************************************************************/ void btif_hl_select_monitor_callback( fd_set *p_cur_set , fd_set *p_org_set){ btif_hl_soc_cb_t *p_scb = NULL; btif_hl_mdl_cb_t *p_dcb = NULL; @@ -3955,11 +4926,17 @@ void btif_hl_select_monitor_callback( fd_set *p_cur_set , fd_set *p_org_set){ } BTIF_TRACE_DEBUG1("leaving %s",__FUNCTION__); } - -/* create dummy socket pair used to wake up select loop */ +/******************************************************************************* +** +** Function btif_hl_select_wakeup_init +** +** Description select loop wakup init +** +** Returns int +** +*******************************************************************************/ static inline int btif_hl_select_wakeup_init(fd_set* set){ BTIF_TRACE_DEBUG0("btif_hl_select_wakeup_init"); - //if (signal_fds[0] == 0 && socketpair(AF_UNIX, SOCK_STREAM, 0, signal_fds) < 0) if (socketpair(AF_UNIX, SOCK_STREAM, 0, signal_fds) < 0) { BTIF_TRACE_ERROR1("socketpair failed: %s", strerror(errno)); @@ -3972,23 +4949,44 @@ static inline int btif_hl_select_wakeup_init(fd_set* set){ return signal_fds[0]; } - +/******************************************************************************* +** +** Function btif_hl_select_wakeup +** +** Description send a signal to wakupo the select loop +** +** Returns int +** +*******************************************************************************/ static inline int btif_hl_select_wakeup(void){ char sig_on = btif_hl_signal_select_wakeup; BTIF_TRACE_DEBUG0("btif_hl_select_wakeup"); return send(signal_fds[1], &sig_on, sizeof(sig_on), 0); } -static inline int btif_hl_select_exit(void){ - char sig_on = btif_hl_signal_select_exit; - BTIF_TRACE_DEBUG0("btif_hl_select_exit"); - return send(signal_fds[1], &sig_on, sizeof(sig_on), 0); -} + +/******************************************************************************* +** +** Function btif_hl_select_close_connected +** +** Description send a signal to close a socket +** +** Returns int +** +*******************************************************************************/ static inline int btif_hl_select_close_connected(void){ char sig_on = btif_hl_signal_select_close_connected; BTIF_TRACE_DEBUG0("btif_hl_select_close_connected"); return send(signal_fds[1], &sig_on, sizeof(sig_on), 0); } -/* clear signal by reading signal */ +/******************************************************************************* +** +** Function btif_hl_select_wake_reset +** +** Description clear the received signal for the select loop +** +** Returns int +** +*******************************************************************************/ static inline int btif_hl_select_wake_reset(void){ char sig_recv = 0; @@ -3996,12 +4994,28 @@ static inline int btif_hl_select_wake_reset(void){ recv(signal_fds[0], &sig_recv, sizeof(sig_recv), MSG_WAITALL); return(int)sig_recv; } - +/******************************************************************************* +** +** Function btif_hl_select_wake_signaled +** +** Description check whether a fd is set or not +** +** Returns int +** +*******************************************************************************/ static inline int btif_hl_select_wake_signaled(fd_set* set){ BTIF_TRACE_DEBUG0("btif_hl_select_wake_signaled"); return FD_ISSET(signal_fds[0], set); } - +/******************************************************************************* +** +** Function btif_hl_thread_cleanup +** +** Description shut down and clean up the select loop +** +** Returns void +** +*******************************************************************************/ static void btif_hl_thread_cleanup(){ if (listen_s != -1) close(listen_s); @@ -4014,7 +5028,15 @@ static void btif_hl_thread_cleanup(){ select_thread_id = -1; BTIF_TRACE_DEBUG0("hl thread cleanup"); } - +/******************************************************************************* +** +** Function btif_hl_select_thread +** +** Description the select loop +** +** Returns void +** +*******************************************************************************/ static void *btif_hl_select_thread(void *arg){ fd_set org_set, curr_set; int r, max_curr_s, max_org_s; @@ -4049,8 +5071,6 @@ static void *btif_hl_select_thread(void *arg){ { btif_hl_select_wakeup_callback(&org_set, r); } - - } btif_hl_select_monitor_callback(&curr_set, &org_set); @@ -4063,7 +5083,15 @@ static void *btif_hl_select_thread(void *arg){ return 0; } - +/******************************************************************************* +** +** Function create_thread +** +** Description creat a select loop +** +** Returns pthread_t +** +*******************************************************************************/ static inline pthread_t create_thread(void *(*start_routine)(void *), void * arg){ BTIF_TRACE_DEBUG0("create_thread: entered"); pthread_attr_t thread_attr; @@ -4084,7 +5112,7 @@ static inline pthread_t create_thread(void *(*start_routine)(void *), void * arg ** ** Function btif_hl_soc_thread_init ** -** Description HL socket thread init function. +** Description HL select loop init function. ** ** Returns void ** @@ -4094,5 +5122,29 @@ void btif_hl_soc_thread_init(void){ GKI_init_q(&soc_queue); select_thread_id = create_thread(btif_hl_select_thread, NULL); } +/******************************************************************************* +** +** Function btif_hl_load_mdl_config +** +** Description load the MDL configuation from the application control block +** +** Returns BOOLEAN +** +*******************************************************************************/ +BOOLEAN btif_hl_load_mdl_config (UINT8 app_id, UINT8 buffer_size, + tBTA_HL_MDL_CFG *p_mdl_buf ){ + UINT8 app_idx; + BOOLEAN result = FALSE; + btif_hl_app_cb_t *p_acb; + BTIF_TRACE_DEBUG1("%s", __FUNCTION__); + if (btif_hl_find_app_idx(app_id, &app_idx)) + { + p_acb = BTIF_HL_GET_APP_CB_PTR(app_idx); + memcpy(p_mdl_buf, &p_acb->mdl_cfg[0], (sizeof(tBTA_HL_MDL_CFG)*buffer_size)); + result = TRUE; + } + BTIF_TRACE_DEBUG1("result=%d", result); + return result; +} diff --git a/btif/src/btif_storage.c b/btif/src/btif_storage.c index e289634..764821b 100644..100755 --- a/btif/src/btif_storage.c +++ b/btif/src/btif_storage.c @@ -188,13 +188,19 @@ /* check against unv max entry size at compile time */ #if (BTIF_STORAGE_ENTRY_MAX_SIZE > UNV_MAXLINE_LENGTH) -#error "btif storage entry size exceeds unv max line size" + #error "btif storage entry size exceeds unv max line size" #endif + + +#define BTIF_STORAGE_HL_APP_CB "hl_app_cb" +#define BTIF_STORAGE_HL_APP_DATA "hl_app_data_" +#define BTIF_STORAGE_HL_APP_MDL_DATA "hl_app_mdl_data_" /************************************************************************************ ** Local type definitions ************************************************************************************/ -typedef struct { +typedef struct +{ uint32_t num_devices; bt_bdaddr_t devices[BTM_SEC_MAX_DEVICE_RECORDS]; } btif_bonded_devices_t; @@ -223,22 +229,22 @@ extern bt_bdaddr_t btif_local_bd_addr; *******************************************************************************/ static char* btif_in_make_filename(bt_bdaddr_t *bd_addr, char *fname) { - static char path[256]; - bdstr_t bdstr; + static char path[256]; + bdstr_t bdstr; - if (fname == NULL)return NULL; - if (bd_addr) - { + if (fname == NULL)return NULL; + if (bd_addr) + { sprintf(path, "%s/%s/%s", BTIF_STORAGE_PATH_BLUEDROID, - bd2str(bd_addr, &bdstr), fname); - } - else - { + bd2str(bd_addr, &bdstr), fname); + } + else + { /* local adapter */ sprintf(path, "%s/LOCAL/%s", BTIF_STORAGE_PATH_BLUEDROID, fname); - } + } - return (char*)path; + return(char*)path; } /******************************************************************************* @@ -253,8 +259,8 @@ static char* btif_in_make_filename(bt_bdaddr_t *bd_addr, char *fname) *******************************************************************************/ static const char *btif_in_get_adapter_key_from_type(bt_property_type_t type) { - switch (type) - { + switch (type) + { case BT_PROPERTY_BDNAME: return BTIF_STORAGE_KEY_ADAPTER_NAME; case BT_PROPERTY_ADAPTER_SCAN_MODE: @@ -264,7 +270,7 @@ static const char *btif_in_get_adapter_key_from_type(bt_property_type_t type) default: /* return valid string to avoid passing NULL to NV RAM driver */ return "NO_KEY"; - } + } } /******************************************************************************* @@ -278,7 +284,7 @@ static const char *btif_in_get_adapter_key_from_type(bt_property_type_t type) ** *******************************************************************************/ static void btif_in_split_uuids_string_to_list(char *str, bt_uuid_t *p_uuid, - uint32_t *p_num_uuid) + uint32_t *p_num_uuid) { char buf[64]; char *p_start = str; @@ -317,59 +323,60 @@ static bt_status_t btif_in_str_to_property(char *value, bt_property_t *property) /* if Value is NULL, then just set the property->len to 0 and return. This is possible if the entry does not exist */ - if (value == NULL) { + if (value == NULL) + { status = BT_STATUS_FAIL; } switch (property->type) { case BT_PROPERTY_BDNAME: case BT_PROPERTY_REMOTE_FRIENDLY_NAME: - { - *((char*)property->val) = 0; - if (value) { - property->len = strlen(value)+1; - strcpy((char*)property->val, value); - } - } break; + *((char*)property->val) = 0; + if (value) + { + property->len = strlen(value)+1; + strcpy((char*)property->val, value); + } + } break; case BT_PROPERTY_ADAPTER_SCAN_MODE: case BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT: - { - *((uint32_t *)property->val) = 0; - if (value) { - uint32_t ival; - property->len = sizeof(uint32_t); - ival = atoi(value); - memcpy((uint32_t*)property->val, &ival, sizeof(uint32_t)); - } - } break; + *((uint32_t *)property->val) = 0; + if (value) + { + uint32_t ival; + property->len = sizeof(uint32_t); + ival = atoi(value); + memcpy((uint32_t*)property->val, &ival, sizeof(uint32_t)); + } + } break; case BT_PROPERTY_CLASS_OF_DEVICE: case BT_PROPERTY_TYPE_OF_DEVICE: - { - *((uint32_t *)property->val) = 0; - if (value) { - uint32_t ival; - property->len = sizeof(uint32_t); - ival = strtol(value, NULL, 16); - memcpy((uint32_t*)property->val, &ival, sizeof(uint32_t)); - } - } break; + *((uint32_t *)property->val) = 0; + if (value) + { + uint32_t ival; + property->len = sizeof(uint32_t); + ival = strtol(value, NULL, 16); + memcpy((uint32_t*)property->val, &ival, sizeof(uint32_t)); + } + } break; case BT_PROPERTY_UUIDS: - { - if (value) { - bt_uuid_t *p_uuid = (bt_uuid_t*)property->val; - uint32_t num_uuids = 0; - btif_in_split_uuids_string_to_list(value, p_uuid, &num_uuids); - property->len = num_uuids * sizeof(bt_uuid_t); - } - } break; + if (value) + { + bt_uuid_t *p_uuid = (bt_uuid_t*)property->val; + uint32_t num_uuids = 0; + btif_in_split_uuids_string_to_list(value, p_uuid, &num_uuids); + property->len = num_uuids * sizeof(bt_uuid_t); + } + } break; default: - { - break; - } + { + break; + } } return status; } @@ -389,43 +396,43 @@ static bt_status_t btif_in_property_to_str(bt_property_t *property, char *value) switch (property->type) { case BT_PROPERTY_REMOTE_DEVICE_TIMESTAMP: - { - sprintf(value, "%d", (int)time(NULL)); - }break; + { + sprintf(value, "%d", (int)time(NULL)); + }break; case BT_PROPERTY_BDNAME: case BT_PROPERTY_REMOTE_FRIENDLY_NAME: - { - strcpy(value, (char*)property->val); - }break; + { + strcpy(value, (char*)property->val); + }break; case BT_PROPERTY_ADAPTER_SCAN_MODE: case BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT: - { - sprintf(value, "%d", *((uint32_t*)property->val)); - }break; + { + sprintf(value, "%d", *((uint32_t*)property->val)); + }break; case BT_PROPERTY_CLASS_OF_DEVICE: case BT_PROPERTY_TYPE_OF_DEVICE: - { - sprintf(value, "0x%x", *((uint32_t*)property->val)); - }break; + { + sprintf(value, "0x%x", *((uint32_t*)property->val)); + }break; case BT_PROPERTY_UUIDS: - { - uint32_t i; - char buf[64]; - value[0] = 0; - for (i=0; i < (property->len)/sizeof(bt_uuid_t); i++) { - bt_uuid_t *p_uuid = (bt_uuid_t*)property->val + i; - memset(buf, 0, sizeof(buf)); - uuid_to_string(p_uuid, buf); - strcat(value, buf); - strcat(value, ";"); - } - value[strlen(value)] = 0; - }break; + uint32_t i; + char buf[64]; + value[0] = 0; + for (i=0; i < (property->len)/sizeof(bt_uuid_t); i++) + { + bt_uuid_t *p_uuid = (bt_uuid_t*)property->val + i; + memset(buf, 0, sizeof(buf)); + uuid_to_string(p_uuid, buf); + strcat(value, buf); + strcat(value, ";"); + } + value[strlen(value)] = 0; + }break; default: - { - return BT_STATUS_FAIL; - } + { + return BT_STATUS_FAIL; + } } return BT_STATUS_SUCCESS; } @@ -442,24 +449,24 @@ static bt_status_t btif_in_property_to_str(bt_property_t *property, char *value) *******************************************************************************/ static char* btif_in_get_remote_device_path_from_property(bt_property_type_t type) { - switch (type) - { - case BT_PROPERTY_BDADDR: - case BT_PROPERTY_REMOTE_DEVICE_TIMESTAMP: - return BTIF_STORAGE_PATH_REMOTE_DEVICES; - case BT_PROPERTY_BDNAME: - return BTIF_STORAGE_PATH_REMOTE_NAMES; - case BT_PROPERTY_CLASS_OF_DEVICE: - return BTIF_STORAGE_PATH_REMOTE_DEVCLASSES; - case BT_PROPERTY_TYPE_OF_DEVICE: - return BTIF_STORAGE_PATH_REMOTE_DEVTYPES; - case BT_PROPERTY_REMOTE_FRIENDLY_NAME: - return BTIF_STORAGE_PATH_REMOTE_ALIASES; - case BT_PROPERTY_UUIDS: - return BTIF_STORAGE_PATH_REMOTE_SERVICES; - default: - return NULL; - } + switch (type) + { + case BT_PROPERTY_BDADDR: + case BT_PROPERTY_REMOTE_DEVICE_TIMESTAMP: + return BTIF_STORAGE_PATH_REMOTE_DEVICES; + case BT_PROPERTY_BDNAME: + return BTIF_STORAGE_PATH_REMOTE_NAMES; + case BT_PROPERTY_CLASS_OF_DEVICE: + return BTIF_STORAGE_PATH_REMOTE_DEVCLASSES; + case BT_PROPERTY_TYPE_OF_DEVICE: + return BTIF_STORAGE_PATH_REMOTE_DEVTYPES; + case BT_PROPERTY_REMOTE_FRIENDLY_NAME: + return BTIF_STORAGE_PATH_REMOTE_ALIASES; + case BT_PROPERTY_UUIDS: + return BTIF_STORAGE_PATH_REMOTE_SERVICES; + default: + return NULL; + } } /******************************************************************************* @@ -519,7 +526,7 @@ int btif_in_load_device_iter_cb(char *key, char *value, void *userdata) /* add extracted information to BTA security manager */ BTA_DmAddDevice(bd_addr.address, dev_class, link_key, 0, 0, key_type, 0); - /* Fill in the bonded devices */ + /* Fill in the bonded devices */ memcpy(&p_bonded_devices->devices[p_bonded_devices->num_devices++], &bd_addr, sizeof(bt_bdaddr_t)); return 0; @@ -630,7 +637,8 @@ static int hex_str_to_int(const char* str, int size) { int n = 0; char c = *str++; - while (size-- != 0) { + while (size-- != 0) + { n <<= 4; if (c >= '0' && c <= '9') { n |= c - '0'; @@ -638,7 +646,8 @@ static int hex_str_to_int(const char* str, int size) else if (c >= 'a' && c <= 'z') { n |= c - 'a' + 10; } - else { // (c >= 'A' && c <= 'Z') + else // (c >= 'A' && c <= 'Z') + { n |= c - 'A' + 10; } @@ -795,26 +804,27 @@ bt_status_t btif_storage_get_adapter_property(bt_property_t *property) for (i=0; i < BTA_MAX_SERVICE_ID; i++) { /* This should eventually become a function when more services are enabled */ - if(service_mask + if (service_mask &(tBTA_SERVICE_MASK)(1 << i)) { - switch (i) { - case BTA_HFP_SERVICE_ID: - { - uuid16_to_uuid128(UUID_SERVCLASS_AG_HANDSFREE, - p_uuid+num_uuids); - num_uuids++; - uuid16_to_uuid128(UUID_SERVCLASS_HEADSET_AUDIO_GATEWAY, - p_uuid+num_uuids); - num_uuids++; - }break; - case BTA_A2DP_SERVICE_ID: - { - uuid16_to_uuid128(UUID_SERVCLASS_AUDIO_SOURCE, - p_uuid+num_uuids); - num_uuids++; - }break; - } + switch (i) + { + case BTA_HFP_SERVICE_ID: + { + uuid16_to_uuid128(UUID_SERVCLASS_AG_HANDSFREE, + p_uuid+num_uuids); + num_uuids++; + uuid16_to_uuid128(UUID_SERVCLASS_HEADSET_AUDIO_GATEWAY, + p_uuid+num_uuids); + num_uuids++; + }break; + case BTA_A2DP_SERVICE_ID: + { + uuid16_to_uuid128(UUID_SERVCLASS_AUDIO_SOURCE, + p_uuid+num_uuids); + num_uuids++; + }break; + } } } property->len = (num_uuids)*sizeof(bt_uuid_t); @@ -911,7 +921,7 @@ bt_status_t btif_storage_set_adapter_property(bt_property_t *property) ** *******************************************************************************/ bt_status_t btif_storage_get_remote_device_property(bt_bdaddr_t *remote_bd_addr, - bt_property_t *property) + bt_property_t *property) { char linebuf[BTIF_STORAGE_MAX_LINE_SZ]; char *fname; @@ -920,12 +930,14 @@ bt_status_t btif_storage_get_remote_device_property(bt_bdaddr_t *remote_bd_addr, bdstr_t bdstr; fname = btif_in_make_filename(NULL, - btif_in_get_remote_device_path_from_property(property->type)); + btif_in_get_remote_device_path_from_property(property->type)); + if (fname == NULL) { return BT_STATUS_FAIL; } + ret = unv_create_file(fname); if (ret < 0) { @@ -949,7 +961,7 @@ bt_status_t btif_storage_get_remote_device_property(bt_bdaddr_t *remote_bd_addr, ** *******************************************************************************/ bt_status_t btif_storage_set_remote_device_property(bt_bdaddr_t *remote_bd_addr, - bt_property_t *property) + bt_property_t *property) { char value[1200]; char *fname; @@ -957,11 +969,15 @@ bt_status_t btif_storage_set_remote_device_property(bt_bdaddr_t *remote_bd_addr, int ret; fname = btif_in_make_filename(NULL, - btif_in_get_remote_device_path_from_property(property->type)); + btif_in_get_remote_device_path_from_property(property->type)); + + if (fname == NULL) { return BT_STATUS_FAIL; } + + ret = unv_create_file(fname); if (ret < 0) { @@ -996,8 +1012,8 @@ bt_status_t btif_storage_set_remote_device_property(bt_bdaddr_t *remote_bd_addr, ** *******************************************************************************/ bt_status_t btif_storage_add_remote_device(bt_bdaddr_t *remote_bdaddr, - uint32_t num_properties, - bt_property_t *properties) + uint32_t num_properties, + bt_property_t *properties) { uint32_t i = 0; /* TODO: If writing a property, fails do we go back undo the earlier @@ -1039,9 +1055,9 @@ bt_status_t btif_storage_add_remote_device(bt_bdaddr_t *remote_bdaddr, *******************************************************************************/ bt_status_t btif_storage_add_bonded_device(bt_bdaddr_t *remote_bd_addr, - LINK_KEY link_key, - uint8_t key_type, - uint8_t pin_length) + LINK_KEY link_key, + uint8_t key_type, + uint8_t pin_length) { char value[STORAGE_REMOTE_LINKKEYS_ENTRY_SIZE]; uint32_t i = 0; @@ -1073,7 +1089,7 @@ bt_status_t btif_storage_add_bonded_device(bt_bdaddr_t *remote_bd_addr, memset(value, 0, sizeof(value)); for (i = 0; i < LINK_KEY_LEN; i++) - sprintf(value + (i * 2), "%2.2X", link_key[i]); + sprintf(value + (i * 2), "%2.2X", link_key[i]); sprintf(value + (LINK_KEY_LEN*2), " %d %d", key_type, pin_length); @@ -1159,55 +1175,55 @@ bt_status_t btif_storage_load_bonded_devices(void) /* Now send the adapter_properties_cb with all adapter_properties */ { - memset(adapter_props, 0, sizeof(adapter_props)); + memset(adapter_props, 0, sizeof(adapter_props)); - /* BD_ADDR */ - BTIF_STORAGE_GET_ADAPTER_PROP(BT_PROPERTY_BDADDR, &addr, sizeof(addr), + /* BD_ADDR */ + BTIF_STORAGE_GET_ADAPTER_PROP(BT_PROPERTY_BDADDR, &addr, sizeof(addr), adapter_props[num_props]); - num_props++; - - /* BD_NAME */ - BTIF_STORAGE_GET_ADAPTER_PROP(BT_PROPERTY_BDNAME, &name, sizeof(name), - adapter_props[num_props]); - num_props++; - - /* SCAN_MODE */ - /* TODO: At the time of BT on, always report the scan mode as 0 irrespective - of the scan_mode during the previous enable cycle. - This needs to be re-visited as part of the app/stack enable sequence - synchronization */ - mode = BT_SCAN_MODE_NONE; - adapter_props[num_props].type = BT_PROPERTY_ADAPTER_SCAN_MODE; - adapter_props[num_props].len = sizeof(mode); - adapter_props[num_props].val = &mode; - num_props++; - - /* DISC_TIMEOUT */ - BTIF_STORAGE_GET_ADAPTER_PROP(BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT, + num_props++; + + /* BD_NAME */ + BTIF_STORAGE_GET_ADAPTER_PROP(BT_PROPERTY_BDNAME, &name, sizeof(name), + adapter_props[num_props]); + num_props++; + + /* SCAN_MODE */ + /* TODO: At the time of BT on, always report the scan mode as 0 irrespective + of the scan_mode during the previous enable cycle. + This needs to be re-visited as part of the app/stack enable sequence + synchronization */ + mode = BT_SCAN_MODE_NONE; + adapter_props[num_props].type = BT_PROPERTY_ADAPTER_SCAN_MODE; + adapter_props[num_props].len = sizeof(mode); + adapter_props[num_props].val = &mode; + num_props++; + + /* DISC_TIMEOUT */ + BTIF_STORAGE_GET_ADAPTER_PROP(BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT, &disc_timeout, sizeof(disc_timeout), adapter_props[num_props]); - num_props++; - - /* BONDED_DEVICES */ - devices_list = (bt_bdaddr_t*)malloc(sizeof(bt_bdaddr_t)*bonded_devices.num_devices); - adapter_props[num_props].type = BT_PROPERTY_ADAPTER_BONDED_DEVICES; - adapter_props[num_props].len = bonded_devices.num_devices * sizeof(bt_bdaddr_t); - adapter_props[num_props].val = devices_list; - for (i=0; i < bonded_devices.num_devices; i++) - { - memcpy(devices_list + i, &bonded_devices.devices[i], sizeof(bt_bdaddr_t)); - } - num_props++; - - /* LOCAL UUIDs */ - BTIF_STORAGE_GET_ADAPTER_PROP(BT_PROPERTY_UUIDS, - local_uuids, sizeof(local_uuids), - adapter_props[num_props]); - num_props++; - - btif_adapter_properties_evt(BT_STATUS_SUCCESS, num_props, adapter_props); - - free(devices_list); + num_props++; + + /* BONDED_DEVICES */ + devices_list = (bt_bdaddr_t*)malloc(sizeof(bt_bdaddr_t)*bonded_devices.num_devices); + adapter_props[num_props].type = BT_PROPERTY_ADAPTER_BONDED_DEVICES; + adapter_props[num_props].len = bonded_devices.num_devices * sizeof(bt_bdaddr_t); + adapter_props[num_props].val = devices_list; + for (i=0; i < bonded_devices.num_devices; i++) + { + memcpy(devices_list + i, &bonded_devices.devices[i], sizeof(bt_bdaddr_t)); + } + num_props++; + + /* LOCAL UUIDs */ + BTIF_STORAGE_GET_ADAPTER_PROP(BT_PROPERTY_UUIDS, + local_uuids, sizeof(local_uuids), + adapter_props[num_props]); + num_props++; + + btif_adapter_properties_evt(BT_STATUS_SUCCESS, num_props, adapter_props); + + free(devices_list); } BTIF_TRACE_EVENT2("%s: %d bonded devices found", __FUNCTION__, bonded_devices.num_devices); @@ -1215,39 +1231,39 @@ bt_status_t btif_storage_load_bonded_devices(void) { for (i = 0; i < bonded_devices.num_devices; i++) { - bt_bdaddr_t *p_remote_addr; - - num_props = 0; - p_remote_addr = &bonded_devices.devices[i]; - memset(remote_properties, 0, sizeof(remote_properties)); - BTIF_STORAGE_GET_REMOTE_PROP(p_remote_addr, BT_PROPERTY_BDNAME, - &name, sizeof(name), - remote_properties[num_props]); - num_props++; - - BTIF_STORAGE_GET_REMOTE_PROP(p_remote_addr, BT_PROPERTY_REMOTE_FRIENDLY_NAME, - &alias, sizeof(alias), - remote_properties[num_props]); - num_props++; - - BTIF_STORAGE_GET_REMOTE_PROP(p_remote_addr, BT_PROPERTY_CLASS_OF_DEVICE, - &cod, sizeof(cod), - remote_properties[num_props]); - num_props++; - - BTIF_STORAGE_GET_REMOTE_PROP(p_remote_addr, BT_PROPERTY_TYPE_OF_DEVICE, - &devtype, sizeof(devtype), - remote_properties[num_props]); - num_props++; - - BTIF_STORAGE_GET_REMOTE_PROP(p_remote_addr, BT_PROPERTY_UUIDS, - remote_uuids, sizeof(remote_uuids), - remote_properties[num_props]); - num_props++; - - btif_remote_properties_evt(BT_STATUS_SUCCESS, p_remote_addr, - num_props, remote_properties); - } + bt_bdaddr_t *p_remote_addr; + + num_props = 0; + p_remote_addr = &bonded_devices.devices[i]; + memset(remote_properties, 0, sizeof(remote_properties)); + BTIF_STORAGE_GET_REMOTE_PROP(p_remote_addr, BT_PROPERTY_BDNAME, + &name, sizeof(name), + remote_properties[num_props]); + num_props++; + + BTIF_STORAGE_GET_REMOTE_PROP(p_remote_addr, BT_PROPERTY_REMOTE_FRIENDLY_NAME, + &alias, sizeof(alias), + remote_properties[num_props]); + num_props++; + + BTIF_STORAGE_GET_REMOTE_PROP(p_remote_addr, BT_PROPERTY_CLASS_OF_DEVICE, + &cod, sizeof(cod), + remote_properties[num_props]); + num_props++; + + BTIF_STORAGE_GET_REMOTE_PROP(p_remote_addr, BT_PROPERTY_TYPE_OF_DEVICE, + &devtype, sizeof(devtype), + remote_properties[num_props]); + num_props++; + + BTIF_STORAGE_GET_REMOTE_PROP(p_remote_addr, BT_PROPERTY_UUIDS, + remote_uuids, sizeof(remote_uuids), + remote_properties[num_props]); + num_props++; + + btif_remote_properties_evt(BT_STATUS_SUCCESS, p_remote_addr, + num_props, remote_properties); + } } return BT_STATUS_SUCCESS; } @@ -1426,3 +1442,249 @@ bt_status_t btif_storage_remove_hid_info(bt_bdaddr_t *remote_bd_addr) return BT_STATUS_SUCCESS; } +/******************************************************************************* +** +** Function btif_storage_read_hl_apps_cb +** +** Description BTIF storage API - Read HL application control block from NVRAM +** +** Returns BT_STATUS_SUCCESS if the operation was successful, +** BT_STATUS_FAIL otherwise +** +*******************************************************************************/ +bt_status_t btif_storage_read_hl_apps_cb(char *value, int value_size) +{ + char fname[256], tmp[3]; + bt_status_t bt_status = BT_STATUS_SUCCESS; + int status=FALSE, i, buf_size; + char *p_buf; + + BTIF_TRACE_DEBUG1("%s ", __FUNCTION__); + sprintf(fname, "%s/LOCAL/%s", BTIF_STORAGE_PATH_BLUEDROID, BTIF_STORAGE_HL_APP_CB); + buf_size = value_size*2; + p_buf = malloc(buf_size); + BTIF_TRACE_DEBUG2("value_size=%d buf_size=%d", value_size, buf_size); + if (p_buf) + { + if ((status = unv_read_hl_apps_cb(fname, p_buf, buf_size))!=0) + { + bt_status = BT_STATUS_FAIL; + } + else + { + for (i = 0; i < value_size; i++) + { + memcpy(tmp, p_buf + (i * 2), 2); + value[i] = (uint8_t) strtol(tmp, NULL, 16); + } + } + + free(p_buf); + } + else + { + bt_status = BT_STATUS_FAIL; + } + + BTIF_TRACE_DEBUG4("%s read file:(%s) read status=%d bt_status=%d", __FUNCTION__, fname, status, bt_status); + return bt_status; +} + +/******************************************************************************* +** +** Function btif_storage_write_hl_apps_cb +** +** Description BTIF storage API - Write HL application control block to NVRAM +** +** Returns BT_STATUS_SUCCESS if the operation was successful, +** BT_STATUS_FAIL otherwise +** +*******************************************************************************/ +bt_status_t btif_storage_write_hl_apps_cb(char *value, int value_size) +{ + char fname[256]; + bt_status_t bt_status = BT_STATUS_SUCCESS; + int status=FALSE, i, buf_size; + char *p_buf; + + BTIF_TRACE_DEBUG1("%s ", __FUNCTION__); + sprintf(fname, "%s/LOCAL/%s", BTIF_STORAGE_PATH_BLUEDROID, BTIF_STORAGE_HL_APP_CB); + buf_size = value_size * 2; + p_buf = malloc(buf_size); + BTIF_TRACE_DEBUG2("value_size=%d buf_size=%d", value_size, buf_size); + if (p_buf) + { + for (i = 0; i < value_size; i++) + sprintf(p_buf + (i * 2), "%2.2X", value[i]); + + if ((status = unv_write_hl_apps_cb(fname, p_buf, buf_size))!=0) + bt_status = BT_STATUS_FAIL; + + free(p_buf); + } + else + { + bt_status = BT_STATUS_FAIL; + } + BTIF_TRACE_DEBUG4("%s write file:(%s) write status=%d bt_status=%d", __FUNCTION__, fname, status, bt_status); + return bt_status; +} + +bt_status_t btif_storage_read_hl_data(char *fname, char *value, int value_size) +{ + char tmp[3]; + bt_status_t bt_status = BT_STATUS_SUCCESS; + int i, buf_size; + char *p_buf; + + buf_size = value_size*2; + p_buf = malloc(buf_size); + BTIF_TRACE_DEBUG3("%s value_size=%d buf_size=%d", __FUNCTION__, value_size, buf_size); + if (p_buf) + { + if (unv_read_hl_data(fname, p_buf, buf_size) != 0) + { + bt_status = BT_STATUS_FAIL; + } + else + { + for (i = 0; i < value_size; i++) + { + memcpy(tmp, p_buf + (i * 2), 2); + value[i] = (uint8_t) strtol(tmp, NULL, 16); + } + } + free(p_buf); + } + else + { + bt_status = BT_STATUS_FAIL; + } + BTIF_TRACE_DEBUG1("bt_status=%d", bt_status); + return bt_status; +} + +bt_status_t btif_storage_write_hl_data(char *fname, char *value, int value_size) +{ + bt_status_t bt_status = BT_STATUS_SUCCESS; + int i, buf_size; + char *p_buf; + + buf_size = value_size * 2; + p_buf = malloc(buf_size); + BTIF_TRACE_DEBUG3("%s value_size=%d buf_size=%d", __FUNCTION__, value_size, buf_size); + if (p_buf) + { + for (i = 0; i < value_size; i++) + sprintf(p_buf + (i * 2), "%2.2X", value[i]); + + if ( unv_write_hl_data(fname, p_buf, buf_size)!= 0) + bt_status = BT_STATUS_FAIL; + + free(p_buf); + } + else + { + bt_status = BT_STATUS_FAIL; + } + BTIF_TRACE_DEBUG1("bt_status=%d", bt_status); + + return bt_status; +} + +/******************************************************************************* +** +** Function btif_storage_read_hl_apps_cb +** +** Description BTIF storage API - Read HL application configuration from NVRAM +** +** Returns BT_STATUS_SUCCESS if the operation was successful, +** BT_STATUS_FAIL otherwise +** +*******************************************************************************/ +bt_status_t btif_storage_read_hl_app_data(UINT8 app_idx, char *value, int value_size) +{ + char fname[256]; + bt_status_t bt_status = BT_STATUS_SUCCESS; + + BTIF_TRACE_DEBUG1("%s ", __FUNCTION__); + sprintf(fname, "%s/LOCAL/%s%d", BTIF_STORAGE_PATH_BLUEDROID, BTIF_STORAGE_HL_APP_DATA, app_idx); + bt_status = btif_storage_read_hl_data(fname, value, value_size); + BTIF_TRACE_DEBUG3("%s read file:(%s) bt_status=%d", __FUNCTION__, fname, bt_status); + + return bt_status; +} + +/******************************************************************************* +** +** Function btif_storage_read_hl_mdl_data +** +** Description BTIF storage API - Read HL application MDL configuration from NVRAM +** +** Returns BT_STATUS_SUCCESS if the operation was successful, +** BT_STATUS_FAIL otherwise +** +*******************************************************************************/ +bt_status_t btif_storage_write_hl_app_data(UINT8 app_idx, char *value, int value_size) +{ + char fname[256]; + bt_status_t bt_status = BT_STATUS_SUCCESS; + + + BTIF_TRACE_DEBUG1("%s ", __FUNCTION__); + sprintf(fname, "%s/LOCAL/%s%d", BTIF_STORAGE_PATH_BLUEDROID, BTIF_STORAGE_HL_APP_DATA, app_idx); + bt_status = btif_storage_write_hl_data(fname, value, value_size); + BTIF_TRACE_DEBUG3("%s write file:(%s) bt_status=%d", __FUNCTION__, fname, bt_status); + + return bt_status; +} + +/******************************************************************************* +** +** Function btif_storage_read_hl_mdl_data +** +** Description BTIF storage API - Read HL application MDL configuration from NVRAM +** +** Returns BT_STATUS_SUCCESS if the operation was successful, +** BT_STATUS_FAIL otherwise +** +*******************************************************************************/ +bt_status_t btif_storage_read_hl_mdl_data(UINT8 app_idx, char *value, int value_size) +{ + char fname[256], tmp[3]; + bt_status_t bt_status = BT_STATUS_SUCCESS; + int status, i, buf_size; + char *p_buf; + + BTIF_TRACE_DEBUG1("%s ", __FUNCTION__); + sprintf(fname, "%s/LOCAL/%s%d", BTIF_STORAGE_PATH_BLUEDROID, BTIF_STORAGE_HL_APP_MDL_DATA, app_idx); + bt_status = btif_storage_read_hl_data(fname, value, value_size); + BTIF_TRACE_DEBUG3("%s read file:(%s) bt_status=%d", __FUNCTION__, fname, bt_status); + + return bt_status; +} + +/******************************************************************************* +** +** Function btif_storage_write_hl_mdl_data +** +** Description BTIF storage API - Write HL application MDL configuration from NVRAM +** +** Returns BT_STATUS_SUCCESS if the operation was successful, +** BT_STATUS_FAIL otherwise +** +*******************************************************************************/ +bt_status_t btif_storage_write_hl_mdl_data(UINT8 app_idx, char *value, int value_size) +{ + char fname[256]; + bt_status_t bt_status = BT_STATUS_SUCCESS; + int status, i, buf_size; + char *p_buf; + + BTIF_TRACE_DEBUG1("%s ", __FUNCTION__); + sprintf(fname, "%s/LOCAL/%s%d", BTIF_STORAGE_PATH_BLUEDROID, BTIF_STORAGE_HL_APP_MDL_DATA, app_idx); + bt_status = btif_storage_write_hl_data(fname, value, value_size); + BTIF_TRACE_DEBUG3("%s write file:(%s) bt_status=%d", __FUNCTION__, fname, bt_status); + + return bt_status; +} diff --git a/stack/sdp/sdp_api.c b/stack/sdp/sdp_api.c index fc2324a..ef662f6 100644..100755 --- a/stack/sdp/sdp_api.c +++ b/stack/sdp/sdp_api.c @@ -66,9 +66,9 @@ BOOLEAN SDP_InitDiscoveryDb (tSDP_DISCOVERY_DB *p_db, UINT32 len, UINT16 num_uui num_attr > SDP_MAX_ATTR_FILTERS || num_uuid > SDP_MAX_UUID_FILTERS) { SDP_TRACE_ERROR4("SDP_InitDiscoveryDb Illegal param: p_db 0x%x, len %d, num_uuid %d, num_attr %d", - (UINT32)p_db, len, num_uuid, num_attr); + (UINT32)p_db, len, num_uuid, num_attr); - return (FALSE); + return(FALSE); } memset (p_db, 0, (size_t)len); @@ -91,7 +91,7 @@ BOOLEAN SDP_InitDiscoveryDb (tSDP_DISCOVERY_DB *p_db, UINT32 len, UINT16 num_uui p_db->num_attr_filters = num_attr; #endif - return (TRUE); + return(TRUE); } @@ -110,12 +110,12 @@ BOOLEAN SDP_CancelServiceSearch (tSDP_DISCOVERY_DB *p_db) #if SDP_CLIENT_ENABLED == TRUE tCONN_CB *p_ccb = sdpu_find_ccb_by_db (p_db); if (!p_ccb) - return (FALSE); + return(FALSE); sdp_disconnect (p_ccb, SDP_CANCEL); p_ccb->disc_state = SDP_DISC_WAIT_CANCEL; #endif - return (TRUE); + return(TRUE); } @@ -139,15 +139,15 @@ BOOLEAN SDP_ServiceSearchRequest (UINT8 *p_bd_addr, tSDP_DISCOVERY_DB *p_db, p_ccb = sdp_conn_originate (p_bd_addr); if (!p_ccb) - return (FALSE); + return(FALSE); p_ccb->disc_state = SDP_DISC_WAIT_CONN; p_ccb->p_db = p_db; p_ccb->p_cb = p_cb; - return (TRUE); + return(TRUE); #else - return (FALSE); + return(FALSE); #endif } @@ -176,7 +176,7 @@ BOOLEAN SDP_ServiceSearchAttributeRequest (UINT8 *p_bd_addr, tSDP_DISCOVERY_DB * p_ccb = sdp_conn_originate (p_bd_addr); if (!p_ccb) - return (FALSE); + return(FALSE); p_ccb->disc_state = SDP_DISC_WAIT_CONN; p_ccb->p_db = p_db; @@ -184,9 +184,9 @@ BOOLEAN SDP_ServiceSearchAttributeRequest (UINT8 *p_bd_addr, tSDP_DISCOVERY_DB * p_ccb->is_attr_search = TRUE; - return (TRUE); + return(TRUE); #else - return (FALSE); + return(FALSE); #endif } /******************************************************************************* @@ -204,7 +204,7 @@ BOOLEAN SDP_ServiceSearchAttributeRequest (UINT8 *p_bd_addr, tSDP_DISCOVERY_DB * ** *******************************************************************************/ BOOLEAN SDP_ServiceSearchAttributeRequest2 (UINT8 *p_bd_addr, tSDP_DISCOVERY_DB *p_db, - tSDP_DISC_CMPL_CB2 *p_cb2, void * user_data) + tSDP_DISC_CMPL_CB2 *p_cb2, void * user_data) { #if SDP_CLIENT_ENABLED == TRUE tCONN_CB *p_ccb; @@ -213,7 +213,7 @@ BOOLEAN SDP_ServiceSearchAttributeRequest2 (UINT8 *p_bd_addr, tSDP_DISCOVERY_DB p_ccb = sdp_conn_originate (p_bd_addr); if (!p_ccb) - return (FALSE); + return(FALSE); p_ccb->disc_state = SDP_DISC_WAIT_CONN; p_ccb->p_db = p_db; @@ -222,9 +222,9 @@ BOOLEAN SDP_ServiceSearchAttributeRequest2 (UINT8 *p_bd_addr, tSDP_DISCOVERY_DB p_ccb->is_attr_search = TRUE; p_ccb->user_data = user_data; - return (TRUE); + return(TRUE); #else - return (FALSE); + return(FALSE); #endif } @@ -255,7 +255,7 @@ tSDP_DISC_REC *SDP_FindAttributeInDb (tSDP_DISCOVERY_DB *p_db, UINT16 attr_id, /* Must have a valid database */ if (p_db == NULL) - return (NULL); + return(NULL); if (!p_start_rec) p_rec = p_db->p_first_rec; @@ -268,7 +268,7 @@ tSDP_DISC_REC *SDP_FindAttributeInDb (tSDP_DISCOVERY_DB *p_db, UINT16 attr_id, while (p_attr) { if (p_attr->attr_id == attr_id) - return (p_rec); + return(p_rec); p_attr = p_attr->p_next_attr; } @@ -277,7 +277,7 @@ tSDP_DISC_REC *SDP_FindAttributeInDb (tSDP_DISCOVERY_DB *p_db, UINT16 attr_id, } #endif /* If here, no matching attribute found */ - return (NULL); + return(NULL); } @@ -300,13 +300,13 @@ tSDP_DISC_ATTR *SDP_FindAttributeInRec (tSDP_DISC_REC *p_rec, UINT16 attr_id) while (p_attr) { if (p_attr->attr_id == attr_id) - return (p_attr); + return(p_attr); p_attr = p_attr->p_next_attr; } #endif /* If here, no matching attribute found */ - return (NULL); + return(NULL); } /******************************************************************************* @@ -332,7 +332,7 @@ BOOLEAN SDP_FindServiceUUIDInRec(tSDP_DISC_REC *p_rec, tBT_UUID * p_uuid) while (p_attr) { if ((p_attr->attr_id == ATTR_ID_SERVICE_CLASS_ID_LIST) - && (SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) == DATA_ELE_SEQ_DESC_TYPE)) + && (SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) == DATA_ELE_SEQ_DESC_TYPE)) { for (p_sattr = p_attr->attr_value.v.p_sub_attr; p_sattr; p_sattr = p_sattr->p_next_attr) { @@ -344,7 +344,7 @@ BOOLEAN SDP_FindServiceUUIDInRec(tSDP_DISC_REC *p_rec, tBT_UUID * p_uuid) p_uuid->len = 2; p_uuid->uu.uuid16 = p_sattr->attr_value.v.u16; } - return (TRUE); + return(TRUE); } /* Checking for Toyota G Block Car Kit: @@ -360,12 +360,12 @@ BOOLEAN SDP_FindServiceUUIDInRec(tSDP_DISC_REC *p_rec, tBT_UUID * p_uuid) { /* Increment past this to see if the next attribut is UUID */ if ((SDP_DISC_ATTR_TYPE(p_extra_sattr->attr_len_type) == UUID_DESC_TYPE) - /* only support 16 bits UUID for now */ - && (SDP_DISC_ATTR_LEN(p_extra_sattr->attr_len_type) == 2)) + /* only support 16 bits UUID for now */ + && (SDP_DISC_ATTR_LEN(p_extra_sattr->attr_len_type) == 2)) { p_uuid->len = 2; p_uuid->uu.uuid16 = p_extra_sattr->attr_value.v.u16; - return (TRUE); + return(TRUE); } } } @@ -376,12 +376,12 @@ BOOLEAN SDP_FindServiceUUIDInRec(tSDP_DISC_REC *p_rec, tBT_UUID * p_uuid) else if (p_attr->attr_id == ATTR_ID_SERVICE_ID) { if ((SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) == UUID_DESC_TYPE) - /* only support 16 bits UUID for now */ - && (SDP_DISC_ATTR_LEN(p_attr->attr_len_type) == 2)) + /* only support 16 bits UUID for now */ + && (SDP_DISC_ATTR_LEN(p_attr->attr_len_type) == 2)) { p_uuid->len = 2; p_uuid->uu.uuid16 = p_attr->attr_value.v.u16; - return (TRUE); + return(TRUE); } } p_attr = p_attr->p_next_attr; @@ -413,7 +413,7 @@ BOOLEAN SDP_FindServiceUUIDInRec_128bit(tSDP_DISC_REC *p_rec, tBT_UUID * p_uuid) while (p_attr) { if ((p_attr->attr_id == ATTR_ID_SERVICE_CLASS_ID_LIST) - && (SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) == DATA_ELE_SEQ_DESC_TYPE)) + && (SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) == DATA_ELE_SEQ_DESC_TYPE)) { for (p_sattr = p_attr->attr_value.v.p_sub_attr; p_sattr; p_sattr = p_sattr->p_next_attr) { @@ -425,7 +425,7 @@ BOOLEAN SDP_FindServiceUUIDInRec_128bit(tSDP_DISC_REC *p_rec, tBT_UUID * p_uuid) p_uuid->len = 16; memcpy(p_uuid->uu.uuid128, p_sattr->attr_value.v.array, MAX_UUID_SIZE); } - return (TRUE); + return(TRUE); } } break; @@ -433,12 +433,12 @@ BOOLEAN SDP_FindServiceUUIDInRec_128bit(tSDP_DISC_REC *p_rec, tBT_UUID * p_uuid) else if (p_attr->attr_id == ATTR_ID_SERVICE_ID) { if ((SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) == UUID_DESC_TYPE) - /* only support 128 bits UUID for now */ - && (SDP_DISC_ATTR_LEN(p_attr->attr_len_type) == 16)) + /* only support 128 bits UUID for now */ + && (SDP_DISC_ATTR_LEN(p_attr->attr_len_type) == 16)) { p_uuid->len = 16; memcpy(p_uuid->uu.uuid128, p_sattr->attr_value.v.array, MAX_UUID_SIZE); - return (TRUE); + return(TRUE); } } p_attr = p_attr->p_next_attr; @@ -467,7 +467,7 @@ tSDP_DISC_REC *SDP_FindServiceInDb (tSDP_DISCOVERY_DB *p_db, UINT16 service_uuid /* Must have a valid database */ if (p_db == NULL) - return (NULL); + return(NULL); if (!p_start_rec) p_rec = p_db->p_first_rec; @@ -480,16 +480,31 @@ tSDP_DISC_REC *SDP_FindServiceInDb (tSDP_DISCOVERY_DB *p_db, UINT16 service_uuid while (p_attr) { if ((p_attr->attr_id == ATTR_ID_SERVICE_CLASS_ID_LIST) - && (SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) == DATA_ELE_SEQ_DESC_TYPE)) + && (SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) == DATA_ELE_SEQ_DESC_TYPE)) { for (p_sattr = p_attr->attr_value.v.p_sub_attr; p_sattr; p_sattr = p_sattr->p_next_attr) { + if ((SDP_DISC_ATTR_TYPE(p_sattr->attr_len_type) == UUID_DESC_TYPE) - && (SDP_DISC_ATTR_LEN(p_sattr->attr_len_type) == 2) - /* for a specific uuid, or any one */ - && ((p_sattr->attr_value.v.u16 == service_uuid) || service_uuid == 0)) + && (SDP_DISC_ATTR_LEN(p_sattr->attr_len_type) == 2) ) { + printf("SDP_FindServiceInDb - p_sattr value = 0x%x serviceuuid = 0x%x\r\n", p_sattr->attr_value.v.u16, service_uuid); + if(service_uuid == UUID_SERVCLASS_HDP_PROFILE) + { + if( (p_sattr->attr_value.v.u16==UUID_SERVCLASS_HDP_SOURCE) || ( p_sattr->attr_value.v.u16==UUID_SERVCLASS_HDP_SOURCE)) + { + printf("SDP_FindServiceInDb found HDP source or sink\n" ); + return (p_rec); + } + } + + } + + if ((SDP_DISC_ATTR_TYPE(p_sattr->attr_len_type) == UUID_DESC_TYPE) + && (SDP_DISC_ATTR_LEN(p_sattr->attr_len_type) == 2) + /* for a specific uuid, or any one */ + && ((p_sattr->attr_value.v.u16 == service_uuid) || service_uuid == 0)) { - return (p_rec); + return(p_rec); } /* Checking for Toyota G Block Car Kit: @@ -505,11 +520,11 @@ tSDP_DISC_REC *SDP_FindServiceInDb (tSDP_DISCOVERY_DB *p_db, UINT16 service_uuid { /* Increment past this to see if the next attribut is UUID */ if ((SDP_DISC_ATTR_TYPE(p_extra_sattr->attr_len_type) == UUID_DESC_TYPE) - && (SDP_DISC_ATTR_LEN(p_extra_sattr->attr_len_type) == 2) - /* for a specific uuid, or any one */ - && ((p_extra_sattr->attr_value.v.u16 == service_uuid) || (service_uuid == 0))) + && (SDP_DISC_ATTR_LEN(p_extra_sattr->attr_len_type) == 2) + /* for a specific uuid, or any one */ + && ((p_extra_sattr->attr_value.v.u16 == service_uuid) || (service_uuid == 0))) { - return (p_rec); + return(p_rec); } } } @@ -520,10 +535,16 @@ tSDP_DISC_REC *SDP_FindServiceInDb (tSDP_DISCOVERY_DB *p_db, UINT16 service_uuid else if (p_attr->attr_id == ATTR_ID_SERVICE_ID) { if ((SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) == UUID_DESC_TYPE) - && (SDP_DISC_ATTR_LEN(p_attr->attr_len_type) == 2) - /* find a specific UUID or anyone */ - && ((p_attr->attr_value.v.u16 == service_uuid) || service_uuid == 0)) - return (p_rec); + && (SDP_DISC_ATTR_LEN(p_attr->attr_len_type) == 2)) + { + printf("SDP_FindServiceInDb - p_attr value = 0x%x serviceuuid= 0x%x \r\n", p_attr->attr_value.v.u16, service_uuid); + } + + if ((SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) == UUID_DESC_TYPE) + && (SDP_DISC_ATTR_LEN(p_attr->attr_len_type) == 2) + /* find a specific UUID or anyone */ + && ((p_attr->attr_value.v.u16 == service_uuid) || service_uuid == 0)) + return(p_rec); } p_attr = p_attr->p_next_attr; @@ -533,7 +554,7 @@ tSDP_DISC_REC *SDP_FindServiceInDb (tSDP_DISCOVERY_DB *p_db, UINT16 service_uuid } #endif /* If here, no matching UUID found */ - return (NULL); + return(NULL); } /******************************************************************************* @@ -559,7 +580,7 @@ tSDP_DISC_REC *SDP_FindServiceInDb_128bit(tSDP_DISCOVERY_DB *p_db, tSDP_DISC_REC /* Must have a valid database */ if (p_db == NULL) - return (NULL); + return(NULL); if (!p_start_rec) p_rec = p_db->p_first_rec; @@ -572,14 +593,14 @@ tSDP_DISC_REC *SDP_FindServiceInDb_128bit(tSDP_DISCOVERY_DB *p_db, tSDP_DISC_REC while (p_attr) { if ((p_attr->attr_id == ATTR_ID_SERVICE_CLASS_ID_LIST) - && (SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) == DATA_ELE_SEQ_DESC_TYPE)) + && (SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) == DATA_ELE_SEQ_DESC_TYPE)) { for (p_sattr = p_attr->attr_value.v.p_sub_attr; p_sattr; p_sattr = p_sattr->p_next_attr) { if ((SDP_DISC_ATTR_TYPE(p_sattr->attr_len_type) == UUID_DESC_TYPE) - && (SDP_DISC_ATTR_LEN(p_sattr->attr_len_type) == 16)) + && (SDP_DISC_ATTR_LEN(p_sattr->attr_len_type) == 16)) { - return (p_rec); + return(p_rec); } } break; @@ -587,8 +608,8 @@ tSDP_DISC_REC *SDP_FindServiceInDb_128bit(tSDP_DISCOVERY_DB *p_db, tSDP_DISC_REC else if (p_attr->attr_id == ATTR_ID_SERVICE_ID) { if ((SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) == UUID_DESC_TYPE) - && (SDP_DISC_ATTR_LEN(p_attr->attr_len_type) == 16)) - return (p_rec); + && (SDP_DISC_ATTR_LEN(p_attr->attr_len_type) == 16)) + return(p_rec); } p_attr = p_attr->p_next_attr; @@ -598,7 +619,7 @@ tSDP_DISC_REC *SDP_FindServiceInDb_128bit(tSDP_DISCOVERY_DB *p_db, tSDP_DISC_REC } #endif /* If here, no matching UUID found */ - return (NULL); + return(NULL); } @@ -625,7 +646,7 @@ tSDP_DISC_REC *SDP_FindServiceUUIDInDb (tSDP_DISCOVERY_DB *p_db, tBT_UUID *p_uui /* Must have a valid database */ if (p_db == NULL) - return (NULL); + return(NULL); if (!p_start_rec) p_rec = p_db->p_first_rec; @@ -638,14 +659,25 @@ tSDP_DISC_REC *SDP_FindServiceUUIDInDb (tSDP_DISCOVERY_DB *p_db, tBT_UUID *p_uui while (p_attr) { if ((p_attr->attr_id == ATTR_ID_SERVICE_CLASS_ID_LIST) - && (SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) == DATA_ELE_SEQ_DESC_TYPE)) + && (SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) == DATA_ELE_SEQ_DESC_TYPE)) { for (p_sattr = p_attr->attr_value.v.p_sub_attr; p_sattr; p_sattr = p_sattr->p_next_attr) { if (SDP_DISC_ATTR_TYPE(p_sattr->attr_len_type) == UUID_DESC_TYPE) { + + printf("uuid len=%d ", p_uuid->len); + if (p_uuid->len == 2) + { + printf("uuid=0x%x \n", p_uuid->uu.uuid16); + } + else + { + printf("\n"); + } + if (sdpu_compare_uuid_with_attr (p_uuid, p_sattr)) - return (p_rec); + return(p_rec); } } break; @@ -655,7 +687,7 @@ tSDP_DISC_REC *SDP_FindServiceUUIDInDb (tSDP_DISCOVERY_DB *p_db, tBT_UUID *p_uui if (SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) == UUID_DESC_TYPE ) { if (sdpu_compare_uuid_with_attr (p_uuid, p_attr)) - return (p_rec); + return(p_rec); } } @@ -666,7 +698,7 @@ tSDP_DISC_REC *SDP_FindServiceUUIDInDb (tSDP_DISCOVERY_DB *p_db, tBT_UUID *p_uui } #endif /* CLIENT_ENABLED == TRUE */ /* If here, no matching UUID found */ - return (NULL); + return(NULL); } #if SDP_CLIENT_ENABLED == TRUE @@ -681,7 +713,7 @@ tSDP_DISC_REC *SDP_FindServiceUUIDInDb (tSDP_DISCOVERY_DB *p_db, tBT_UUID *p_uui ** *******************************************************************************/ static BOOLEAN sdp_fill_proto_elem( tSDP_DISC_ATTR *p_attr, UINT16 layer_uuid, - tSDP_PROTOCOL_ELEM *p_elem) + tSDP_PROTOCOL_ELEM *p_elem) { tSDP_DISC_ATTR *p_sattr; @@ -690,7 +722,7 @@ static BOOLEAN sdp_fill_proto_elem( tSDP_DISC_ATTR *p_attr, UINT16 layer_uuid, { /* Safety check - each entry should itself be a sequence */ if (SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) != DATA_ELE_SEQ_DESC_TYPE) - return (FALSE); + return(FALSE); /* Now, see if the entry contains the layer we are interested in */ for (p_sattr = p_attr->attr_value.v.p_sub_attr; p_sattr; p_sattr = p_sattr->p_next_attr) @@ -699,8 +731,8 @@ static BOOLEAN sdp_fill_proto_elem( tSDP_DISC_ATTR *p_attr, UINT16 layer_uuid, p_sattr, layer_uuid, p_sattr->attr_value.v.u16); */ if ((SDP_DISC_ATTR_TYPE(p_sattr->attr_len_type) == UUID_DESC_TYPE) - && (SDP_DISC_ATTR_LEN(p_sattr->attr_len_type) == 2) - && (p_sattr->attr_value.v.u16 == layer_uuid)) + && (SDP_DISC_ATTR_LEN(p_sattr->attr_len_type) == 2) + && (p_sattr->attr_value.v.u16 == layer_uuid)) { /* Bingo. Now fill in the passed element */ p_elem->protocol_uuid = layer_uuid; @@ -720,12 +752,12 @@ static BOOLEAN sdp_fill_proto_elem( tSDP_DISC_ATTR *p_attr, UINT16 layer_uuid, if (p_elem->num_params >= SDP_MAX_PROTOCOL_PARAMS) break; } - return (TRUE); + return(TRUE); } } } - return (FALSE); + return(FALSE); } #endif /* CLIENT_ENABLED == TRUE */ @@ -750,7 +782,7 @@ BOOLEAN SDP_FindProtocolListElemInRec (tSDP_DISC_REC *p_rec, UINT16 layer_uuid, { /* Find the protocol descriptor list */ if ((p_attr->attr_id == ATTR_ID_PROTOCOL_DESC_LIST) - && (SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) == DATA_ELE_SEQ_DESC_TYPE)) + && (SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) == DATA_ELE_SEQ_DESC_TYPE)) { return sdp_fill_proto_elem(p_attr, layer_uuid, p_elem); } @@ -758,7 +790,7 @@ BOOLEAN SDP_FindProtocolListElemInRec (tSDP_DISC_REC *p_rec, UINT16 layer_uuid, } #endif /* If here, no match found */ - return (FALSE); + return(FALSE); } @@ -791,7 +823,7 @@ BOOLEAN SDP_FindAddProtoListsElemInRec (tSDP_DISC_REC *p_rec, UINT16 layer_uuid, /* Safety check - each entry should itself be a sequence */ if (SDP_DISC_ATTR_TYPE(p_sattr->attr_len_type) == DATA_ELE_SEQ_DESC_TYPE) { - if( (ret = sdp_fill_proto_elem(p_sattr, layer_uuid, p_elem)) == TRUE) + if ( (ret = sdp_fill_proto_elem(p_sattr, layer_uuid, p_elem)) == TRUE) break; } } @@ -801,7 +833,7 @@ BOOLEAN SDP_FindAddProtoListsElemInRec (tSDP_DISC_REC *p_rec, UINT16 layer_uuid, } #endif /* If here, no match found */ - return (FALSE); + return(FALSE); } @@ -829,21 +861,21 @@ BOOLEAN SDP_FindProfileVersionInRec (tSDP_DISC_REC *p_rec, UINT16 profile_uuid, { /* Find the profile descriptor list */ if ((p_attr->attr_id == ATTR_ID_BT_PROFILE_DESC_LIST) - && (SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) == DATA_ELE_SEQ_DESC_TYPE)) + && (SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) == DATA_ELE_SEQ_DESC_TYPE)) { /* Walk through the protocol descriptor list */ for (p_attr = p_attr->attr_value.v.p_sub_attr; p_attr; p_attr = p_attr->p_next_attr) { /* Safety check - each entry should itself be a sequence */ if (SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) != DATA_ELE_SEQ_DESC_TYPE) - return (FALSE); + return(FALSE); /* Now, see if the entry contains the profile UUID we are interested in */ for (p_sattr = p_attr->attr_value.v.p_sub_attr; p_sattr; p_sattr = p_sattr->p_next_attr) { if ((SDP_DISC_ATTR_TYPE(p_sattr->attr_len_type) == UUID_DESC_TYPE) - && (SDP_DISC_ATTR_LEN(p_sattr->attr_len_type) == 2) /* <- This is bytes, not size code! */ - && (p_sattr->attr_value.v.u16 == profile_uuid)) + && (SDP_DISC_ATTR_LEN(p_sattr->attr_len_type) == 2) /* <- This is bytes, not size code! */ + && (p_sattr->attr_value.v.u16 == profile_uuid)) { /* Now fill in the major and minor numbers */ /* if the attribute matches the description for version (type UINT, size 2 bytes) */ @@ -855,22 +887,22 @@ BOOLEAN SDP_FindProfileVersionInRec (tSDP_DISC_REC *p_rec, UINT16 profile_uuid, /* The high order 8 bits is the major number, low order is the minor number (big endian) */ *p_version = p_sattr->attr_value.v.u16; - return (TRUE); + return(TRUE); } else - return (FALSE); /* The type and/or size was not valid for the profile list version */ + return(FALSE); /* The type and/or size was not valid for the profile list version */ } } } - return (FALSE); + return(FALSE); } p_attr = p_attr->p_next_attr; } #endif /* CLIENT_ENABLED == TRUE */ /* If here, no match found */ - return (FALSE); + return(FALSE); } /******************************************************************************* @@ -899,8 +931,8 @@ UINT16 SDP_DiDiscover( BD_ADDR remote_device, tSDP_DISCOVERY_DB *p_db, init_uuid.len = 2; init_uuid.uu.uuid16 = di_uuid; - if( SDP_InitDiscoveryDb(p_db, len, num_uuids, &init_uuid, 0, NULL) ) - if( SDP_ServiceSearchRequest(remote_device, p_db, p_cb) ) + if ( SDP_InitDiscoveryDb(p_db, len, num_uuids, &init_uuid, 0, NULL) ) + if ( SDP_ServiceSearchRequest(remote_device, p_db, p_cb) ) result = SDP_SUCCESS; return result; @@ -928,9 +960,9 @@ UINT8 SDP_GetNumDiRecords( tSDP_DISCOVERY_DB *p_db ) { p_curr_record = SDP_FindServiceInDb( p_db, UUID_SERVCLASS_PNP_INFORMATION, p_curr_record ); - if( p_curr_record ) + if ( p_curr_record ) num_records++; - }while( p_curr_record ); + }while ( p_curr_record ); return num_records; #else @@ -962,77 +994,77 @@ UINT16 SDP_GetDiRecord( UINT8 get_record_index, tSDP_DI_GET_RECORD *p_device_inf { p_curr_record = SDP_FindServiceInDb( p_db, UUID_SERVCLASS_PNP_INFORMATION, p_curr_record ); - if( p_curr_record ) + if ( p_curr_record ) { - if( curr_record_index++ == get_record_index ) + if ( curr_record_index++ == get_record_index ) { result = SDP_SUCCESS; break; } } - }while( p_curr_record ); + }while ( p_curr_record ); - if( result == SDP_SUCCESS ) + if ( result == SDP_SUCCESS ) { /* copy the information from the SDP record to the DI record */ tSDP_DISC_ATTR *p_curr_attr = NULL; /* ClientExecutableURL is optional */ p_curr_attr = SDP_FindAttributeInRec( p_curr_record, ATTR_ID_CLIENT_EXE_URL ); - if( p_curr_attr ) + if ( p_curr_attr ) BCM_STRNCPY_S( p_device_info->rec.client_executable_url, sizeof(p_device_info->rec.client_executable_url), - (char *)p_curr_attr->attr_value.v.array, SDP_MAX_ATTR_LEN ); + (char *)p_curr_attr->attr_value.v.array, SDP_MAX_ATTR_LEN ); else p_device_info->rec.client_executable_url[0] = '\0'; /* Service Description is optional */ p_curr_attr = SDP_FindAttributeInRec( p_curr_record, ATTR_ID_SERVICE_DESCRIPTION ); - if( p_curr_attr ) + if ( p_curr_attr ) BCM_STRNCPY_S( p_device_info->rec.service_description, sizeof(p_device_info->rec.service_description), - (char *)p_curr_attr->attr_value.v.array, SDP_MAX_ATTR_LEN ); + (char *)p_curr_attr->attr_value.v.array, SDP_MAX_ATTR_LEN ); else p_device_info->rec.service_description[0] = '\0'; /* DocumentationURL is optional */ p_curr_attr = SDP_FindAttributeInRec( p_curr_record, ATTR_ID_DOCUMENTATION_URL ); - if( p_curr_attr ) + if ( p_curr_attr ) BCM_STRNCPY_S( p_device_info->rec.documentation_url, sizeof(p_device_info->rec.documentation_url), - (char *)p_curr_attr->attr_value.v.array, SDP_MAX_ATTR_LEN ); + (char *)p_curr_attr->attr_value.v.array, SDP_MAX_ATTR_LEN ); else p_device_info->rec.documentation_url[0] = '\0'; p_curr_attr = SDP_FindAttributeInRec( p_curr_record, ATTR_ID_SPECIFICATION_ID ); - if( p_curr_attr ) + if ( p_curr_attr ) p_device_info->spec_id = p_curr_attr->attr_value.v.u16; else result = SDP_ERR_ATTR_NOT_PRESENT; p_curr_attr = SDP_FindAttributeInRec( p_curr_record, ATTR_ID_VENDOR_ID ); - if( p_curr_attr ) + if ( p_curr_attr ) p_device_info->rec.vendor = p_curr_attr->attr_value.v.u16; else result = SDP_ERR_ATTR_NOT_PRESENT; p_curr_attr = SDP_FindAttributeInRec( p_curr_record, ATTR_ID_VENDOR_ID_SOURCE ); - if( p_curr_attr ) + if ( p_curr_attr ) p_device_info->rec.vendor_id_source = p_curr_attr->attr_value.v.u16; else result = SDP_ERR_ATTR_NOT_PRESENT; p_curr_attr = SDP_FindAttributeInRec( p_curr_record, ATTR_ID_PRODUCT_ID ); - if( p_curr_attr ) + if ( p_curr_attr ) p_device_info->rec.product = p_curr_attr->attr_value.v.u16; else result = SDP_ERR_ATTR_NOT_PRESENT; p_curr_attr = SDP_FindAttributeInRec( p_curr_record, ATTR_ID_PRODUCT_VERSION ); - if( p_curr_attr ) + if ( p_curr_attr ) p_device_info->rec.version = p_curr_attr->attr_value.v.u16; else result = SDP_ERR_ATTR_NOT_PRESENT; p_curr_attr = SDP_FindAttributeInRec( p_curr_record, ATTR_ID_PRIMARY_RECORD ); - if( p_curr_attr ) + if ( p_curr_attr ) p_device_info->rec.primary_record = (BOOLEAN)p_curr_attr->attr_value.v.u8; else result = SDP_ERR_ATTR_NOT_PRESENT; @@ -1071,15 +1103,15 @@ UINT16 SDP_SetLocalDiRecord( tSDP_DI_RECORD *p_device_info, UINT32 *p_handle ) UINT8 u8; *p_handle = 0; - if( p_device_info == NULL ) + if ( p_device_info == NULL ) return SDP_ILLEGAL_PARAMETER; /* if record is to be primary record, get handle to replace old primary */ - if( p_device_info->primary_record == TRUE && sdp_cb.server_db.di_primary_handle ) + if ( p_device_info->primary_record == TRUE && sdp_cb.server_db.di_primary_handle ) handle = sdp_cb.server_db.di_primary_handle; else { - if( (handle = SDP_CreateRecord()) == 0 ) + if ( (handle = SDP_CreateRecord()) == 0 ) return SDP_NO_RESOURCES; } @@ -1095,48 +1127,48 @@ UINT16 SDP_SetLocalDiRecord( tSDP_DI_RECORD *p_device_info, UINT32 *p_handle ) { p_temp = temp_u16; UINT16_TO_BE_STREAM(p_temp, di_specid); - if( !(SDP_AddAttribute(handle, ATTR_ID_SPECIFICATION_ID, - UINT_DESC_TYPE, sizeof(di_specid), - temp_u16)) ) + if ( !(SDP_AddAttribute(handle, ATTR_ID_SPECIFICATION_ID, + UINT_DESC_TYPE, sizeof(di_specid), + temp_u16)) ) result = SDP_DI_REG_FAILED; } /* optional - if string is null, do not add attribute */ - if( result == SDP_SUCCESS ) + if ( result == SDP_SUCCESS ) { - if( p_device_info->client_executable_url[0] != '\0' ) + if ( p_device_info->client_executable_url[0] != '\0' ) { - if( !((strlen(p_device_info->client_executable_url)+1 <= SDP_MAX_ATTR_LEN) && - SDP_AddAttribute(handle, ATTR_ID_CLIENT_EXE_URL, URL_DESC_TYPE, - (UINT32)(strlen(p_device_info->client_executable_url)+1), - (UINT8 *)p_device_info->client_executable_url)) ) + if ( !((strlen(p_device_info->client_executable_url)+1 <= SDP_MAX_ATTR_LEN) && + SDP_AddAttribute(handle, ATTR_ID_CLIENT_EXE_URL, URL_DESC_TYPE, + (UINT32)(strlen(p_device_info->client_executable_url)+1), + (UINT8 *)p_device_info->client_executable_url)) ) result = SDP_DI_REG_FAILED; } } /* optional - if string is null, do not add attribute */ - if( result == SDP_SUCCESS ) + if ( result == SDP_SUCCESS ) { - if( p_device_info->service_description[0] != '\0' ) + if ( p_device_info->service_description[0] != '\0' ) { if ( !((strlen(p_device_info->service_description)+1 <= SDP_MAX_ATTR_LEN) && - SDP_AddAttribute(handle, ATTR_ID_SERVICE_DESCRIPTION, - TEXT_STR_DESC_TYPE, - (UINT32)(strlen(p_device_info->service_description)+1), - (UINT8 *)p_device_info->service_description)) ) + SDP_AddAttribute(handle, ATTR_ID_SERVICE_DESCRIPTION, + TEXT_STR_DESC_TYPE, + (UINT32)(strlen(p_device_info->service_description)+1), + (UINT8 *)p_device_info->service_description)) ) result = SDP_DI_REG_FAILED; } } /* optional - if string is null, do not add attribute */ - if( result == SDP_SUCCESS ) + if ( result == SDP_SUCCESS ) { - if( p_device_info->documentation_url[0] != '\0' ) + if ( p_device_info->documentation_url[0] != '\0' ) { - if( !((strlen(p_device_info->documentation_url)+1 <= SDP_MAX_ATTR_LEN) && - SDP_AddAttribute(handle, ATTR_ID_DOCUMENTATION_URL, URL_DESC_TYPE, - (UINT32)(strlen(p_device_info->documentation_url)+1), - (UINT8 *)p_device_info->documentation_url)) ) + if ( !((strlen(p_device_info->documentation_url)+1 <= SDP_MAX_ATTR_LEN) && + SDP_AddAttribute(handle, ATTR_ID_DOCUMENTATION_URL, URL_DESC_TYPE, + (UINT32)(strlen(p_device_info->documentation_url)+1), + (UINT8 *)p_device_info->documentation_url)) ) result = SDP_DI_REG_FAILED; } } @@ -1156,8 +1188,8 @@ UINT16 SDP_SetLocalDiRecord( tSDP_DI_RECORD *p_device_info, UINT32 *p_handle ) { p_temp = temp_u16; UINT16_TO_BE_STREAM (p_temp, p_device_info->product); - if( !(SDP_AddAttribute(handle, ATTR_ID_PRODUCT_ID, - UINT_DESC_TYPE, sizeof(p_device_info->product), temp_u16)) ) + if ( !(SDP_AddAttribute(handle, ATTR_ID_PRODUCT_ID, + UINT_DESC_TYPE, sizeof(p_device_info->product), temp_u16)) ) result = SDP_DI_REG_FAILED; } @@ -1166,8 +1198,8 @@ UINT16 SDP_SetLocalDiRecord( tSDP_DI_RECORD *p_device_info, UINT32 *p_handle ) { p_temp = temp_u16; UINT16_TO_BE_STREAM (p_temp, p_device_info->version); - if( !(SDP_AddAttribute(handle, ATTR_ID_PRODUCT_VERSION, UINT_DESC_TYPE, - sizeof(p_device_info->version), temp_u16)) ) + if ( !(SDP_AddAttribute(handle, ATTR_ID_PRODUCT_VERSION, UINT_DESC_TYPE, + sizeof(p_device_info->version), temp_u16)) ) result = SDP_DI_REG_FAILED; } @@ -1175,8 +1207,8 @@ UINT16 SDP_SetLocalDiRecord( tSDP_DI_RECORD *p_device_info, UINT32 *p_handle ) if ( result == SDP_SUCCESS) { u8 = (UINT8)p_device_info->primary_record; - if( !(SDP_AddAttribute(handle, ATTR_ID_PRIMARY_RECORD, - BOOLEAN_DESC_TYPE, 1, &u8)) ) + if ( !(SDP_AddAttribute(handle, ATTR_ID_PRIMARY_RECORD, + BOOLEAN_DESC_TYPE, 1, &u8)) ) result = SDP_DI_REG_FAILED; } @@ -1190,7 +1222,7 @@ UINT16 SDP_SetLocalDiRecord( tSDP_DI_RECORD *p_device_info, UINT32 *p_handle ) result = SDP_DI_REG_FAILED; } - if( result != SDP_SUCCESS ) + if ( result != SDP_SUCCESS ) SDP_DeleteRecord( handle ); else if (p_device_info->primary_record == TRUE) sdp_cb.server_db.di_primary_handle = handle; @@ -1234,7 +1266,7 @@ UINT16 SDP_GetLocalDiRecord(tSDP_DI_GET_RECORD *p_device_info, UINT32 *p_handle /* Retrieve the Specification ID */ if ((p_attr = sdp_db_find_attr_in_rec(p_rec, ATTR_ID_SPECIFICATION_ID, - ATTR_ID_SPECIFICATION_ID)) != NULL) + ATTR_ID_SPECIFICATION_ID)) != NULL) { p_temp = p_attr->value_ptr; BE_STREAM_TO_UINT16 (p_device_info->spec_id, p_temp); @@ -1242,7 +1274,7 @@ UINT16 SDP_GetLocalDiRecord(tSDP_DI_GET_RECORD *p_device_info, UINT32 *p_handle /* Retrieve the Vendor ID */ if ((p_attr = sdp_db_find_attr_in_rec(p_rec, ATTR_ID_VENDOR_ID, - ATTR_ID_VENDOR_ID)) != NULL) + ATTR_ID_VENDOR_ID)) != NULL) { p_temp = p_attr->value_ptr; BE_STREAM_TO_UINT16 (p_device_info->rec.vendor, p_temp); @@ -1250,7 +1282,7 @@ UINT16 SDP_GetLocalDiRecord(tSDP_DI_GET_RECORD *p_device_info, UINT32 *p_handle /* Retrieve the Product ID */ if ((p_attr = sdp_db_find_attr_in_rec(p_rec, ATTR_ID_PRODUCT_ID, - ATTR_ID_PRODUCT_ID)) != NULL) + ATTR_ID_PRODUCT_ID)) != NULL) { p_temp = p_attr->value_ptr; BE_STREAM_TO_UINT16 (p_device_info->rec.product, p_temp); @@ -1258,7 +1290,7 @@ UINT16 SDP_GetLocalDiRecord(tSDP_DI_GET_RECORD *p_device_info, UINT32 *p_handle /* Retrieve the Version ID */ if ((p_attr = sdp_db_find_attr_in_rec(p_rec, ATTR_ID_PRODUCT_VERSION, - ATTR_ID_PRODUCT_VERSION)) != NULL) + ATTR_ID_PRODUCT_VERSION)) != NULL) { p_temp = p_attr->value_ptr; BE_STREAM_TO_UINT16 (p_device_info->rec.version, p_temp); @@ -1266,7 +1298,7 @@ UINT16 SDP_GetLocalDiRecord(tSDP_DI_GET_RECORD *p_device_info, UINT32 *p_handle /* Retrieve the Vendor ID Source ID */ if ((p_attr = sdp_db_find_attr_in_rec(p_rec, ATTR_ID_VENDOR_ID_SOURCE, - ATTR_ID_VENDOR_ID_SOURCE)) != NULL) + ATTR_ID_VENDOR_ID_SOURCE)) != NULL) { p_temp = p_attr->value_ptr; BE_STREAM_TO_UINT16 (p_device_info->rec.vendor_id_source, p_temp); @@ -1274,14 +1306,14 @@ UINT16 SDP_GetLocalDiRecord(tSDP_DI_GET_RECORD *p_device_info, UINT32 *p_handle /* Retrieve the Primary Record */ if ((p_attr = sdp_db_find_attr_in_rec(p_rec, ATTR_ID_PRIMARY_RECORD, - ATTR_ID_PRIMARY_RECORD)) != NULL) + ATTR_ID_PRIMARY_RECORD)) != NULL) { p_device_info->rec.primary_record = *p_attr->value_ptr; } /* Retrieve the Client Executable URL */ if ((p_attr = sdp_db_find_attr_in_rec(p_rec, ATTR_ID_CLIENT_EXE_URL, - ATTR_ID_CLIENT_EXE_URL)) != NULL) + ATTR_ID_CLIENT_EXE_URL)) != NULL) { templen = (INT32)((p_attr->len < SDP_MAX_ATTR_LEN) ? p_attr->len : SDP_MAX_ATTR_LEN); p_temp = p_attr->value_ptr; @@ -1290,7 +1322,7 @@ UINT16 SDP_GetLocalDiRecord(tSDP_DI_GET_RECORD *p_device_info, UINT32 *p_handle /* Retrieve the Service Description */ if ((p_attr = sdp_db_find_attr_in_rec(p_rec, ATTR_ID_SERVICE_DESCRIPTION, - ATTR_ID_SERVICE_DESCRIPTION)) != NULL) + ATTR_ID_SERVICE_DESCRIPTION)) != NULL) { templen = (INT32)((p_attr->len < SDP_MAX_ATTR_LEN) ? p_attr->len : SDP_MAX_ATTR_LEN); p_temp = p_attr->value_ptr; @@ -1299,7 +1331,7 @@ UINT16 SDP_GetLocalDiRecord(tSDP_DI_GET_RECORD *p_device_info, UINT32 *p_handle /* Retrieve the Documentation URL */ if ((p_attr = sdp_db_find_attr_in_rec(p_rec, ATTR_ID_DOCUMENTATION_URL, - ATTR_ID_DOCUMENTATION_URL)) != NULL) + ATTR_ID_DOCUMENTATION_URL)) != NULL) { templen = (INT32)((p_attr->len < SDP_MAX_ATTR_LEN) ? p_attr->len : SDP_MAX_ATTR_LEN); p_temp = p_attr->value_ptr; @@ -1329,7 +1361,7 @@ UINT8 SDP_SetTraceLevel (UINT8 new_level) if (new_level != 0xFF) sdp_cb.trace_level = new_level; - return (sdp_cb.trace_level); + return(sdp_cb.trace_level); } #if SDP_FOR_JV_INCLUDED == TRUE @@ -1344,20 +1376,20 @@ UINT8 SDP_SetTraceLevel (UINT8 new_level) ** *******************************************************************************/ UINT32 SDP_ConnOpen (UINT8 *p_bd_addr, tSDP_DISC_RES_CB *p_rcb, - tSDP_DISC_CMPL_CB *p_cb) + tSDP_DISC_CMPL_CB *p_cb) { #if SDP_CLIENT_ENABLED == TRUE tCONN_CB *p_ccb; UINT32 idx = 0; if (!p_cb || !p_rcb) - return (idx); + return(idx); /* Specific BD address */ p_ccb = sdp_conn_originate (p_bd_addr); if (!p_ccb) - return (idx); + return(idx); p_ccb->disc_state = SDP_DISC_WAIT_CONN; p_ccb->p_db = (tSDP_DISCOVERY_DB *)p_rcb; @@ -1366,9 +1398,9 @@ UINT32 SDP_ConnOpen (UINT8 *p_bd_addr, tSDP_DISC_RES_CB *p_rcb, p_ccb->is_attr_search = SDP_IS_PASS_THRU; idx = (UINT32)(p_ccb - sdp_cb.ccb); - return (UINT32)(idx + 1); + return(UINT32)(idx + 1); #else - return (0); + return(0); #endif } @@ -1386,11 +1418,11 @@ BOOLEAN SDP_WriteData (UINT32 handle, BT_HDR *p_msg) #if SDP_CLIENT_ENABLED == TRUE tCONN_CB *p_ccb = NULL; - if(p_msg && (handle > 0) && (handle <= SDP_MAX_CONNECTIONS) ) + if (p_msg && (handle > 0) && (handle <= SDP_MAX_CONNECTIONS) ) { p_ccb = &sdp_cb.ccb[handle - 1]; - if( (p_ccb->con_state == SDP_STATE_CONNECTED) && - (p_ccb->con_flags & SDP_FLAGS_IS_ORIG) ) + if ( (p_ccb->con_state == SDP_STATE_CONNECTED) && + (p_ccb->con_flags & SDP_FLAGS_IS_ORIG) ) { /* Start inactivity timer */ btu_start_timer (&p_ccb->timer_entry, BTU_TTYPE_SDP, SDP_INACT_TIMEOUT); @@ -1418,7 +1450,7 @@ BOOLEAN SDP_ConnClose (UINT32 handle) #if SDP_CLIENT_ENABLED == TRUE tCONN_CB *p_ccb = NULL; - if(handle > 0 && handle <= SDP_MAX_CONNECTIONS) + if (handle > 0 && handle <= SDP_MAX_CONNECTIONS) { p_ccb = &sdp_cb.ccb[handle - 1]; sdp_disconnect (p_ccb, SDP_SUCCESS); diff --git a/udrv/include/unv.h b/udrv/include/unv.h index 87983da..ea1d817 100644..100755 --- a/udrv/include/unv.h +++ b/udrv/include/unv.h @@ -199,7 +199,66 @@ int unv_write_key( const char *path, int unv_remove_key( const char *path, const char *key ); - +/******************************************************************************* +** +** Function unv_read_hl_apps_cb +** +** Description read HL applciation contorl block +** +** Parameters +** path : path of file +** value : pointer to value +** value_size : size of value +** +** Returns 0 if successful, -1 if failure +** +******************************************************************************/ +int unv_read_hl_apps_cb(const char *path, char *value, int value_size); +/******************************************************************************* +** +** Function unv_write_hl_apps_cb +** +** Description write HL applciation contorl block +** +** Parameters +** path : path of file +** value : pointer to value +** value_size : size of value +** +** Returns 0 if successful, -1 if failure +** +******************************************************************************/ +int unv_write_hl_apps_cb(const char *path, char *value, int value_size); +/******************************************************************************* +** +** Function unv_read_hl_data +** +** Description read HL applciation data +** +** Parameters +** path : path of file +** value : pointer to value +** value_size : size of value +** +** Returns 0 if successful, -1 if failure +** +******************************************************************************/ +int unv_read_hl_data(const char *path, char *value, int value_size); +/******************************************************************************* +** +** Function unv_write_hl_data +** +** Description write HL applciation data +** +** Parameters +** path : path of file +** value : pointer to value +** value_size : size of value +** +** Returns 0 if successful, -1 if failure +** +******************************************************************************/ +int unv_write_hl_data(const char *path, char *value, int value_size); #endif /* UNV_H */ diff --git a/udrv/ulinux/unv_linux.c b/udrv/ulinux/unv_linux.c index 3e98693..2f58265 100644..100755 --- a/udrv/ulinux/unv_linux.c +++ b/udrv/ulinux/unv_linux.c @@ -193,7 +193,8 @@ static int rm_dir(const char *path) status = rmdir(path); - if (status < 0) { + if (status < 0) + { error("rmdir %s failed (%s)", path, strerror(errno)); return -1; } @@ -600,9 +601,10 @@ char* unv_read_key( const char *path, fd = open(path, O_RDONLY, FILE_MODE); - if (fd < 0) { - error("file failed to open %s (%s)", path, strerror(errno)); - return NULL; + if (fd < 0) + { + error("file failed to open %s (%s)", path, strerror(errno)); + return NULL; } p_search = get_keyval(fd, key, p_out, out_len, NULL, NULL); @@ -646,21 +648,22 @@ int unv_read_key_iter( const char *path, fd = open(path, O_RDONLY, FILE_MODE); - if (fd < 0) { - error("file failed to open %s (%s)", path, strerror(errno)); - return -1; + if (fd < 0) + { + error("file failed to open %s (%s)", path, strerror(errno)); + return -1; } if (fstat(fd, &st) != 0) { - error("stat failed (%s)", strerror(errno)); - return -1; + error("stat failed (%s)", strerror(errno)); + return -1; } p_buf = malloc(st.st_size + 1); if (!p_buf) - return -1; + return -1; p = p_buf; @@ -739,8 +742,8 @@ int unv_write_key( const char *path, if (fd < 0) { - error("file failed to create %s (%s)", path, strerror(errno)); - return -1; + error("file failed to create %s (%s)", path, strerror(errno)); + return -1; } /* check if key already present */ @@ -799,9 +802,10 @@ int unv_remove_key( const char *path, fd = open(path, O_RDWR, FILE_MODE); - if (fd < 0) { - error("file failed to open %s (%s)", path, strerror(errno)); - return -1; + if (fd < 0) + { + error("file failed to open %s (%s)", path, strerror(errno)); + return -1; } p_search = get_keyval(fd, key, p_line, UNV_MAXLINE_LENGTH, &pos_begin, &pos_stop); @@ -812,7 +816,235 @@ int unv_remove_key( const char *path, update_key(fd, key, NULL, pos_begin, pos_stop); } - return (p_search ? 0 : -1); + return(p_search ? 0 : -1); +} + + +/******************************************************************************* +** +** Function unv_read_hl_apps_cb +** +** Description read HL applciation contorl block +** +** Parameters +** path : path of file +** value : pointer to value +** value_size : size of value +** +** Returns 0 if successful, -1 if failure +** +******************************************************************************/ + +int unv_read_hl_apps_cb(const char *path, char *value, int value_size) +{ + struct stat st; + int fd, len, i, data_size; + int status = 0; + + debug("unv_read_hl_apps_cb path=%s value_size=%d ", path, value_size); + + if (check_caller_context() == 0) + { + return -1; + } + + if (stat(path, &st) != 0) + { + debug("%s does not exist open a file to write", path); + fd = open(path, O_WRONLY|O_CREAT, FILE_MODE); + if (fd < 0) + { + error("file failed to open %s (%s)", path, strerror(errno)); + return -1; + } + data_size = value_size >> 1; + for (i = 0; i < data_size; i++) + sprintf(value + (i * 2), "%2.2X", 0); + len = write(fd, value, value_size); + if (len < value_size) + { + error("write failed len=%d < value_size=%d", len, value_size); + status = -1; + } + else + { + debug("write OK len=%d value size=%d", len, value_size); + } + close(fd); + } + else + { + fd = open(path, O_RDONLY, FILE_MODE); + if (fd < 0) + { + error("file failed to open %s (%s)", path, strerror(errno)); + return -1; + } + len = read(fd, value, value_size); + if (len < value_size) + { + error("read failed len=%d < value_size=%d", len, value_size); + status = -1; + } + else + { + debug("read OK len=%d value size=%d", len, value_size); + } + close(fd); + } + + + return status; +} + +/******************************************************************************* +** +** Function unv_write_hl_apps_cb +** +** Description write HL applciation contorl block +** +** Parameters +** path : path of file +** value : pointer to value +** value_size : size of value +** +** Returns 0 if successful, -1 if failure +** +******************************************************************************/ +int unv_write_hl_apps_cb(const char *path, char *value, int value_size) +{ + struct stat st; + int fd, len; + int status = 0; + + debug("unv_write_hl_apps_cb %s value_size=%d ", path, value_size); + + if (check_caller_context() == 0) + { + return -1; + } + + fd = open(path, O_WRONLY|O_CREAT, FILE_MODE); + if (fd < 0) + { + error("file failed to open %s (%s)", path, strerror(errno)); + return -1; + } + len = write(fd, value, value_size); + if (len < value_size) + { + error("write failed len=%d < value_size=%d", len, value_size); + status = -1; + } + else + { + debug("write OK len=%d value size=%d", len, value_size); + } + close(fd); + + return status; } +/******************************************************************************* +** +** Function unv_read_hl_data +** +** Description read HL applciation data +** +** Parameters +** path : path of file +** value : pointer to value +** value_size : size of value +** +** Returns 0 if successful, -1 if failure +** +******************************************************************************/ +int unv_read_hl_data(const char *path, char *value, int value_size) +{ + struct stat st; + int fd, len; + int status = 0; + debug("unv_read_hl_data %s value_size=%d ", path, value_size); + if (check_caller_context() == 0) + { + return -1; + } + + if (stat(path, &st) != 0) + { + debug("%s does not exist", path); + status = -1;; + } + else + { + fd = open(path, O_RDONLY, FILE_MODE); + if (fd < 0) + { + error("file failed to open %s (%s)", path, strerror(errno)); + status = -1; + } + else + { + len = read(fd, value, value_size); + if (len < value_size) + { + error("read failed len=%d < value_size=%d", len, value_size); + status = -1; + } + debug("read OK len=%d value size=%d", len, value_size); + close(fd); + } + } + + + return status; +} + +/******************************************************************************* +** +** Function unv_write_hl_data +** +** Description write HL applciation data +** +** Parameters +** path : path of file +** value : pointer to value +** value_size : size of value +** +** Returns 0 if successful, -1 if failure +** +******************************************************************************/ +int unv_write_hl_data(const char *path, char *value, int value_size) +{ + struct stat st; + int fd, len; + int status = 0; + + debug("unv_write_hl_data %s value_size=%d ", path, value_size); + + if (check_caller_context() == 0) + { + return -1; + } + + debug("%s exist", path); + fd = open(path, O_WRONLY|O_CREAT, FILE_MODE); + if (fd < 0) + { + error("file failed to open %s (%s)", path, strerror(errno)); + status = -1; + } + else + { + len = write(fd, value, value_size); + if (len < value_size) + { + error("write failed len=%d < value_size=%d", len, value_size); + status = -1; + } + debug("write OK len=%d value size=%d", len, value_size); + close(fd); + } + return status; +} |