static void acl_state_changed_cb(bt_status_t status, bt_bdaddr_t* remote_bd_addr, bt_acl_state_t state) { struct pdu_wbuf* wbuf; wbuf = create_pdu_wbuf(1 + /* status */ 6 + /* remote address */ 1, /* ACL state */ 0, NULL); if (!wbuf) return; init_pdu(&wbuf->buf.pdu, SERVICE_BT_CORE, OPCODE_ACL_STATE_CHANGED_NTF); if (append_to_pdu(&wbuf->buf.pdu, "C", (uint8_t)status) < 0) goto cleanup; if (append_bt_bdaddr_t(&wbuf->buf.pdu, remote_bd_addr) < 0) goto cleanup; if (append_to_pdu(&wbuf->buf.pdu, "C", (uint8_t)state) < 0) goto cleanup; if (run_task(send_ntf_pdu, wbuf) < 0) goto cleanup; return; cleanup: cleanup_pdu_wbuf(wbuf); }
static void pin_request_cb(bt_bdaddr_t* remote_bd_addr, bt_bdname_t* bd_name, uint32_t cod) { struct pdu_wbuf* wbuf; wbuf = create_pdu_wbuf(6 + /* remote address */ 249 + /* remote name */ 4, /* class of device */ 0, NULL); if (!wbuf) return; init_pdu(&wbuf->buf.pdu, SERVICE_BT_CORE, OPCODE_PIN_REQUEST_NTF); if (append_bt_bdaddr_t(&wbuf->buf.pdu, remote_bd_addr) < 0) goto cleanup; if (append_bt_bdname_t(&wbuf->buf.pdu, bd_name) < 0) goto cleanup; if (append_to_pdu(&wbuf->buf.pdu, "I", cod) < 0) goto cleanup; if (run_task(send_ntf_pdu, wbuf) < 0) goto cleanup; return; cleanup: cleanup_pdu_wbuf(wbuf); }
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) { struct pdu_wbuf* wbuf; wbuf = create_pdu_wbuf(6 + /* remote address */ 249 + /* remote name */ 4 + /* class of device */ 1 + /* paring variant */ 4, /* passkey */ 0, NULL); if (!wbuf) return; init_pdu(&wbuf->buf.pdu, SERVICE_BT_CORE, OPCODE_SSP_REQUEST_NTF); if (append_bt_bdaddr_t(&wbuf->buf.pdu, remote_bd_addr) < 0) goto cleanup; if (append_bt_bdname_t(&wbuf->buf.pdu, bd_name) < 0) goto cleanup; if (append_to_pdu(&wbuf->buf.pdu, "ICI", cod, (uint8_t)pairing_variant, pass_key) < 0) goto cleanup; if (run_task(send_ntf_pdu, wbuf) < 0) goto cleanup; return; cleanup: cleanup_pdu_wbuf(wbuf); }
long append_btrc_player_settings_t(struct pdu* pdu, const btrc_player_settings_t* settings) { long off; unsigned long i; off = append_to_pdu(pdu, "C", settings->num_attr); for (i = 0; (off >= 0) && (i < settings->num_attr); ++i) { off = append_to_pdu(pdu, "CC", settings->attr_ids[i], settings->attr_values[i]); } return off; }
long append_btrc_media_attr_t_array(struct pdu* pdu, const btrc_media_attr_t* attr, unsigned long num_attrs) { long off; unsigned long i; for (off = pdu->len, i = 0; (off >= 0) && (i < num_attrs); ++i) { off = append_to_pdu(pdu, "C", (uint8_t)attr[i]); } return off; }
static int register_module(const struct pdu* cmd) { uint8_t service; struct pdu_wbuf* wbuf; int (*handler)(const struct pdu*); if (read_pdu_at(cmd, 0, "C", &service) < 0) { return ERROR_PARM_INVALID; } if (g_service_handler[service]) { ALOGE("service 0x%x already registered", service); return ERROR_FAIL; } if (!g_register_service[service]) { ALOGE("invalid service id 0x%x", service); return ERROR_FAIL; } wbuf = create_pdu_wbuf(OPCODE_REGISTER_MODULE_RSP_SIZE, 0, NULL); if (!wbuf) { return ERROR_NOMEM; } handler = g_register_service[service](g_send_pdu); if (!handler) { goto err_register_service; } g_service_handler[service] = handler; init_pdu(&wbuf->buf.pdu, cmd->service, cmd->opcode); if (append_to_pdu(&wbuf->buf.pdu, "I", (uint32_t)PROTOCOL_VERSION) < 0) { goto err_append_to_pdu; } send_pdu(wbuf); return ERROR_NONE; err_append_to_pdu: err_register_service: destroy_pdu_wbuf(wbuf); return ERROR_FAIL; }
static void remote_device_properties_cb(bt_status_t status, bt_bdaddr_t* bd_addr, int num_properties, bt_property_t* properties) { bt_property_t* aligned_properties; struct pdu_wbuf* wbuf; properties = align_properties(properties, num_properties, &aligned_properties); if (!properties) return; fix_properties(bd_addr, num_properties, properties); wbuf = create_pdu_wbuf(1 + /* status */ 6 + /* address */ 1 + /* number of properties */ properties_length(num_properties, properties), 0, NULL); if (!wbuf) goto cleanup_properties; init_pdu(&wbuf->buf.pdu, SERVICE_BT_CORE, OPCODE_REMOTE_DEVICE_PROPERTIES_NTF); if (append_to_pdu(&wbuf->buf.pdu, "C", (uint8_t)status) < 0) goto cleanup; if (append_bt_bdaddr_t(&wbuf->buf.pdu, bd_addr) < 0) goto cleanup; if (append_bt_property_t_array(&wbuf->buf.pdu, properties, num_properties) < 0) goto cleanup; if (run_task(send_ntf_pdu, wbuf) < 0) goto cleanup; free(aligned_properties); return; cleanup: cleanup_pdu_wbuf(wbuf); cleanup_properties: free(aligned_properties); }
static void list_player_app_values_cb(btrc_player_attr_t attr_id) { struct pdu_wbuf* wbuf; wbuf = create_pdu_wbuf(1, /* player attribute */ 0, NULL); if (!wbuf) return; init_pdu(&wbuf->buf.pdu, SERVICE_BT_RC, OPCODE_LIST_PLAYER_APP_VALUES_NTF); if ((append_to_pdu(&wbuf->buf.pdu, "C", (uint8_t)attr_id) < 0)) goto cleanup; if (run_task(send_ntf_pdu, wbuf) < 0) goto cleanup; return; cleanup: cleanup_pdu_wbuf(wbuf); }
static void adapter_state_changed_cb(bt_state_t state) { struct pdu_wbuf* wbuf; wbuf = create_pdu_wbuf(1, /* state */ 0, NULL); if (!wbuf) return; init_pdu(&wbuf->buf.pdu, SERVICE_BT_CORE, OPCODE_ADAPTER_STATE_CHANGED_NTF); if (append_to_pdu(&wbuf->buf.pdu, "C", (uint8_t)state) < 0) goto cleanup; if (run_task(send_ntf_pdu, wbuf) < 0) goto cleanup; return; cleanup: cleanup_pdu_wbuf(wbuf); }
static void adapter_properties_cb(bt_status_t status, int num_properties, bt_property_t* properties) { bt_property_t* aligned_properties; struct pdu_wbuf* wbuf; properties = align_properties(properties, num_properties, &aligned_properties); if (!properties) return; wbuf = create_pdu_wbuf(1 + /* status */ 1 + /* number of properties */ properties_length(num_properties, properties), 0, NULL); if (!wbuf) goto cleanup_properties; init_pdu(&wbuf->buf.pdu, SERVICE_BT_CORE, OPCODE_ADAPTER_PROPERTIES_CHANGED_NTF); if (append_to_pdu(&wbuf->buf.pdu, "C", (uint8_t)status) < 0) goto cleanup; if (append_bt_property_t_array(&wbuf->buf.pdu, properties, num_properties) < 0) goto cleanup; if (run_task(send_ntf_pdu, wbuf) < 0) goto cleanup; free(aligned_properties); return; cleanup: cleanup_pdu_wbuf(wbuf); cleanup_properties: free(aligned_properties); }
static void passthrough_cmd_cb(int id, int key_state) { struct pdu_wbuf* wbuf; wbuf = create_pdu_wbuf(1 + /* id */ 1, /* state */ 0, NULL); if (!wbuf) return; init_pdu(&wbuf->buf.pdu, SERVICE_BT_RC, OPCODE_PASSTHROUGH_CMD_NTF); if (append_to_pdu(&wbuf->buf.pdu, "CC", (uint8_t)id, (uint8_t)key_state) < 0) goto cleanup; if (run_task(send_ntf_pdu, wbuf) < 0) goto cleanup; return; cleanup: cleanup_pdu_wbuf(wbuf); }
static void volume_change_cb(uint8_t volume, uint8_t ctype) { struct pdu_wbuf* wbuf; wbuf = create_pdu_wbuf(1 + /* volume */ 1, /* type */ 0, NULL); if (!wbuf) return; init_pdu(&wbuf->buf.pdu, SERVICE_BT_RC, OPCODE_VOLUME_CHANGE_NTF); if (append_to_pdu(&wbuf->buf.pdu, "CC", (uint8_t)volume, (uint8_t)ctype) < 0) goto cleanup; if (run_task(send_ntf_pdu, wbuf) < 0) goto cleanup; return; cleanup: cleanup_pdu_wbuf(wbuf); }
static void register_notification_cb(btrc_event_id_t event_id, uint32_t param) { struct pdu_wbuf* wbuf; wbuf = create_pdu_wbuf(1 + /* event id */ 4, /* parameter */ 0, NULL); if (!wbuf) return; init_pdu(&wbuf->buf.pdu, SERVICE_BT_RC, OPCODE_REGISTER_NOTIFICATION_NTF); if (append_to_pdu(&wbuf->buf.pdu, "CI", (uint8_t)event_id, param) < 0) goto cleanup; if (run_task(send_ntf_pdu, wbuf) < 0) goto cleanup; return; cleanup: cleanup_pdu_wbuf(wbuf); }
static void remote_features_cb(bt_bdaddr_t* bd_addr, btrc_remote_features_t features) { struct pdu_wbuf* wbuf; wbuf = create_pdu_wbuf(6 + /* address */ 1, /* feature bitmask */ 0, NULL); if (!wbuf) return; init_pdu(&wbuf->buf.pdu, SERVICE_BT_RC, OPCODE_REMOTE_FEATURES_NTF); if ((append_bt_bdaddr_t(&wbuf->buf.pdu, bd_addr) < 0) || (append_to_pdu(&wbuf->buf.pdu, "C", (uint8_t)features) < 0)) goto cleanup; if (run_task(send_ntf_pdu, wbuf) < 0) goto cleanup; return; cleanup: cleanup_pdu_wbuf(wbuf); }
static void get_element_attr_cb(uint8_t num_attr, btrc_media_attr_t* p_attrs) { struct pdu_wbuf* wbuf; wbuf = create_pdu_wbuf(1 + /* number of attributes */ num_attr, /* one byte per attribute */ 0, NULL); if (!wbuf) return; init_pdu(&wbuf->buf.pdu, SERVICE_BT_RC, OPCODE_GET_ELEMENT_ATTR_NTF); if ((append_to_pdu(&wbuf->buf.pdu, "C", num_attr) < 0) || (append_btrc_media_attr_t_array(&wbuf->buf.pdu, p_attrs, num_attr) < 0)) goto cleanup; if (run_task(send_ntf_pdu, wbuf) < 0) goto cleanup; return; cleanup: cleanup_pdu_wbuf(wbuf); }
static void get_player_app_value_cb(uint8_t num_attr, btrc_player_attr_t* p_attrs) { struct pdu_wbuf* wbuf; wbuf = create_pdu_wbuf(1 + /* number of player attributes */ num_attr, /* one byte per attribute */ 0, NULL); if (!wbuf) return; init_pdu(&wbuf->buf.pdu, SERVICE_BT_RC, OPCODE_GET_PLAYER_APP_VALUE_NTF); if ((append_to_pdu(&wbuf->buf.pdu, "C", num_attr) < 0) || (append_btrc_player_attr_t_array(&wbuf->buf.pdu, p_attrs, num_attr) < 0)) goto cleanup; if (run_task(send_ntf_pdu, wbuf) < 0) goto cleanup; return; cleanup: cleanup_pdu_wbuf(wbuf); }
static void le_test_mode_cb(bt_status_t status, uint16_t num_packets) { struct pdu_wbuf* wbuf; wbuf = create_pdu_wbuf(1 + /* status */ 2, /* number of packets */ 0, NULL); if (!wbuf) return; init_pdu(&wbuf->buf.pdu, SERVICE_BT_CORE, OPCODE_LE_TEST_MODE_NTF); if (append_to_pdu(&wbuf->buf.pdu, "CS", (uint8_t)status, (uint16_t)num_packets) < 0) goto cleanup; if (run_task(send_ntf_pdu, wbuf) < 0) goto cleanup; return; cleanup: cleanup_pdu_wbuf(wbuf); }
static void dut_mode_recv_cb(uint16_t opcode, uint8_t* buf, uint8_t len) { struct pdu_wbuf* wbuf; wbuf = create_pdu_wbuf(2 + /* opcode */ 1 + /* buffer length */ len, /* buffer */ 0, NULL); if (!wbuf) return; init_pdu(&wbuf->buf.pdu, SERVICE_BT_CORE, OPCODE_DUT_MODE_RECEIVE_NTF); if (append_to_pdu(&wbuf->buf.pdu, "SCm", opcode, len, buf, (size_t)len) < 0) goto cleanup; if (run_task(send_ntf_pdu, wbuf) < 0) goto cleanup; return; cleanup: cleanup_pdu_wbuf(wbuf); }
static void get_player_app_values_text_cb(uint8_t attr_id, uint8_t num_val, uint8_t* p_vals) { struct pdu_wbuf* wbuf; wbuf = create_pdu_wbuf(1 + /* attribute */ 1 + /* number of values */ num_val, /* one byte per value */ 0, NULL); if (!wbuf) return; init_pdu(&wbuf->buf.pdu, SERVICE_BT_RC, OPCODE_GET_PLAYER_APP_VALUES_TEXT_NTF); if (append_to_pdu(&wbuf->buf.pdu, "CCm", attr_id, num_val, p_vals, num_val) < 0) goto cleanup; if (run_task(send_ntf_pdu, wbuf) < 0) goto cleanup; return; cleanup: cleanup_pdu_wbuf(wbuf); }