2 * Copyright (C) 2013 Intel Corporation
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
23 #include "../hal-msg.h"
24 #include "../hal-utils.h"
26 static hw_device_t *bt_device;
27 const bt_interface_t *if_bluetooth;
29 #define VERIFY_PROP_TYPE_ARG(n, typ) \
32 typ = str2btpropertytype(argv[n]); \
34 haltest_error("No property type specified\n"); \
39 static bt_scan_mode_t str2btscanmode(const char *str)
41 bt_scan_mode_t v = str2bt_scan_mode_t(str);
46 haltest_warn("WARN: %s cannot convert %s\n", __func__, str);
47 return (bt_scan_mode_t) atoi(str);
50 static bt_ssp_variant_t str2btsspvariant(const char *str)
52 bt_ssp_variant_t v = str2bt_ssp_variant_t(str);
57 haltest_warn("WARN: %s cannot convert %s\n", __func__, str);
58 return (bt_ssp_variant_t) atoi(str);
61 static bt_property_type_t str2btpropertytype(const char *str)
63 bt_property_type_t v = str2bt_property_type_t(str);
68 haltest_warn("WARN: %s cannot convert %s\n", __func__, str);
69 return (bt_property_type_t) atoi(str);
72 static void dump_properties(int num_properties, bt_property_t *properties)
76 for (i = 0; i < num_properties; i++) {
78 * properities sometimes come unaligned hence memcp to
82 memcpy(&prop, properties + i, sizeof(prop));
84 haltest_info("prop: %s\n", btproperty2str(&prop));
88 /* Cache for remote devices, stored in sorted array */
89 static bt_bdaddr_t *remote_devices = NULL;
90 static int remote_devices_cnt = 0;
91 static int remote_devices_capacity = 0;
93 /* Adds address to remote device set so it can be used in tab completion */
94 void add_remote_device(const bt_bdaddr_t *addr)
98 if (remote_devices == NULL) {
99 remote_devices = malloc(4 * sizeof(bt_bdaddr_t));
100 remote_devices_cnt = 0;
101 if (remote_devices == NULL) {
102 remote_devices_capacity = 0;
106 remote_devices_capacity = 4;
109 /* Array is sorted, search for right place */
110 for (i = 0; i < remote_devices_cnt; ++i) {
111 int res = memcmp(&remote_devices[i], addr, sizeof(*addr));
114 return; /* Already added */
119 /* Realloc space if needed */
120 if (remote_devices_cnt >= remote_devices_capacity) {
123 remote_devices_capacity *= 2;
125 * Save reference to previously allocated memory block so that
126 * it can be freed in case realloc fails.
128 tmp = remote_devices;
130 remote_devices = realloc(remote_devices, sizeof(bt_bdaddr_t) *
131 remote_devices_capacity);
132 if (remote_devices == NULL) {
134 remote_devices_capacity = 0;
135 remote_devices_cnt = 0;
140 if (i < remote_devices_cnt)
141 memmove(remote_devices + i + 1, remote_devices + i,
142 (remote_devices_cnt - i) * sizeof(bt_bdaddr_t));
143 remote_devices[i] = *addr;
144 remote_devices_cnt++;
147 const char *enum_devices(void *v, int i)
149 static char buf[MAX_ADDR_STR_LEN];
151 if (i >= remote_devices_cnt)
154 bt_bdaddr_t2str(&remote_devices[i], buf);
158 static void add_remote_device_from_props(int num_properties,
159 const bt_property_t *properties)
163 for (i = 0; i < num_properties; i++) {
165 * properities sometimes come unaligned hence memcp to
168 bt_property_t property;
170 memcpy(&property, properties + i, sizeof(property));
171 if (property.type == BT_PROPERTY_BDADDR)
172 add_remote_device((bt_bdaddr_t *) property.val);
176 bool close_hw_bt_dev(void)
181 bt_device->close(bt_device);
185 static void adapter_state_changed_cb(bt_state_t state)
187 haltest_info("%s: state=%s\n", __func__, bt_state_t2str(state));
190 static void adapter_properties_cb(bt_status_t status, int num_properties,
191 bt_property_t *properties)
193 haltest_info("%s: status=%s num_properties=%d\n", __func__,
194 bt_status_t2str(status), num_properties);
196 dump_properties(num_properties, properties);
199 static void remote_device_properties_cb(bt_status_t status,
200 bt_bdaddr_t *bd_addr,
202 bt_property_t *properties)
204 haltest_info("%s: status=%s bd_addr=%s num_properties=%d\n", __func__,
205 bt_status_t2str(status), bdaddr2str(bd_addr),
208 add_remote_device(bd_addr);
210 dump_properties(num_properties, properties);
213 static void device_found_cb(int num_properties, bt_property_t *properties)
215 haltest_info("%s: num_properties=%d\n", __func__, num_properties);
217 add_remote_device_from_props(num_properties, properties);
219 dump_properties(num_properties, properties);
222 static void discovery_state_changed_cb(bt_discovery_state_t state)
224 haltest_info("%s: state=%s\n", __func__,
225 bt_discovery_state_t2str(state));
229 * Buffer for remote addres that came from one of bind request.
230 * It's stored for command completion.
232 static char last_remote_addr[MAX_ADDR_STR_LEN];
233 static bt_ssp_variant_t last_ssp_variant = (bt_ssp_variant_t) -1;
235 static bt_bdaddr_t pin_request_addr;
236 static void pin_request_answer(char *reply)
240 int pin_len = strlen(reply);
246 memcpy(&pin.pin, reply, pin_len);
249 EXEC(if_bluetooth->pin_reply, &pin_request_addr, accept, pin_len, &pin);
252 static void pin_request_cb(bt_bdaddr_t *remote_bd_addr, bt_bdname_t *bd_name,
255 /* Store for command completion */
256 bt_bdaddr_t2str(remote_bd_addr, last_remote_addr);
257 pin_request_addr = *remote_bd_addr;
259 haltest_info("%s: remote_bd_addr=%s bd_name=%s cod=%06x\n", __func__,
260 last_remote_addr, bd_name->name, cod);
261 terminal_prompt_for("Enter pin: ", pin_request_answer);
264 /* Variables to store information from ssp_request_cb used for ssp_reply */
265 static bt_bdaddr_t ssp_request_addr;
266 static bt_ssp_variant_t ssp_request_variant;
267 static uint32_t ssp_request_pask_key;
269 /* Called when user hit enter on prompt for confirmation */
270 static void ssp_request_yes_no_answer(char *reply)
272 int accept = *reply == 0 || *reply == 'y' || *reply == 'Y';
274 if_bluetooth->ssp_reply(&ssp_request_addr, ssp_request_variant, accept,
275 ssp_request_pask_key);
278 static void ssp_request_cb(bt_bdaddr_t *remote_bd_addr, bt_bdname_t *bd_name,
279 uint32_t cod, bt_ssp_variant_t pairing_variant,
282 static char prompt[50];
284 /* Store for command completion */
285 bt_bdaddr_t2str(remote_bd_addr, last_remote_addr);
286 last_ssp_variant = pairing_variant;
288 haltest_info("%s: remote_bd_addr=%s bd_name=%s cod=%06x pairing_variant=%s pass_key=%d\n",
289 __func__, last_remote_addr, bd_name->name, cod,
290 bt_ssp_variant_t2str(pairing_variant), pass_key);
292 switch (pairing_variant) {
293 case BT_SSP_VARIANT_PASSKEY_CONFIRMATION:
294 sprintf(prompt, "Does other device show %d [Y/n] ?", pass_key);
296 ssp_request_addr = *remote_bd_addr;
297 ssp_request_variant = pairing_variant;
298 ssp_request_pask_key = pass_key;
300 terminal_prompt_for(prompt, ssp_request_yes_no_answer);
302 case BT_SSP_VARIANT_CONSENT:
303 sprintf(prompt, "Consent pairing [Y/n] ?");
305 ssp_request_addr = *remote_bd_addr;
306 ssp_request_variant = pairing_variant;
307 ssp_request_pask_key = 0;
309 terminal_prompt_for(prompt, ssp_request_yes_no_answer);
311 case BT_SSP_VARIANT_PASSKEY_ENTRY:
312 case BT_SSP_VARIANT_PASSKEY_NOTIFICATION:
314 haltest_info("Not automatically handled\n");
319 static void bond_state_changed_cb(bt_status_t status,
320 bt_bdaddr_t *remote_bd_addr,
321 bt_bond_state_t state)
323 haltest_info("%s: status=%s remote_bd_addr=%s state=%s\n", __func__,
324 bt_status_t2str(status), bdaddr2str(remote_bd_addr),
325 bt_bond_state_t2str(state));
328 static void acl_state_changed_cb(bt_status_t status,
329 bt_bdaddr_t *remote_bd_addr,
330 bt_acl_state_t state)
332 haltest_info("%s: status=%s remote_bd_addr=%s state=%s\n", __func__,
333 bt_status_t2str(status), bdaddr2str(remote_bd_addr),
334 bt_acl_state_t2str(state));
337 static void thread_evt_cb(bt_cb_thread_evt evt)
339 haltest_info("%s: evt=%s\n", __func__, bt_cb_thread_evt2str(evt));
342 static void dut_mode_recv_cb(uint16_t opcode, uint8_t *buf, uint8_t len)
344 haltest_info("%s\n", __func__);
347 static void le_test_mode_cb(bt_status_t status, uint16_t num_packets)
349 haltest_info("%s %s %d\n", __func__, bt_status_t2str(status),
353 #if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
354 static void energy_info_cb(bt_activity_energy_info *energy_info)
356 haltest_info("%s status=%s, ctrl_state=0x%02X, tx_time=0x%jx,"
357 "rx_time=0x%jx, idle_time=0x%jx, energu_used=0x%jx\n",
358 __func__, bt_status_t2str(energy_info->status),
359 energy_info->ctrl_state, energy_info->tx_time,
360 energy_info->rx_time, energy_info->idle_time,
361 energy_info->energy_used);
365 static bt_callbacks_t bt_callbacks = {
366 .size = sizeof(bt_callbacks),
367 .adapter_state_changed_cb = adapter_state_changed_cb,
368 .adapter_properties_cb = adapter_properties_cb,
369 .remote_device_properties_cb = remote_device_properties_cb,
370 .device_found_cb = device_found_cb,
371 .discovery_state_changed_cb = discovery_state_changed_cb,
372 .pin_request_cb = pin_request_cb,
373 .ssp_request_cb = ssp_request_cb,
374 .bond_state_changed_cb = bond_state_changed_cb,
375 .acl_state_changed_cb = acl_state_changed_cb,
376 .thread_evt_cb = thread_evt_cb,
377 .dut_mode_recv_cb = dut_mode_recv_cb,
378 .le_test_mode_cb = le_test_mode_cb,
379 #if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
380 .energy_info_cb = energy_info_cb,
384 #if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
385 static alarm_cb alarm_cb_p = NULL;
386 static void *alarm_cb_p_data = NULL;
388 static bool set_wake_alarm(uint64_t delay_millis, bool should_wake, alarm_cb cb,
391 haltest_info("%s: delay %"PRIu64" should_wake %u cb %p data %p\n",
392 __func__, delay_millis, should_wake, cb, data);
394 /* TODO call alarm callback after specified delay */
396 alarm_cb_p_data = data;
401 static int acquire_wake_lock(const char *lock_name)
403 haltest_info("%s: %s\n", __func__, lock_name);
405 return BT_STATUS_SUCCESS;
408 static int release_wake_lock(const char *lock_name)
410 haltest_info("%s: %s\n", __func__, lock_name);
412 return BT_STATUS_SUCCESS;
415 static bt_os_callouts_t bt_os_callouts = {
416 .size = sizeof(bt_os_callouts),
417 .set_wake_alarm = set_wake_alarm,
418 .acquire_wake_lock = acquire_wake_lock,
419 .release_wake_lock = release_wake_lock,
423 static void init_p(int argc, const char **argv)
426 const hw_module_t *module;
428 err = hw_get_module(BT_HARDWARE_MODULE_ID, &module);
430 haltest_error("he_get_module returned %d\n", err);
434 err = module->methods->open(module, BT_HARDWARE_MODULE_ID, &bt_device);
436 haltest_error("module->methods->open returned %d\n", err);
441 ((bluetooth_device_t *) bt_device)->get_bluetooth_interface();
443 haltest_error("get_bluetooth_interface returned NULL\n");
447 EXEC(if_bluetooth->init, &bt_callbacks);
449 #if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
450 EXEC(if_bluetooth->set_os_callouts, &bt_os_callouts);
454 static void cleanup_p(int argc, const char **argv)
456 RETURN_IF_NULL(if_bluetooth);
458 EXECV(if_bluetooth->cleanup);
463 static void enable_p(int argc, const char **argv)
465 RETURN_IF_NULL(if_bluetooth);
467 EXEC(if_bluetooth->enable);
469 #if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
470 static void read_energy_info_p(int argc, const char **argv)
472 RETURN_IF_NULL(if_bluetooth);
474 EXEC(if_bluetooth->read_energy_info);
477 #define get_connection_state_c complete_addr_c
479 static void get_connection_state_p(int argc, const char **argv)
483 RETURN_IF_NULL(if_bluetooth);
485 VERIFY_ADDR_ARG(2, &addr);
487 haltest_info("if_bluetooth->get_connection_state : %d\n",
488 if_bluetooth->get_connection_state(&addr));
492 static void disable_p(int argc, const char **argv)
494 RETURN_IF_NULL(if_bluetooth);
496 EXEC(if_bluetooth->disable);
499 static void get_adapter_properties_p(int argc, const char **argv)
501 RETURN_IF_NULL(if_bluetooth);
503 EXEC(if_bluetooth->get_adapter_properties);
506 static void get_adapter_property_c(int argc, const char **argv,
507 enum_func *enum_func, void **user)
510 *user = TYPE_ENUM(bt_property_type_t);
511 *enum_func = enum_defines;
515 static void get_adapter_property_p(int argc, const char **argv)
519 RETURN_IF_NULL(if_bluetooth);
520 VERIFY_PROP_TYPE_ARG(2, type);
522 EXEC(if_bluetooth->get_adapter_property, type);
525 static const char * const names[] = {
526 "BT_PROPERTY_BDNAME",
527 "BT_PROPERTY_ADAPTER_SCAN_MODE",
528 "BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT",
532 static void set_adapter_property_c(int argc, const char **argv,
533 enum_func *enum_func, void **user)
536 *user = (void *) names;
537 *enum_func = enum_strings;
538 } else if (argc == 4) {
539 if (0 == strcmp(argv[2], "BT_PROPERTY_ADAPTER_SCAN_MODE")) {
540 *user = TYPE_ENUM(bt_scan_mode_t);
541 *enum_func = enum_defines;
546 static void set_adapter_property_p(int argc, const char **argv)
548 bt_property_t property;
552 RETURN_IF_NULL(if_bluetooth);
553 VERIFY_PROP_TYPE_ARG(2, property.type);
556 haltest_error("No property value specified\n");
559 switch (property.type) {
560 case BT_PROPERTY_BDNAME:
561 property.len = strlen(argv[3]) + 1;
562 property.val = (char *) argv[3];
565 case BT_PROPERTY_ADAPTER_SCAN_MODE:
566 mode = str2btscanmode(argv[3]);
567 property.len = sizeof(bt_scan_mode_t);
568 property.val = &mode;
571 case BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT:
572 timeout = atoi(argv[3]);
573 property.val = &timeout;
574 property.len = sizeof(timeout);
577 case BT_PROPERTY_BDADDR:
578 case BT_PROPERTY_UUIDS:
579 case BT_PROPERTY_CLASS_OF_DEVICE:
580 case BT_PROPERTY_TYPE_OF_DEVICE:
581 case BT_PROPERTY_SERVICE_RECORD:
582 case BT_PROPERTY_ADAPTER_BONDED_DEVICES:
583 case BT_PROPERTY_REMOTE_FRIENDLY_NAME:
584 case BT_PROPERTY_REMOTE_RSSI:
585 case BT_PROPERTY_REMOTE_VERSION_INFO:
586 case BT_PROPERTY_REMOTE_DEVICE_TIMESTAMP:
587 #if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
588 case BT_PROPERTY_LOCAL_LE_FEATURES:
591 haltest_error("Invalid property %s\n", argv[3]);
595 EXEC(if_bluetooth->set_adapter_property, &property);
598 /* This function is to be used for completion methods that need only address */
599 static void complete_addr_c(int argc, const char **argv, enum_func *enum_func,
604 *enum_func = enum_devices;
608 /* Just addres to complete, use complete_addr_c */
609 #define get_remote_device_properties_c complete_addr_c
611 static void get_remote_device_properties_p(int argc, const char **argv)
615 RETURN_IF_NULL(if_bluetooth);
616 VERIFY_ADDR_ARG(2, &addr);
618 EXEC(if_bluetooth->get_remote_device_properties, &addr);
621 static void get_remote_device_property_c(int argc, const char **argv,
622 enum_func *enum_func,
627 *enum_func = enum_devices;
628 } else if (argc == 4) {
629 *user = TYPE_ENUM(bt_property_type_t);
630 *enum_func = enum_defines;
634 static void get_remote_device_property_p(int argc, const char **argv)
636 bt_property_type_t type;
639 RETURN_IF_NULL(if_bluetooth);
640 VERIFY_ADDR_ARG(2, &addr);
641 VERIFY_PROP_TYPE_ARG(3, type);
643 EXEC(if_bluetooth->get_remote_device_property, &addr, type);
647 * Same completion as for get_remote_device_property_c can be used for
648 * set_remote_device_property_c. No need to create separate function.
650 #define set_remote_device_property_c get_remote_device_property_c
652 static void set_remote_device_property_p(int argc, const char **argv)
654 bt_property_t property;
657 RETURN_IF_NULL(if_bluetooth);
658 VERIFY_ADDR_ARG(2, &addr);
659 VERIFY_PROP_TYPE_ARG(3, property.type);
661 switch (property.type) {
662 case BT_PROPERTY_REMOTE_FRIENDLY_NAME:
663 property.len = strlen(argv[4]);
664 property.val = (char *) argv[4];
666 case BT_PROPERTY_BDNAME:
667 case BT_PROPERTY_BDADDR:
668 case BT_PROPERTY_UUIDS:
669 case BT_PROPERTY_CLASS_OF_DEVICE:
670 case BT_PROPERTY_TYPE_OF_DEVICE:
671 case BT_PROPERTY_SERVICE_RECORD:
672 case BT_PROPERTY_ADAPTER_SCAN_MODE:
673 case BT_PROPERTY_ADAPTER_BONDED_DEVICES:
674 case BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT:
675 case BT_PROPERTY_REMOTE_RSSI:
676 case BT_PROPERTY_REMOTE_VERSION_INFO:
677 case BT_PROPERTY_REMOTE_DEVICE_TIMESTAMP:
678 #if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
679 case BT_PROPERTY_LOCAL_LE_FEATURES:
685 EXEC(if_bluetooth->set_remote_device_property, &addr, &property);
688 /* For now uuid is not autocompleted. Use routine for complete_addr_c */
689 #define get_remote_service_record_c complete_addr_c
691 static void get_remote_service_record_p(int argc, const char **argv)
696 RETURN_IF_NULL(if_bluetooth);
697 VERIFY_ADDR_ARG(2, &addr);
700 haltest_error("No uuid specified\n");
704 str2bt_uuid_t(argv[3], &uuid);
706 EXEC(if_bluetooth->get_remote_service_record, &addr, &uuid);
709 /* Just addres to complete, use complete_addr_c */
710 #define get_remote_services_c complete_addr_c
712 static void get_remote_services_p(int argc, const char **argv)
716 RETURN_IF_NULL(if_bluetooth);
717 VERIFY_ADDR_ARG(2, &addr);
719 EXEC(if_bluetooth->get_remote_services, &addr);
722 static void start_discovery_p(int argc, const char **argv)
724 RETURN_IF_NULL(if_bluetooth);
726 EXEC(if_bluetooth->start_discovery);
729 static void cancel_discovery_p(int argc, const char **argv)
731 RETURN_IF_NULL(if_bluetooth);
733 EXEC(if_bluetooth->cancel_discovery);
736 /* Just addres to complete, use complete_addr_c */
737 #define create_bond_c complete_addr_c
739 static void create_bond_p(int argc, const char **argv)
742 #if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
746 RETURN_IF_NULL(if_bluetooth);
747 VERIFY_ADDR_ARG(2, &addr);
749 #if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
751 transport = BT_TRANSPORT_UNKNOWN;
753 transport = atoi(argv[3]);
755 EXEC(if_bluetooth->create_bond, &addr, transport);
757 EXEC(if_bluetooth->create_bond, &addr);
761 /* Just addres to complete, use complete_addr_c */
762 #define remove_bond_c complete_addr_c
764 static void remove_bond_p(int argc, const char **argv)
768 RETURN_IF_NULL(if_bluetooth);
769 VERIFY_ADDR_ARG(2, &addr);
771 EXEC(if_bluetooth->remove_bond, &addr);
774 /* Just addres to complete, use complete_addr_c */
775 #define cancel_bond_c complete_addr_c
777 static void cancel_bond_p(int argc, const char **argv)
781 RETURN_IF_NULL(if_bluetooth);
782 VERIFY_ADDR_ARG(2, &addr);
784 EXEC(if_bluetooth->cancel_bond, &addr);
787 static void pin_reply_c(int argc, const char **argv, enum_func *enum_func,
790 static const char *const completions[] = { last_remote_addr, NULL };
793 *user = (void *) completions;
794 *enum_func = enum_strings;
798 static void pin_reply_p(int argc, const char **argv)
805 RETURN_IF_NULL(if_bluetooth);
806 VERIFY_ADDR_ARG(2, &addr);
810 pin_len = strlen(argv[3]);
811 memcpy(pin.pin, argv[3], pin_len);
814 EXEC(if_bluetooth->pin_reply, &addr, accept, pin_len, &pin);
817 static void ssp_reply_c(int argc, const char **argv, enum_func *enum_func,
821 *user = last_remote_addr;
822 *enum_func = enum_one_string;
823 } else if (argc == 5) {
825 *enum_func = enum_one_string;
826 } else if (argc == 4) {
827 if (-1 != (int) last_ssp_variant) {
828 *user = (void *) bt_ssp_variant_t2str(last_ssp_variant);
829 *enum_func = enum_one_string;
831 *user = TYPE_ENUM(bt_ssp_variant_t);
832 *enum_func = enum_defines;
837 static void ssp_reply_p(int argc, const char **argv)
840 bt_ssp_variant_t var;
844 RETURN_IF_NULL(if_bluetooth);
845 VERIFY_ADDR_ARG(2, &addr);
848 haltest_error("No ssp variant specified\n");
852 var = str2btsspvariant(argv[3]);
854 haltest_error("No accept value specified\n");
858 accept = atoi(argv[4]);
861 if (accept && var == BT_SSP_VARIANT_PASSKEY_ENTRY && argc >= 5)
862 passkey = atoi(argv[4]);
864 EXEC(if_bluetooth->ssp_reply, &addr, var, accept, passkey);
867 static void get_profile_interface_c(int argc, const char **argv,
868 enum_func *enum_func, void **user)
870 static const char *const profile_ids[] = {
871 BT_PROFILE_HANDSFREE_ID,
872 BT_PROFILE_ADVANCED_AUDIO_ID,
873 BT_PROFILE_HEALTH_ID,
874 BT_PROFILE_SOCKETS_ID,
875 BT_PROFILE_HIDHOST_ID,
879 #if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
880 BT_PROFILE_HANDSFREE_CLIENT_ID,
881 BT_PROFILE_MAP_CLIENT_ID,
882 BT_PROFILE_AV_RC_CTRL_ID,
883 BT_PROFILE_ADVANCED_AUDIO_SINK_ID,
889 *user = (void *) profile_ids;
890 *enum_func = enum_strings;
894 static void get_profile_interface_p(int argc, const char **argv)
897 const void **pif = NULL;
899 RETURN_IF_NULL(if_bluetooth);
901 haltest_error("No interface specified\n");
907 if (strcmp(BT_PROFILE_HANDSFREE_ID, id) == 0)
908 pif = (const void **) &if_hf;
909 else if (strcmp(BT_PROFILE_ADVANCED_AUDIO_ID, id) == 0)
910 pif = (const void **) &if_av;
911 else if (strcmp(BT_PROFILE_HEALTH_ID, id) == 0)
912 pif = (const void **) &if_hl;
913 else if (strcmp(BT_PROFILE_SOCKETS_ID, id) == 0)
914 pif = (const void **) &if_sock;
915 else if (strcmp(BT_PROFILE_HIDHOST_ID, id) == 0)
916 pif = (const void **) &if_hh;
917 else if (strcmp(BT_PROFILE_PAN_ID, id) == 0)
918 pif = (const void **) &if_pan;
919 else if (strcmp(BT_PROFILE_AV_RC_ID, id) == 0)
920 pif = (const void **) &if_rc;
921 else if (strcmp(BT_PROFILE_GATT_ID, id) == 0)
922 pif = (const void **) &if_gatt;
923 #if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
924 else if (strcmp(BT_PROFILE_AV_RC_CTRL_ID, id) == 0)
925 pif = (const void **) &if_rc_ctrl;
926 else if (strcmp(BT_PROFILE_HANDSFREE_CLIENT_ID, id) == 0)
927 pif = (const void **) &if_hf_client;
928 else if (strcmp(BT_PROFILE_MAP_CLIENT_ID, id) == 0)
929 pif = (const void **) &if_mce;
930 else if (strcmp(BT_PROFILE_ADVANCED_AUDIO_SINK_ID, id) == 0)
931 pif = (const void **) &if_av_sink;
934 haltest_error("%s is not correct for get_profile_interface\n",
938 *pif = if_bluetooth->get_profile_interface(id);
939 haltest_info("get_profile_interface(%s) : %p\n", id, *pif);
943 static void dut_mode_configure_p(int argc, const char **argv)
947 RETURN_IF_NULL(if_bluetooth);
950 haltest_error("No dut mode specified\n");
954 mode = strtol(argv[2], NULL, 0);
956 EXEC(if_bluetooth->dut_mode_configure, mode);
959 static void dut_mode_send_p(int argc, const char **argv)
961 haltest_error("not implemented\n");
964 static void le_test_mode_p(int argc, const char **argv)
966 haltest_error("not implemented\n");
969 static void config_hci_snoop_log_p(int argc, const char **argv)
973 RETURN_IF_NULL(if_bluetooth);
976 haltest_error("No mode specified\n");
980 mode = strtol(argv[2], NULL, 0);
982 EXEC(if_bluetooth->config_hci_snoop_log, mode);
985 static struct method methods[] = {
990 STD_METHOD(get_adapter_properties),
991 STD_METHODCH(get_adapter_property, "<prop_type>"),
992 STD_METHODCH(set_adapter_property, "<prop_type> <prop_value>"),
993 STD_METHODCH(get_remote_device_properties, "<addr>"),
994 STD_METHODCH(get_remote_device_property, "<addr> <property_type>"),
995 STD_METHODCH(set_remote_device_property,
996 "<addr> <property_type> <value>"),
997 STD_METHODCH(get_remote_service_record, "<addr> <uuid>"),
998 STD_METHODCH(get_remote_services, "<addr>"),
999 STD_METHOD(start_discovery),
1000 STD_METHOD(cancel_discovery),
1001 #if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
1002 STD_METHODCH(create_bond, "<addr> [<transport>]"),
1003 STD_METHOD(read_energy_info),
1004 STD_METHODCH(get_connection_state, "<addr>"),
1006 STD_METHODCH(create_bond, "<addr>"),
1008 STD_METHODCH(remove_bond, "<addr>"),
1009 STD_METHODCH(cancel_bond, "<addr>"),
1010 STD_METHODCH(pin_reply, "<address> [<pin>]"),
1011 STD_METHODCH(ssp_reply, "<address> <ssp_veriant> 1|0 [<passkey>]"),
1012 STD_METHODCH(get_profile_interface, "<profile id>"),
1013 STD_METHODH(dut_mode_configure, "<dut mode>"),
1014 STD_METHOD(dut_mode_send),
1015 STD_METHOD(le_test_mode),
1016 STD_METHODH(config_hci_snoop_log, "<mode>"),
1020 const struct interface bluetooth_if = {
1021 .name = "bluetooth",