/* Callback for scan results */ static void gattc_scan_result_cb(bt_bdaddr_t *bda, int rssi, uint8_t *adv_data) { char buf[MAX_ADDR_STR_LEN]; haltest_info("%s: bda=%s rssi=%d adv_data=%p\n", __func__, bt_bdaddr_t2str(bda, buf), rssi, adv_data); }
static void connection_state(btav_connection_state_t state, bt_bdaddr_t *bd_addr) { haltest_info("%s: connection_state=%s remote_bd_addr=%s\n", __func__, btav_connection_state_t2str(state), bt_bdaddr_t2str(bd_addr, last_addr)); }
/* GATT open callback invoked in response to open */ static void gattc_connect_cb(int conn_id, int status, int client_if, bt_bdaddr_t *bda) { haltest_info("%s: conn_id=%d status=%d, client_if=%d bda=%s\n", __func__, conn_id, status, client_if, bt_bdaddr_t2str(bda, last_addr)); }
/* * This function read from fd socket information about * connected socket */ static void receive_sock_connect_signal(struct pollfd *pollfd) { sock_connect_signal_t cs; char addr_str[MAX_ADDR_STR_LEN]; if (pollfd->revents & POLLIN) { int ret; poll_unregister_fd(pollfd->fd, receive_sock_connect_signal); ret = read(pollfd->fd, &cs, sizeof(cs)); if (ret != sizeof(cs)) { haltest_info("Read on connect return %d\n", ret); return; } haltest_info("Connection to %s channel %d status=%d\n", bt_bdaddr_t2str(&cs.bd_addr, addr_str), cs.channel, cs.status); if (cs.status == 0) poll_register_fd(pollfd->fd, POLLIN, receive_from_client); } if (pollfd->revents & POLLHUP) { haltest_error("Disconnected fd=%d revents=0x%X\n", pollfd->fd, pollfd->revents); poll_unregister_fd(pollfd->fd, receive_sock_connect_signal); } }
/* Callback for audio connection state change. */ static void hf_client_audio_state_callback(bthf_client_audio_state_t state, bt_bdaddr_t *bd_addr) { haltest_info("%s: state=%s bd_addr=%s\n", __func__, bthf_client_audio_state_t2str(state), bt_bdaddr_t2str(bd_addr, last_addr)); }
/* * Callback for connection state change. * state will have one of the values from BtHfConnectionState */ static void connection_state_cb(bthf_connection_state_t state, bt_bdaddr_t *bd_addr) { haltest_info("%s: state=%s bd_addr=%s\n", __func__, bthf_connection_state_t2str(state), bt_bdaddr_t2str(bd_addr, last_addr)); }
/* * Callback for get hid info * hid_info will contain attr_mask, sub_class, app_id, vendor_id, product_id, * version, ctry_code, len */ static void hid_info_cb(bt_bdaddr_t *bd_addr, bthh_hid_info_t hid_info) { char addr[MAX_ADDR_STR_LEN]; /* TODO: bluedroid does not seem to ever call this callback */ haltest_info("%s: bd_addr=%s\n", __func__, bt_bdaddr_t2str(bd_addr, addr)); }
/* Callback triggered in response to read_remote_rssi */ static void gattc_read_remote_rssi_cb(int client_if, bt_bdaddr_t *bda, int rssi, int status) { char buf[MAX_ADDR_STR_LEN]; haltest_info("%s: client_if=%d bda=%s rssi=%d satus=%d\n", __func__, client_if, bt_bdaddr_t2str(bda, buf), rssi, status); }
/* * Callback indicating that a remote device has connected * or been disconnected */ static void gatts_connection_cb(int conn_id, int server_if, int connected, bt_bdaddr_t *bda) { haltest_info("%s: conn_id=%d server_if=%d connected=%d bda=%s\n", __func__, conn_id, server_if, connected, bt_bdaddr_t2str(bda, last_addr)); snprintf(conn_id_str, sizeof(conn_id_str), "%d", conn_id); }
/* * Callback for virtual unplug api. * the status of the virtual unplug */ static void virtual_unplug_cb(bt_bdaddr_t *bd_addr, bthh_status_t hh_status) { char addr[MAX_ADDR_STR_LEN]; haltest_info("%s: bd_addr=%s hh_status=%s\n", __func__, bt_bdaddr_t2str(bd_addr, addr), bthh_status_t2str(hh_status)); }
/* * Callback for get/set_idle_time api. */ static void idle_time_cb(bt_bdaddr_t *bd_addr, bthh_status_t hh_status, int idle_rate) { char addr[MAX_ADDR_STR_LEN]; haltest_info("%s: bd_addr=%s hh_status=%s idle_rate=%d\n", __func__, bt_bdaddr_t2str(bd_addr, addr), bthh_status_t2str(hh_status), idle_rate); }
/* Callback invoked when a previously prepared write is to be executed */ static void gatts_request_exec_write_cb(int conn_id, int trans_id, bt_bdaddr_t *bda, int exec_write) { char buf[MAX_ADDR_STR_LEN]; haltest_info("%s: conn_id=%d trans_id=%d bda=%s exec_write=%d\n", __func__, conn_id, trans_id, bt_bdaddr_t2str(bda, buf), exec_write); }
/* Callback invoked in response to close */ static void gattc_disconnect_cb(int conn_id, int status, int client_if, bt_bdaddr_t *bda) { char buf[MAX_ADDR_STR_LEN]; haltest_info("%s: conn_id=%d status=%d, client_if=%d bda=%s\n", __func__, conn_id, status, client_if, bt_bdaddr_t2str(bda, buf)); }
/* * Callback for get/set protocol api. * the protocol mode is one of the value from bthh_protocol_mode_t */ static void protocol_mode_cb(bt_bdaddr_t *bd_addr, bthh_status_t hh_status, bthh_protocol_mode_t mode) { char addr[MAX_ADDR_STR_LEN]; haltest_info("%s: bd_addr=%s hh_status=%s mode=%s\n", __func__, bt_bdaddr_t2str(bd_addr, addr), bthh_status_t2str(hh_status), bthh_protocol_mode_t2str(mode)); }
/* * Callback for get report api. * if status is ok rpt_data contains the report data */ static void get_report_cb(bt_bdaddr_t *bd_addr, bthh_status_t hh_status, uint8_t *rpt_data, int rpt_size) { char addr[MAX_ADDR_STR_LEN]; /* TODO: print actual report */ haltest_info("%s: bd_addr=%s hh_status=%s rpt_size=%d\n", __func__, bt_bdaddr_t2str(bd_addr, addr), bthh_status_t2str(hh_status), rpt_size); }
/* * Callback invoked when a remote device has requested to read a characteristic * or descriptor. The application must respond by calling send_response */ static void gatts_request_read_cb(int conn_id, int trans_id, bt_bdaddr_t *bda, int attr_handle, int offset, bool is_long) { char buf[MAX_ADDR_STR_LEN]; haltest_info("%s: conn_id=%d trans_id=%d bda=%s attr_handle=0x%x offset=%d is_long=%d\n", __func__, conn_id, trans_id, bt_bdaddr_t2str(bda, buf), attr_handle, offset, is_long); }
const char *enum_devices(void *v, int i) { static char buf[MAX_ADDR_STR_LEN]; if (i >= remote_devices_cnt) return NULL; bt_bdaddr_t2str(&remote_devices[i], buf); return buf; }
static void pin_request_cb(bt_bdaddr_t *remote_bd_addr, bt_bdname_t *bd_name, uint32_t cod) { /* Store for command completion */ bt_bdaddr_t2str(remote_bd_addr, last_remote_addr); pin_request_addr = *remote_bd_addr; haltest_info("%s: remote_bd_addr=%s bd_name=%s cod=%06x\n", __func__, last_remote_addr, bd_name->name, cod); terminal_prompt_for("Enter pin: ", pin_request_answer); }
/* * This function read from fd socket information about * incoming connection and starts monitoring new connection * on file descriptor read from fd. */ static void read_accepted(int fd) { int ret; struct msghdr msg; struct iovec iv; char cmsgbuf[CMSG_SPACE(1)]; struct cmsghdr *cmsgptr; sock_connect_signal_t cs; int accepted_fd = -1; char addr_str[MAX_ADDR_STR_LEN]; memset(&msg, 0, sizeof(msg)); memset(&iv, 0, sizeof(iv)); memset(cmsgbuf, 0, sizeof(cmsgbuf)); iv.iov_base = &cs; iv.iov_len = sizeof(cs); msg.msg_iov = &iv; msg.msg_iovlen = 1; msg.msg_control = cmsgbuf; msg.msg_controllen = sizeof(cmsgbuf); do { ret = recvmsg(fd, &msg, MSG_NOSIGNAL); } while (ret < 0 && errno == EINTR); if (ret < 16 || (msg.msg_flags & (MSG_CTRUNC | MSG_OOB | MSG_ERRQUEUE)) != 0) haltest_error("Failed to accept connection\n"); for (cmsgptr = CMSG_FIRSTHDR(&msg); cmsgptr != NULL; cmsgptr = CMSG_NXTHDR(&msg, cmsgptr)) { int count; if (cmsgptr->cmsg_level != SOL_SOCKET || cmsgptr->cmsg_type != SCM_RIGHTS) continue; memcpy(&accepted_fd, CMSG_DATA(cmsgptr), sizeof(accepted_fd)); count = ((cmsgptr->cmsg_len - CMSG_LEN(0)) / sizeof(int)); if (count != 1) haltest_error("Failed to accept descriptors count=%d\n", count); break; } haltest_info("Incoming connection from %s channel %d status=%d fd=%d\n", bt_bdaddr_t2str(&cs.bd_addr, addr_str), cs.channel, cs.status, accepted_fd); poll_register_fd(accepted_fd, POLLIN, receive_from_client); }
static void connection_state_cb(btpan_connection_state_t state, bt_status_t error, const bt_bdaddr_t *bd_addr, int local_role, int remote_role) { haltest_info("%s: state=%s error=%s bd_addr=%s local_role=%s remote_role=%s\n", __func__, btpan_connection_state_t2str(state), bt_status_t2str(error), bt_bdaddr_t2str(bd_addr, last_used_addr), btpan_role_t2str(local_role), btpan_role_t2str(remote_role)); }
/* * Callback for connection state change. * state will have one of the values from bthh_connection_state_t */ static void connection_state_cb(bt_bdaddr_t *bd_addr, bthh_connection_state_t state) { char addr[MAX_ADDR_STR_LEN]; haltest_info("%s: bd_addr=%s connection_state=%s\n", __func__, bt_bdaddr_t2str(bd_addr, addr), bthh_connection_state_t2str(state)); if (state == BTHH_CONN_STATE_CONNECTED) strcpy(connected_device_addr, addr); }
/* Callback for connection state change. */ static void hf_client_connection_state_callback( bthf_client_connection_state_t state, unsigned int peer_feat, unsigned int chld_feat, bt_bdaddr_t *bd_addr) { haltest_info("%s: state=%s bd_addr=%s\n", __func__, bthf_client_connection_state_t2str(state), bt_bdaddr_t2str(bd_addr, last_addr)); haltest_info("\tpeer_features%s\n", pear_features_t2str(peer_feat)); haltest_info("\tchld_feat=%s\n", chld_features_t2str(chld_feat)); }
/* * Callback invoked when a remote device has requested to write to a * characteristic or descriptor. */ static void gatts_request_write_cb(int conn_id, int trans_id, bt_bdaddr_t *bda, int attr_handle, int offset, int length, bool need_rsp, bool is_prep, uint8_t *value) { char buf[MAX_ADDR_STR_LEN]; char valbuf[100]; haltest_info("%s: conn_id=%d trans_id=%d bda=%s attr_handle=0x%x offset=%d length=%d need_rsp=%d is_prep=%d value=%s\n", __func__, conn_id, trans_id, bt_bdaddr_t2str(bda, buf), attr_handle, offset, length, need_rsp, is_prep, array2str(value, length, valbuf, sizeof(valbuf))); }
/* Converts btgatt_notify_params_t to string */ static char *btgatt_notify_params_t2str(const btgatt_notify_params_t *data, char *buf) { char addr[MAX_ADDR_STR_LEN]; char srvc_id[MAX_SRVC_ID_STR_LEN]; char char_id[MAX_CHAR_ID_STR_LEN]; char value[MAX_HEX_VAL_STR_LEN]; sprintf(buf, "{bda=%s, srvc_id=%s, char_id=%s, val=%s, is_notify=%u}", bt_bdaddr_t2str(&data->bda, addr), btgatt_srvc_id_t2str(&data->srvc_id, srvc_id), btgatt_gatt_id_t2str(&data->char_id, char_id), array2str(data->value, data->len, value, sizeof(value)), data->is_notify); return buf; }
static void channel_state_cb(int app_id, bt_bdaddr_t *bd_addr, int index, int channel_id, bthl_channel_state_t state, int fd) { char addr[MAX_ADDR_STR_LEN]; haltest_info("%s: app_id=%d bd_addr=%s mdep_cfg_index=%d\n" "channel_id=%d channel_state=%s fd=%d\n", __func__, app_id, bt_bdaddr_t2str(bd_addr, addr), index, channel_id, bthl_channel_state_t2str(state), fd); if (app_id >= APP_ID_SIZE || index >= MDEP_CFG_SIZE || channel_id >= CHANNEL_ID_SIZE) { haltest_error("exceeds maximum limit"); return; } if (state == BTHL_CONN_STATE_CONNECTED) { app[app_id].mdep[index].channel[channel_id].fd = fd; /* * PTS expects dummy data on fd when it * connects in source role. */ if (app[app_id].mdep[index].role == BTHL_MDEP_ROLE_SOURCE) if (write(fd, "0", sizeof("0")) < 0) haltest_error("writing data on fd failed\n"); return; } if (state == BTHL_CONN_STATE_DISCONNECTED || state == BTHL_CONN_STATE_DESTROYED) { if (app[app_id].mdep[index].channel[channel_id].fd >= 0) { close(app[app_id].mdep[index].channel[channel_id].fd); app[app_id].mdep[index].channel[channel_id].fd = -1; } } }
static void ssp_request_cb(bt_bdaddr_t *remote_bd_addr, bt_bdname_t *bd_name, uint32_t cod, bt_ssp_variant_t pairing_variant, uint32_t pass_key) { static char prompt[50]; /* Store for command completion */ bt_bdaddr_t2str(remote_bd_addr, last_remote_addr); last_ssp_variant = pairing_variant; haltest_info("%s: remote_bd_addr=%s bd_name=%s cod=%06x pairing_variant=%s pass_key=%d\n", __func__, last_remote_addr, bd_name->name, cod, bt_ssp_variant_t2str(pairing_variant), pass_key); switch (pairing_variant) { case BT_SSP_VARIANT_PASSKEY_CONFIRMATION: sprintf(prompt, "Does other device show %d [Y/n] ?", pass_key); ssp_request_addr = *remote_bd_addr; ssp_request_variant = pairing_variant; ssp_request_pask_key = pass_key; terminal_prompt_for(prompt, ssp_request_yes_no_answer); break; case BT_SSP_VARIANT_CONSENT: sprintf(prompt, "Consent pairing [Y/n] ?"); ssp_request_addr = *remote_bd_addr; ssp_request_variant = pairing_variant; ssp_request_pask_key = 0; terminal_prompt_for(prompt, ssp_request_yes_no_answer); break; default: haltest_info("Not automatically handled\n"); break; } }
static void audio_state(btav_audio_state_t state, bt_bdaddr_t *bd_addr) { haltest_info("%s: audio_state=%s remote_bd_addr=%s\n", __func__, btav_audio_state_t2str(state), bt_bdaddr_t2str(bd_addr, last_addr)); }
static void remote_features_cb(bt_bdaddr_t *bd_addr, btrc_remote_features_t features) { haltest_info("%s: remote_bd_addr=%s features=%u\n", __func__, bt_bdaddr_t2str(bd_addr, last_addr), features); }
const char *bdaddr2str(const bt_bdaddr_t *bd_addr) { static char buf[MAX_ADDR_STR_LEN]; return bt_bdaddr_t2str(bd_addr, buf); }