diff options
author | Priti Aghera <paghera@broadcom.com> | 2012-04-06 14:43:25 -0700 |
---|---|---|
committer | Matthew Xie <mattx@google.com> | 2012-07-14 11:19:15 -0700 |
commit | b110b5ff2dc873c23a2a61e49b189a404d148c50 (patch) | |
tree | f9312ff337a01716b0e8acc212204585834ba6c5 /btif | |
parent | 5883f2fb3fff54e3d308e64108b634eb85e43c62 (diff) | |
download | external_bluetooth_bluedroid-b110b5ff2dc873c23a2a61e49b189a404d148c50.zip external_bluetooth_bluedroid-b110b5ff2dc873c23a2a61e49b189a404d148c50.tar.gz external_bluetooth_bluedroid-b110b5ff2dc873c23a2a61e49b189a404d148c50.tar.bz2 |
HID-HOST:Fixed MAX_LINE_LENGTH
Patch to i) store/load/remove hid descriptors for bonded hid devices to the nvram ii)support set report
Change-Id: I47fae85b0f26ec2c4e577550545dc9761a4d1bda
Diffstat (limited to 'btif')
-rwxr-xr-x[-rw-r--r--] | btif/include/btif_storage.h | 3 | ||||
-rwxr-xr-x[-rw-r--r--] | btif/include/btif_util.h | 1 | ||||
-rwxr-xr-x[-rw-r--r--] | btif/src/btif_hh.c | 148 | ||||
-rwxr-xr-x | btif/src/btif_storage.c | 103 | ||||
-rwxr-xr-x | btif/src/btif_util.c | 42 |
5 files changed, 242 insertions, 55 deletions
diff --git a/btif/include/btif_storage.h b/btif/include/btif_storage.h index 00121e9..6aaa10f 100644..100755 --- a/btif/include/btif_storage.h +++ b/btif/include/btif_storage.h @@ -215,6 +215,9 @@ bt_status_t btif_storage_add_hid_device_info(bt_bdaddr_t *remote_bd_addr, *******************************************************************************/ bt_status_t btif_storage_load_bonded_hid_info(void); +bt_status_t btif_storage_remove_hid_info(bt_bdaddr_t *remote_bd_addr); + + #endif /* BTIF_STORAGE_H */ diff --git a/btif/include/btif_util.h b/btif/include/btif_util.h index 05b7e76..a15d1ca 100644..100755 --- a/btif/include/btif_util.h +++ b/btif/include/btif_util.h @@ -106,6 +106,7 @@ void uuid16_to_uuid128(uint16_t uuid16, bt_uuid_t* uuid128); void uuid_to_string(bt_uuid_t *p_uuid, char *str); void string_to_uuid(char *str, bt_uuid_t *p_uuid); +int ascii_2_hex (char *p_ascii, int len, UINT8 *p_hex); #endif /* BTIF_UTIL_H */ diff --git a/btif/src/btif_hh.c b/btif/src/btif_hh.c index 4046964..01061a1 100644..100755 --- a/btif/src/btif_hh.c +++ b/btif/src/btif_hh.c @@ -138,6 +138,7 @@ typedef enum ** Static variables ************************************************************************************/ btif_hh_cb_t btif_hh_cb; + static bthh_callbacks_t *bt_hh_callbacks = NULL; #define CHECK_BTHH_INIT() if (bt_hh_callbacks == NULL)\ @@ -322,7 +323,7 @@ void btif_hh_remove_device(bt_bdaddr_t bd_addr) p_added_dev = &btif_hh_cb.added_devices[i]; if (memcmp(&(p_added_dev->bd_addr),&bd_addr, 6) == 0) { BTA_HhRemoveDev(p_added_dev->dev_handle); - + btif_storage_remove_hid_info(&(p_added_dev->bd_addr)); memset(&(p_added_dev->bd_addr), 0, 6); p_added_dev->dev_handle = BTA_HH_INVALID_HANDLE; break; @@ -489,8 +490,8 @@ static void btif_hh_upstreams_evt(UINT16 event, char* p_param) if (p_data->status == BTA_HH_OK) { btif_hh_cb.status = BTIF_HH_ENABLED; BTIF_TRACE_DEBUG1("%s--Loading added devices",__FUNCTION__); - //TODO: - //btif_storage_load_bonded_hid_info(); + /* Add hid descriptors for already bonded hid devices*/ + btif_storage_load_bonded_hid_info(); } else { btif_hh_cb.status = BTIF_HH_DISABLED; @@ -500,9 +501,16 @@ static void btif_hh_upstreams_evt(UINT16 event, char* p_param) case BTA_HH_DISABLE_EVT: btif_hh_cb.status = BTIF_HH_DISABLED; - if (p_data->status != BTA_HH_OK) { - BTIF_TRACE_WARNING1("BTA_HH_DISABLE_EVT: Error, HH disabling failed, status = %d", p_data->status); + if (p_data->status == BTA_HH_OK) { + int i; + //Clear the control block + memset(&btif_hh_cb, 0, sizeof(btif_hh_cb)); + for (i = 0; i < BTIF_HH_MAX_HID; i++){ + btif_hh_cb.devices[i].dev_status = BTHH_CONN_STATE_UNKNOWN; + } } + else + BTIF_TRACE_WARNING1("BTA_HH_DISABLE_EVT: Error, HH disabling failed, status = %d", p_data->status); break; case BTA_HH_OPEN_EVT: @@ -563,11 +571,14 @@ static void btif_hh_upstreams_evt(UINT16 event, char* p_param) case BTA_HH_GET_RPT_EVT: BTIF_TRACE_DEBUG2("BTA_HH_GET_RPT_EVT: status = %d, handle = %d", p_data->hs_data.status, p_data->hs_data.handle); + p_dev = btif_hh_find_connected_dev_by_handle(p_data->conn.handle); + HAL_CBACK(bt_hh_callbacks, get_report_cb,(bt_bdaddr_t*) &(p_dev->bd_addr), (bthh_status_t) p_data->hs_data.status, + (uint8_t*) p_data->hs_data.rsp_data.p_rpt_data, BT_HDR_SIZE); break; case BTA_HH_SET_RPT_EVT: BTIF_TRACE_DEBUG2("BTA_HH_SET_RPT_EVT: status = %d, handle = %d", - p_data->dev_status.status, p_data->dev_status.handle); + p_data->dev_status.status, p_data->dev_status.handle); p_dev = btif_hh_find_connected_dev_by_handle(p_data->dev_status.handle); if (p_dev != NULL && p_dev->p_buf != NULL) { BTIF_TRACE_DEBUG0("Freeing buffer..." ); @@ -577,32 +588,35 @@ static void btif_hh_upstreams_evt(UINT16 event, char* p_param) break; case BTA_HH_GET_PROTO_EVT: + p_dev = btif_hh_find_connected_dev_by_handle(p_data->dev_status.handle); BTIF_TRACE_WARNING4("BTA_HH_GET_PROTO_EVT: status = %d, handle = %d, proto = [%d], %s", p_data->hs_data.status, p_data->hs_data.handle, p_data->hs_data.rsp_data.proto_mode, (p_data->hs_data.rsp_data.proto_mode == BTA_HH_PROTO_RPT_MODE) ? "Report Mode" : (p_data->hs_data.rsp_data.proto_mode == BTA_HH_PROTO_BOOT_MODE) ? "Boot Mode" : "Unsupported"); + HAL_CBACK(bt_hh_callbacks, protocol_mode_cb,(bt_bdaddr_t*) &(p_dev->bd_addr), (bthh_status_t)p_data->hs_data.status, + (bthh_protocol_mode_t) p_data->hs_data.rsp_data.proto_mode); break; case BTA_HH_SET_PROTO_EVT: BTIF_TRACE_DEBUG2("BTA_HH_SET_PROTO_EVT: status = %d, handle = %d", p_data->dev_status.status, p_data->dev_status.handle); break; - /* +/* case BTA_HH_GET_IDLE_EVT: BTIF_TRACE_DEBUG3("BTA_HH_GET_IDLE_EVT: handle = %d, status = %d, rate = %d", p_data->hs_data.handle, p_data->hs_data.status, p_data->hs_data.rsp_data.idle_rate); break; - case BTA_HH_SET_IDLE_EVT: + case BTA_HH_SET_IDLE_EVT: BTIF_TRACE_DEBUG2("BTA_HH_SET_IDLE_EVT: status = %d, handle = %d", - p_data->dev_status.status, p_data->dev_status.handle); - btif_hh_cb.p_curr_dev = btif_hh_find_connected_dev_by_handle(p_data->dev_status.handle); - BTA_HhGetDscpInfo(p_data->dev_status.handle); - break; - */ + p_data->dev_status.status, p_data->dev_status.handle); + btif_hh_cb.p_curr_dev = btif_hh_find_connected_dev_by_handle(p_data->dev_status.handle); + BTA_HhGetDscpInfo(p_data->dev_status.handle); + break; +*/ case BTA_HH_GET_DSCP_EVT: BTIF_TRACE_WARNING2("BTA_HH_GET_DSCP_EVT: status = %d, handle = %d", p_data->dev_status.status, p_data->dev_status.handle); @@ -644,25 +658,14 @@ static void btif_hh_upstreams_evt(UINT16 event, char* p_param) BTIF_TRACE_DEBUG6("BTA_HH_GET_DSCP_EVT:bda2 = %02x:%02x:%02x:%02x:%02x:%02x", bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]); - - BTIF_TRACE_WARNING0("BTA_HH_GET_DSCP_EVT: Calling add device"); - BTIF_TRACE_WARNING1("BTA_HH_GET_DSCP_EVT: attr_mask %d", p_dev->attr_mask); - BTIF_TRACE_WARNING1("BTA_HH_GET_DSCP_EVT: sub_class %d", p_dev->sub_class); - BTIF_TRACE_WARNING1("BTA_HH_GET_DSCP_EVT: app_id %d", p_dev->app_id); - BTIF_TRACE_WARNING2("BTA_HH_GET_DSCP_EVT:desc_len=%d, dscp_info %d",len,&dscp_info); - BTIF_TRACE_DEBUG4("BTA_HH_GET_DSCP_EVT:country_code=%d,dscp_len=%d,version_id=%d,product_id=%d", - dscp_info.ctry_code, - dscp_info.descriptor.dl_len, - dscp_info.vendor_id,dscp_info.product_id); BTA_HhAddDev(bda, p_dev->attr_mask,p_dev->sub_class,p_dev->app_id, dscp_info); - //TODO write hid info to nvram - BTIF_TRACE_DEBUG0("BTA_HH_GET_DSCP_EVT:calling storage function"); - /*ret = btif_storage_add_hid_device_info(&(p_dev->bd_addr), p_dev->attr_mask,p_dev->sub_class,p_dev->app_id, + // write hid info to nvram + ret = btif_storage_add_hid_device_info(&(p_dev->bd_addr), p_dev->attr_mask,p_dev->sub_class,p_dev->app_id, p_data->dscp_info.vendor_id, p_data->dscp_info.product_id, p_data->dscp_info.version, p_data->dscp_info.ctry_code, len, p_data->dscp_info.descriptor.dsc_list); - //ASSERTC(ret == BT_STATUS_SUCCESS, "storing hid info failed", ret);*/ + ASSERTC(ret == BT_STATUS_SUCCESS, "storing hid info failed", ret); BTIF_TRACE_WARNING0("BTA_HH_GET_DSCP_EVT: Called add device"); //Free buffer created for dscp_info; @@ -712,7 +715,7 @@ static void btif_hh_upstreams_evt(UINT16 event, char* p_param) p_dev->dev_status = BTHH_CONN_STATE_DISCONNECTED; HAL_CBACK(bt_hh_callbacks, connection_state_cb,&(p_dev->bd_addr), p_dev->dev_status); btif_dm_cb_remove_bond(&(p_dev->bd_addr)); - HAL_CBACK(bt_hh_callbacks, virtual_unplug_cb,&(p_dev->bd_addr),BTHH_CONN_STATE_DISCONNECTED); + HAL_CBACK(bt_hh_callbacks, virtual_unplug_cb,&(p_dev->bd_addr),p_data->dev_status.status); } break; @@ -1027,6 +1030,73 @@ static bt_status_t set_info (bt_bdaddr_t *bd_addr, bthh_hid_info_t hid_info ) return BT_STATUS_SUCCESS; } +/******************************************************************************* +** +** Function get_idle_time +** +** Description Get the HID idle time +** +** Returns bt_status_t +** +*******************************************************************************/ +static bt_status_t get_idle_time(bt_bdaddr_t *bd_addr) +{ + CHECK_BTHH_INIT(); + btif_hh_device_t *p_dev; + BD_ADDR* bda = (BD_ADDR*) bd_addr; + + BTIF_TRACE_DEBUG6(" addr = %02X:%02X:%02X:%02X:%02X:%02X", + (*bda)[0], (*bda)[1], (*bda)[2], (*bda)[3], (*bda)[4], (*bda)[5]); + + if (btif_hh_cb.status != BTIF_HH_ENABLED) { + BTIF_TRACE_ERROR2("%s: Error, HH status = %d", __FUNCTION__, btif_hh_cb.status); + return BT_STATUS_FAIL; + } + + p_dev = btif_hh_find_connected_dev_by_bda(bd_addr); + if (p_dev != NULL) { + //BTA_HhGetIdle(p_dev->dev_handle); + } + else { + return BT_STATUS_FAIL; + } + return BT_STATUS_SUCCESS; +} + +/******************************************************************************* +** +** Function set_idle_time +** +** Description Set the HID idle time +** +** Returns bt_status_t +** +*******************************************************************************/ +static bt_status_t set_idle_time (bt_bdaddr_t *bd_addr, uint8_t idle_time) +{ + CHECK_BTHH_INIT(); + btif_hh_device_t *p_dev; + BD_ADDR* bda = (BD_ADDR*) bd_addr; + + BTIF_TRACE_DEBUG6("addr = %02X:%02X:%02X:%02X:%02X:%02X", + (*bda)[0], (*bda)[1], (*bda)[2], (*bda)[3], (*bda)[4], (*bda)[5]); + + if (btif_hh_cb.status != BTIF_HH_ENABLED) { + BTIF_TRACE_ERROR2("%s: Error, HH status = %d", __FUNCTION__, btif_hh_cb.status); + return BT_STATUS_FAIL; + } + + p_dev = btif_hh_find_connected_dev_by_bda(bd_addr); + if (p_dev == NULL) { + BTIF_TRACE_WARNING6(" Error, device %02X:%02X:%02X:%02X:%02X:%02X not opened.", + (*bda)[0], (*bda)[1], (*bda)[2], (*bda)[3], (*bda)[4], (*bda)[5]); + return BT_STATUS_FAIL; + } + else { + //BTA_HhSetIdle(p_dev->dev_handle, idle_time); + } + return BT_STATUS_SUCCESS; +} /******************************************************************************* ** @@ -1208,7 +1278,7 @@ static bt_status_t set_report (bt_bdaddr_t *bd_addr, bthh_report_type_t reportTy /* Build a SetReport data buffer */ memset(hexbuf, 0, 200); //TODO - /*hex_bytes_filled = scru_ascii_2_hex(report, len, hexbuf); + hex_bytes_filled = ascii_2_hex(report, len, hexbuf); LOGI("Hex bytes filled, hex value: %d", hex_bytes_filled); if (hex_bytes_filled) { @@ -1216,7 +1286,7 @@ static bt_status_t set_report (bt_bdaddr_t *bd_addr, bthh_report_type_t reportTy pbuf_data = (UINT8*) (p_dev->p_buf + 1) + p_dev->p_buf->offset; memcpy(pbuf_data, hexbuf, hex_bytes_filled); BTA_HhSetReport(p_dev->dev_handle, reportType, p_dev->p_buf); - }*/ + } return BT_STATUS_SUCCESS; } @@ -1304,12 +1374,28 @@ static bt_status_t send_data (bt_bdaddr_t *bd_addr, char* data) static void cleanup( void ) { BTIF_TRACE_EVENT1("%s", __FUNCTION__); + btif_hh_device_t *p_dev; + int i; + if (btif_hh_cb.status != BTIF_HH_ENABLED) { + BTIF_TRACE_WARNING2("%s: HH disabling or disabled already, status = %d", __FUNCTION__, btif_hh_cb.status); + return; + } + btif_hh_cb.status = BTIF_HH_DISABLING; + for (i = 0; i < BTIF_HH_MAX_HID; i++) { + p_dev = &btif_hh_cb.devices[i]; + if (p_dev->dev_status != BTIF_HH_DEV_UNKNOWN && p_dev->fd >= 0) { + BTIF_TRACE_DEBUG2("%s: Closing bthid.ko fd = %d", __FUNCTION__, p_dev->fd); + close(p_dev->fd); + p_dev->fd = -1; + } + } if (bt_hh_callbacks) { btif_disable_service(BTA_HID_SERVICE_ID); bt_hh_callbacks = NULL; } + } static const bthh_interface_t bthhInterface = { @@ -1321,6 +1407,8 @@ static const bthh_interface_t bthhInterface = { set_info, get_protocol, set_protocol, +// get_idle_time, +// set_idle_time, get_report, set_report, send_data, diff --git a/btif/src/btif_storage.c b/btif/src/btif_storage.c index f051de1..879be48 100755 --- a/btif/src/btif_storage.c +++ b/btif/src/btif_storage.c @@ -148,6 +148,15 @@ #define STORAGE_KEY_TYPE_MAX (10) +#define STORAGE_HID_ATRR_MASK_SIZE (4) +#define STORAGE_HID_SUB_CLASS_SIZE (2) +#define STORAGE_HID_APP_ID_SIZE (2) +#define STORAGE_HID_VENDOR_ID_SIZE (4) +#define STORAGE_HID_PRODUCT_ID_SIZE (4) +#define STORAGE_HID_VERSION_SIZE (4) +#define STORAGE_HID_CTRY_CODE_SIZE (2) +#define STORAGE_HID_DESC_LEN_SIZE (4) +#define STORAGE_HID_DESC_MAX_SIZE (2*512) /* <18 char bd addr> <space> LIST< <36 char uuid> <;> > <keytype (dec)> <pinlen> */ #define BTIF_REMOTE_SERVICES_ENTRY_SIZE_MAX (STORAGE_BDADDR_STRING_SZ + 1 +\ @@ -157,10 +166,25 @@ #define STORAGE_REMOTE_LINKKEYS_ENTRY_SIZE (LINK_KEY_LEN*2 + 1 + 2 + 1 + 2) +/* <18 char bd addr> <space>LIST <attr_mask> <space> > <sub_class> <space> <app_id> <space> + <vendor_id> <space> > <product_id> <space> <version> <space> + <ctry_code> <space> > <desc_len> <space> <desc_list> <space> */ +#define BTIF_HID_INFO_ENTRY_SIZE_MAX (STORAGE_BDADDR_STRING_SZ + 1 +\ + STORAGE_HID_ATRR_MASK_SIZE + 1 +\ + STORAGE_HID_SUB_CLASS_SIZE + 1 +\ + STORAGE_HID_APP_ID_SIZE+ 1 +\ + STORAGE_HID_VENDOR_ID_SIZE+ 1 +\ + STORAGE_HID_PRODUCT_ID_SIZE+ 1 +\ + STORAGE_HID_VERSION_SIZE+ 1 +\ + STORAGE_HID_CTRY_CODE_SIZE+ 1 +\ + STORAGE_HID_DESC_LEN_SIZE+ 1 +\ + STORAGE_HID_DESC_MAX_SIZE+ 1 ) + /* currently remote services is the potentially largest entry */ #define BTIF_STORAGE_MAX_LINE_SZ BTIF_REMOTE_SERVICES_ENTRY_SIZE_MAX + /* 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" @@ -594,10 +618,6 @@ int btif_in_load_hid_info_iter_cb(char *key, char *value, void *userdata) dscp_info.descriptor.dl_len = (uint16_t) hex_str_to_int(p, 4); p += 5; - BTIF_TRACE_DEBUG6("attr_mask=%d,sub_class=%d,app_id=%d,vendor_id=%d,product_id=%d,version=%d",attr_mask, - sub_class,app_id,dscp_info.vendor_id,dscp_info.product_id, dscp_info.version); - BTIF_TRACE_DEBUG2("country_code=%d,dscp_len=%d",dscp_info.ctry_code, dscp_info.descriptor.dl_len); - dscp_info.descriptor.dsc_list = (UINT8 *) GKI_getbuf(dscp_info.descriptor.dl_len); if (dscp_info.descriptor.dsc_list == NULL) { @@ -610,23 +630,19 @@ int btif_in_load_hid_info_iter_cb(char *key, char *value, void *userdata) p += 2; } - BTIF_TRACE_DEBUG1("btif_in_load_hid_info_iter_cb: BD-ADDR---%s",key); /* convert bd address (keystring) */ - //str2bd(key, &bd_addr); - //bda = (BD_ADDR*) &bd_addr; + str2bd(key, &bd_addr); + bda = (BD_ADDR*) &bd_addr; - /* add extracted information to BTA HH + // add extracted information to BTA HH if (btif_hh_add_added_dev(bd_addr,attr_mask)) { + BTIF_TRACE_DEBUG0("btif_in_load_hid_info_iter_cb: adding device"); BTA_HhAddDev(bd_addr.address, attr_mask, sub_class, app_id, dscp_info); - }*/ + } GKI_freebuf(dscp_info.descriptor.dsc_list); - - /* Fill in the bonded devices */ - //mcpy(&p_bonded_devices->devices[p_bonded_devices->num_devices++], &bd_addr, sizeof(bt_bdaddr_t)); - return 0; } @@ -684,7 +700,7 @@ bt_status_t btif_storage_get_adapter_property(bt_property_t *property) btif_in_fetch_bonded_devices(&bonded_devices); - BTIF_TRACE_DEBUG2("%s: Number of bonded devices: %d", __FUNCTION__, bonded_devices.num_devices); + BTIF_TRACE_DEBUG2("%s: Number of bonded devices: %d Property:BT_PROPERTY_ADAPTER_BONDED_DEVICES", __FUNCTION__, bonded_devices.num_devices); if (bonded_devices.num_devices > 0) { @@ -1204,8 +1220,15 @@ bt_status_t btif_storage_add_hid_device_info(bt_bdaddr_t *remote_bd_addr, } BTIF_TRACE_DEBUG1("%s",__FUNCTION__); +/* value = <attr_mask> <space> > <sub_class> <space> <app_id> <space> + <vendor_id> <space> > <product_id> <space> <version> <space> + <ctry_code> <space> > <desc_len> <space> <desc_list> <space> */ + size = (STORAGE_BDADDR_STRING_SZ + 1 + STORAGE_HID_ATRR_MASK_SIZE + 1 + + STORAGE_HID_SUB_CLASS_SIZE + 1 + STORAGE_HID_APP_ID_SIZE+ 1 + + STORAGE_HID_VENDOR_ID_SIZE+ 1 + STORAGE_HID_PRODUCT_ID_SIZE+ 1 + + STORAGE_HID_VERSION_SIZE+ 1 + STORAGE_HID_CTRY_CODE_SIZE+ 1 + + STORAGE_HID_DESC_LEN_SIZE+ 1 + (dl_len *2)+1); - size = 5 + 3 + 3 + 5 + 5 + 5 + 3 + 5 + (2 * dl_len) + 1; hid_info = (char *) malloc(size); if (hid_info == NULL) { BTIF_TRACE_ERROR2("%s: Oops, failed to allocate %d byte buffer for HID info string", @@ -1213,7 +1236,7 @@ bt_status_t btif_storage_add_hid_device_info(bt_bdaddr_t *remote_bd_addr, return BT_STATUS_FAIL; } - + //Convert the entries to hex and copy it to hid_info sprintf(hid_info, "%04X %02X %02X %04X %04X %04X %02X %04X ", attr_mask,sub_class,app_id,vendor_id,product_id,version,ctry_code,dl_len); @@ -1255,11 +1278,8 @@ bt_status_t btif_storage_add_hid_device_info(bt_bdaddr_t *remote_bd_addr, } *p = '\0'; - BTIF_TRACE_DEBUG1("key: %s",bd2str(remote_bd_addr, &bdstr)); - BTIF_TRACE_DEBUG1("hid info %s",hid_info); - ret = unv_write_key(fname, bd2str(remote_bd_addr, &bdstr), hid_info); - + free(hid_info); if (ret < 0) { return BT_STATUS_FAIL; @@ -1281,20 +1301,55 @@ bt_status_t btif_storage_add_hid_device_info(bt_bdaddr_t *remote_bd_addr, bt_status_t btif_storage_load_bonded_hid_info(void) { char *fname; - btif_bonded_devices_t bonded_devices; int ret; + fname = btif_in_make_filename(NULL, BTIF_STORAGE_PATH_REMOTE_HIDINFO); + + if (fname == NULL) + return BT_STATUS_FAIL; - memset(&bonded_devices, 0, sizeof(btif_bonded_devices_t)); + ret = unv_read_key_iter(fname, btif_in_load_hid_info_iter_cb, NULL); - fname = btif_in_make_filename(NULL, BTIF_STORAGE_PATH_REMOTE_HIDINFO); + if (ret < 0) + return BT_STATUS_FAIL; + + return BT_STATUS_SUCCESS; +} + +/******************************************************************************* +** +** Function btif_storage_remove_hid_info +** +** Description BTIF storage API - Deletes the bonded hid device info from NVRAM +** +** Returns BT_STATUS_SUCCESS if the deletion was successful, +** BT_STATUS_FAIL otherwise +** +*******************************************************************************/ +bt_status_t btif_storage_remove_hid_info(bt_bdaddr_t *remote_bd_addr) +{ + char *fname; + int ret; + bdstr_t bdstr; + fname = btif_in_make_filename(NULL, + BTIF_STORAGE_PATH_REMOTE_HIDINFO); if (fname == NULL) + { + return BT_STATUS_FAIL; + } + ret = unv_create_file(fname); + + if (ret < 0) + { return BT_STATUS_FAIL; + } - ret = unv_read_key_iter(fname, btif_in_load_hid_info_iter_cb, &bonded_devices); + ret = unv_remove_key(fname, bd2str(remote_bd_addr, &bdstr)); if (ret < 0) + { return BT_STATUS_FAIL; + } return BT_STATUS_SUCCESS; } diff --git a/btif/src/btif_util.c b/btif/src/btif_util.c index f5c06f8..a9eb0b4 100755 --- a/btif/src/btif_util.c +++ b/btif/src/btif_util.c @@ -61,7 +61,8 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <stdlib.h> +#include <ctype.h> + #define LOG_TAG "BTIF_UTIL" #include "btif_common.h" @@ -80,6 +81,8 @@ /************************************************************************************ ** Constants & Macros ************************************************************************************/ +#define ISDIGIT(a) ((a>='0') && (a<='9')) +#define ISXDIGIT(a) (((a>='0') && (a<='9'))||((a>='A') && (a<='F'))||((a>='a') && (a<='f'))) /************************************************************************************ ** Local type definitions @@ -192,6 +195,43 @@ void uuid_to_string(bt_uuid_t *p_uuid, char *str) ntohl(uuid4), ntohs(uuid5)); return; } + +/***************************************************************************** +** Function ascii_2_hex +** +** Description This function converts an ASCII string into HEX +** +** Returns the number of hex bytes filled. +*/ +int ascii_2_hex (char *p_ascii, int len, UINT8 *p_hex) +{ + int x; + UINT8 c; + + for (x = 0; (x < len) && (*p_ascii); x++) + { + if (ISDIGIT (*p_ascii)) + c = (*p_ascii - '0') << 4; + else + c = (toupper(*p_ascii) - 'A' + 10) << 4; + + p_ascii++; + if (*p_ascii) + { + if (ISDIGIT (*p_ascii)) + c |= (*p_ascii - '0'); + else + c |= (toupper(*p_ascii) - 'A' + 10); + + p_ascii++; + } + *p_hex++ = c; + } + + return (x); +} + + const char* dump_dm_search_event(UINT16 event) { switch(event) |