void ble_sm_public_key_log(struct ble_sm_public_key *cmd) { BLE_HS_LOG(DEBUG, "x="); ble_hs_log_flat_buf(cmd->x, sizeof cmd->x); BLE_HS_LOG(DEBUG, "y="); ble_hs_log_flat_buf(cmd->y, sizeof cmd->y); }
void ble_sm_master_id_log(struct ble_sm_master_id *cmd) { /* These get logged separately to accommodate a bug in the va_args * implementation related to 64-bit integers. */ BLE_HS_LOG(DEBUG, "ediv=0x%04x ", cmd->ediv); BLE_HS_LOG(DEBUG, "rand=0x%016llx", cmd->rand_val); }
void ble_att_find_type_value_req_log(const struct ble_att_find_type_value_req *cmd) { BLE_HS_LOG(DEBUG, "start_handle=0x%04x end_handle=0x%04x attr_type=%d", cmd->bavq_start_handle, cmd->bavq_end_handle, cmd->bavq_attr_type); }
/** * Transmits an HCI ACL data packet. This function consumes the supplied mbuf, * regardless of the outcome. */ int host_hci_data_tx(struct ble_hs_conn *connection, struct os_mbuf *om) { int rc; /* XXX: Different transport mechanisms have different fragmentation * requirements. For now, never fragment. */ om = host_hci_data_hdr_prepend(om, connection->bhc_handle, BLE_HCI_PB_FIRST_NON_FLUSH); if (om == NULL) { return BLE_HS_ENOMEM; } BLE_HS_LOG(DEBUG, "host_hci_data_tx(): "); ble_hs_misc_log_mbuf(om); rc = ble_hs_tx_data(om); if (rc != 0) { return rc; } connection->bhc_outstanding_pkts++; return 0; }
void ble_sm_pair_cmd_log(struct ble_sm_pair_cmd *cmd) { BLE_HS_LOG(DEBUG, "io_cap=%d oob_data_flag=%d authreq=0x%02x " "mac_enc_key_size=%d init_key_dist=%d " "resp_key_dist=%d", cmd->io_cap, cmd->oob_data_flag, cmd->authreq, cmd->max_enc_key_size, cmd->init_key_dist, cmd->resp_key_dist); }
/** * Called when a data packet is received from the controller. This function * consumes the supplied mbuf, regardless of the outcome. * * @param om The incoming data packet, beginning with the * HCI ACL data header. * * @return 0 on success; nonzero on failure. */ int host_hci_data_rx(struct os_mbuf *om) { struct hci_data_hdr hci_hdr; struct ble_hs_conn *conn; ble_l2cap_rx_fn *rx_cb; struct os_mbuf *rx_buf; uint16_t handle; int rc; rc = host_hci_data_hdr_strip(om, &hci_hdr); if (rc == 0) { BLE_HS_LOG(DEBUG, "host_hci_data_rx(): handle=%u pb=%x len=%u data=", BLE_HCI_DATA_HANDLE(hci_hdr.hdh_handle_pb_bc), BLE_HCI_DATA_PB(hci_hdr.hdh_handle_pb_bc), hci_hdr.hdh_len); ble_hs_misc_log_mbuf(om); if (hci_hdr.hdh_len != OS_MBUF_PKTHDR(om)->omp_len) { rc = BLE_HS_EBADDATA; } else { handle = BLE_HCI_DATA_HANDLE(hci_hdr.hdh_handle_pb_bc); ble_hs_conn_lock(); conn = ble_hs_conn_find(handle); if (conn == NULL) { rc = BLE_HS_ENOTCONN; } else { rc = ble_l2cap_rx(conn, &hci_hdr, om, &rx_cb, &rx_buf); om = NULL; } ble_hs_conn_unlock(); } } os_mbuf_free_chain(om); if (rc == 0) { assert(rx_cb != NULL); assert(rx_buf != NULL); rc = rx_cb(handle, &rx_buf); os_mbuf_free_chain(rx_buf); } else if (rc == BLE_HS_EAGAIN) { /* More fragments on the way. */ rc = 0; } return rc; }
static int ble_sm_sc_ensure_keys_generated(void) { int rc; if (!ble_sm_sc_keys_generated) { rc = ble_sm_gen_pub_priv(ble_sm_sc_pub_key.u32, ble_sm_sc_priv_key.u32); if (rc != BLE_HS_ENONE) { return rc; } ble_sm_sc_keys_generated = TRUE; } BLE_HS_LOG(DEBUG, "our pubkey="); ble_hs_log_flat_buf(&ble_sm_sc_pub_key, sizeof ble_sm_sc_pub_key); BLE_HS_LOG(DEBUG, "\n"); BLE_HS_LOG(DEBUG, "our privkey="); ble_hs_log_flat_buf(&ble_sm_sc_priv_key, sizeof ble_sm_sc_priv_key); BLE_HS_LOG(DEBUG, "\n"); return BLE_HS_ENONE; }
static int ble_sm_sc_ensure_keys_generated(void) { int rc; if (!ble_sm_sc_keys_generated) { rc = ble_sm_gen_pub_priv(ble_sm_sc_pub_key.u32, ble_sm_sc_priv_key.u32); if (rc != 0) { return rc; } ble_sm_sc_keys_generated = 1; } BLE_HS_LOG(DEBUG, "our pubkey="); ble_hs_log_flat_buf(&ble_sm_sc_pub_key, 64); BLE_HS_LOG(DEBUG, "\n"); BLE_HS_LOG(DEBUG, "our privkey="); ble_hs_log_flat_buf(&ble_sm_sc_priv_key, 32); BLE_HS_LOG(DEBUG, "\n"); return 0; }
static struct os_mbuf * host_hci_data_hdr_prepend(struct os_mbuf *om, uint16_t handle, uint8_t pb_flag) { struct hci_data_hdr hci_hdr; hci_hdr.hdh_handle_pb_bc = host_hci_handle_pb_bc_join(handle, pb_flag, 0); htole16(&hci_hdr.hdh_len, OS_MBUF_PKTHDR(om)->omp_len); om = os_mbuf_prepend(om, sizeof hci_hdr); if (om == NULL) { return NULL; } memcpy(om->om_data, &hci_hdr, sizeof hci_hdr); BLE_HS_LOG(DEBUG, "host tx hci data; handle=%d length=%d\n", handle, le16toh(&hci_hdr.hdh_len)); return om; }
int host_hci_cmd_send(uint8_t ogf, uint8_t ocf, uint8_t len, void *cmddata) { int rc; uint8_t *cmd; uint16_t opcode; /* Don't allow multiple commands "in flight." */ assert(host_hci_outstanding_opcode == 0); rc = -1; cmd = os_memblock_get(&g_hci_cmd_pool); if (cmd) { opcode = (ogf << 10) | ocf; htole16(cmd, opcode); cmd[2] = len; if (len) { memcpy(cmd + BLE_HCI_CMD_HDR_LEN, cmddata, len); } rc = host_hci_cmd_transport(cmd); BLE_HS_LOG(DEBUG, "host_hci_cmd_send: ogf=0x%02x ocf=0x%02x len=%d\n", ogf, ocf, len); if (rc == 0) { host_hci_outstanding_opcode = opcode; } } /* Cancel ack callback if transmission failed. */ if (rc != 0) { ble_hci_sched_set_ack_cb(NULL, NULL); } else { STATS_INC(ble_hs_stats, hci_cmd); } return rc; }
void ble_att_prep_write_cmd_log(const struct ble_att_prep_write_cmd *cmd) { BLE_HS_LOG(DEBUG, "handle=0x%04x offset=%d", cmd->bapc_handle, cmd->bapc_offset); }
void ble_att_read_group_type_rsp_log(const struct ble_att_read_group_type_rsp *cmd) { BLE_HS_LOG(DEBUG, "length=%d", cmd->bagp_length); }
void ble_att_write_cmd_log(const struct ble_att_write_req *cmd) { BLE_HS_LOG(DEBUG, "handle=0x%04x", cmd->bawq_handle); }
void ble_att_read_blob_req_log(const struct ble_att_read_blob_req *cmd) { BLE_HS_LOG(DEBUG, "handle=0x%04x offset=%d", cmd->babq_handle, cmd->babq_offset); }
void ble_att_read_group_type_req_log(const struct ble_att_read_group_type_req *cmd) { BLE_HS_LOG(DEBUG, "start_handle=0x%04x end_handle=0x%04x", cmd->bagq_start_handle, cmd->bagq_end_handle); }
void ble_sm_sign_info_log(struct ble_sm_sign_info *cmd) { BLE_HS_LOG(DEBUG, "sig_key="); ble_hs_log_flat_buf(cmd->sig_key, sizeof cmd->sig_key); }
void ble_sm_enc_info_log(struct ble_sm_enc_info *cmd) { BLE_HS_LOG(DEBUG, "ltk="); ble_hs_log_flat_buf(cmd->ltk, sizeof cmd->ltk); }
void ble_att_mtu_cmd_log(const struct ble_att_mtu_cmd *cmd) { BLE_HS_LOG(DEBUG, "mtu=%d", cmd->bamc_mtu); }
void ble_att_find_info_req_log(const struct ble_att_find_info_req *cmd) { BLE_HS_LOG(DEBUG, "start_handle=0x%04x end_handle=0x%04x", cmd->bafq_start_handle, cmd->bafq_end_handle); }
void ble_sm_id_info_log(struct ble_sm_id_info *cmd) { BLE_HS_LOG(DEBUG, "irk="); ble_hs_log_flat_buf(cmd->irk, sizeof cmd->irk); }
static void ble_sm_dhkey_check_process(struct ble_sm_proc *proc, struct ble_sm_dhkey_check *cmd, struct ble_sm_result *res) { uint8_t exp_value[16]; const uint8_t *peer_ota_addr; const uint8_t *our_ota_addr; uint8_t peer_id_addr_type; uint8_t our_id_addr_type; uint8_t iocap[3]; uint8_t ioact; if (proc->flags & BLE_SM_PROC_F_INITIATOR) { ble_sm_sc_dhkey_check_iocap(&proc->pair_rsp, iocap); } else { ble_sm_sc_dhkey_check_iocap(&proc->pair_req, iocap); } ble_sm_sc_dhkey_addrs(proc, &our_id_addr_type, &our_ota_addr, &peer_id_addr_type, &peer_ota_addr); BLE_HS_LOG(DEBUG, "tk="); ble_hs_log_flat_buf(proc->tk, 32); BLE_HS_LOG(DEBUG, "\n"); res->app_status = ble_sm_alg_f6(proc->mackey, ble_sm_peer_pair_rand(proc), ble_sm_our_pair_rand(proc), proc->tk, iocap, peer_id_addr_type, peer_ota_addr, our_id_addr_type, our_ota_addr, exp_value); if (res->app_status != 0) { res->sm_err = BLE_SM_ERR_UNSPECIFIED; res->enc_cb = 1; return; } if (memcmp(cmd->value, exp_value, 16) != 0) { /* Random number mismatch. */ res->sm_err = BLE_SM_ERR_DHKEY; res->app_status = BLE_HS_SM_US_ERR(BLE_SM_ERR_DHKEY); res->enc_cb = 1; return; } ioact = ble_sm_sc_io_action(proc); if (ble_sm_ioact_state(ioact) == proc->state) { proc->flags |= BLE_SM_PROC_F_ADVANCE_ON_IO; } if (ble_sm_proc_can_advance(proc)) { if (proc->flags & BLE_SM_PROC_F_INITIATOR) { proc->state = BLE_SM_PROC_STATE_ENC_START; } res->execute = 1; } }
void ble_att_indicate_req_log(const struct ble_att_indicate_req *cmd) { BLE_HS_LOG(DEBUG, "handle=0x%04x", cmd->baiq_handle); }
void ble_sm_id_addr_info_log(struct ble_sm_id_addr_info *cmd) { BLE_HS_LOG(DEBUG, "addr_type=%d addr=", cmd->addr_type); BLE_HS_LOG_ADDR(DEBUG, cmd->bd_addr); }
void ble_sm_dhkey_check_log(struct ble_sm_dhkey_check *cmd) { BLE_HS_LOG(DEBUG, "value="); ble_hs_log_flat_buf(cmd->value, sizeof cmd->value); }
void ble_att_exec_write_req_log(const struct ble_att_exec_write_req *cmd) { BLE_HS_LOG(DEBUG, "flags=0x%02x", cmd->baeq_flags); }
void ble_att_find_info_rsp_log(const struct ble_att_find_info_rsp *cmd) { BLE_HS_LOG(DEBUG, "format=%d", cmd->bafp_format); }
void ble_att_notify_req_log(const struct ble_att_notify_req *cmd) { BLE_HS_LOG(DEBUG, "handle=0x%04x", cmd->banq_handle); }
void ble_sm_sec_req_log(struct ble_sm_sec_req *cmd) { BLE_HS_LOG(DEBUG, "authreq=0x%02x", cmd->authreq); }
void ble_att_error_rsp_log(const struct ble_att_error_rsp *cmd) { BLE_HS_LOG(DEBUG, "req_op=%d handle=0x%04x error_code=%d", cmd->baep_req_op, cmd->baep_handle, cmd->baep_error_code); }
void ble_sm_sc_random_rx(struct ble_sm_proc *proc, struct ble_sm_result *res) { uint8_t confirm_val[16]; uint8_t ia[6]; uint8_t ra[6]; uint8_t ioact; uint8_t iat; uint8_t rat; int rc; if (proc->flags & BLE_SM_PROC_F_INITIATOR || ble_sm_sc_responder_verifies_random(proc)) { BLE_HS_LOG(DEBUG, "tk="); ble_hs_log_flat_buf(proc->tk, 32); BLE_HS_LOG(DEBUG, "\n"); rc = ble_sm_alg_f4(proc->pub_key_peer.x, ble_sm_sc_pub_key.u8, ble_sm_peer_pair_rand(proc), proc->ri, confirm_val); if (rc != 0) { res->app_status = rc; res->sm_err = BLE_SM_ERR_UNSPECIFIED; res->enc_cb = 1; return; } if (memcmp(proc->confirm_peer, confirm_val, 16) != 0) { /* Random number mismatch. */ res->app_status = BLE_HS_SM_US_ERR(BLE_SM_ERR_CONFIRM_MISMATCH); res->sm_err = BLE_SM_ERR_CONFIRM_MISMATCH; res->enc_cb = 1; return; } } /* Calculate the mac key and ltk. */ ble_sm_ia_ra(proc, &iat, ia, &rat, ra); rc = ble_sm_alg_f5(proc->dhkey, proc->randm, proc->rands, iat, ia, rat, ra, proc->mackey, proc->ltk); if (rc != 0) { res->app_status = rc; res->sm_err = BLE_SM_ERR_UNSPECIFIED; res->enc_cb = 1; return; } /* Ensure the ltk gets persisted when the pairing procedure succeeds. */ memcpy(proc->our_keys.ltk, proc->ltk, sizeof proc->our_keys.ltk); proc->our_keys.ltk_valid = 1; proc->our_keys.ediv = 0; proc->our_keys.rand_val = 0; proc->our_keys.ediv_rand_valid = 1; memcpy(proc->peer_keys.ltk, proc->ltk, sizeof proc->peer_keys.ltk); proc->peer_keys.ltk_valid = 1; proc->peer_keys.ediv = 0; proc->peer_keys.rand_val = 0; proc->peer_keys.ediv_rand_valid = 1; if (proc->flags & BLE_SM_PROC_F_INITIATOR) { ble_sm_sc_random_advance(proc); ioact = ble_sm_sc_io_action(proc); if (ble_sm_ioact_state(ioact) == proc->state && !(proc->flags & BLE_SM_PROC_F_IO_INJECTED)) { res->passkey_params.action = ioact; BLE_HS_DBG_ASSERT(ioact == BLE_SM_IOACT_NUMCMP); ble_sm_sc_gen_numcmp(proc, res); } else { res->execute = 1; } } else { res->execute = 1; } }