void
ble_sm_sc_dhkey_check_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
                         struct ble_sm_result *res)
{
    struct ble_sm_dhkey_check cmd;
    struct ble_sm_proc *proc;
    struct ble_sm_proc *prev;

    res->app_status = ble_hs_mbuf_pullup_base(om, BLE_SM_DHKEY_CHECK_SZ);
    if (res->app_status != 0) {
        res->enc_cb = 1;
        res->sm_err = BLE_SM_ERR_UNSPECIFIED;
        return;
    }

    ble_sm_dhkey_check_parse((*om)->om_data, (*om)->om_len, &cmd);
    BLE_SM_LOG_CMD(0, "dhkey check", conn_handle, ble_sm_dhkey_check_log,
                   &cmd);

    ble_hs_lock();
    proc = ble_sm_proc_find(conn_handle, BLE_SM_PROC_STATE_DHKEY_CHECK, -1,
                            &prev);
    if (proc == NULL) {
        res->app_status = BLE_HS_ENOENT;
    } else {
        ble_sm_dhkey_check_process(proc, &cmd, res);
    }
    ble_hs_unlock();
}
Beispiel #2
0
/* XXX: Should not require locked. */
int
ble_sm_pair_fail_tx(uint16_t conn_handle, uint8_t reason)
{
    struct ble_sm_pair_fail cmd;
    struct os_mbuf *txom;
    int rc;

    BLE_HS_DBG_ASSERT(reason > 0 && reason < BLE_SM_ERR_MAX_PLUS_1);

    rc = ble_sm_init_req(BLE_SM_PAIR_FAIL_SZ, &txom);
    if (rc != BLE_HS_ENONE) {
        return BLE_HS_ENOMEM;
    }

    cmd.reason = reason;

    ble_sm_pair_fail_write(txom->om_data, txom->om_len, &cmd);
    BLE_SM_LOG_CMD(TRUE, "fail", conn_handle, ble_sm_pair_fail_log, &cmd);

    rc = ble_sm_tx(conn_handle, txom);
    if (rc != BLE_HS_ENONE) {
        return rc;
    }

    return BLE_HS_ENONE;
}
Beispiel #3
0
int
ble_sm_pair_random_tx(uint16_t conn_handle, struct ble_sm_pair_random *cmd)
{
    struct os_mbuf *txom;
    int rc;

    rc = ble_sm_init_req(BLE_SM_PAIR_RANDOM_SZ, &txom);
    if (rc != BLE_HS_ENONE) {
        return BLE_HS_ENOMEM;
    }

    ble_sm_pair_random_write(txom->om_data, txom->om_len, cmd);
    BLE_SM_LOG_CMD(TRUE, "random", conn_handle, ble_sm_pair_random_log, cmd);

    rc = ble_sm_tx(conn_handle, txom);
    if (rc != BLE_HS_ENONE) {
        return rc;
    }

    return BLE_HS_ENONE;
}
Beispiel #4
0
int
ble_sm_sec_req_tx(uint16_t conn_handle, struct ble_sm_sec_req *cmd)
{
    struct os_mbuf *txom;
    int rc;

    rc = ble_sm_init_req(BLE_SM_SEC_REQ_SZ, &txom);
    if (rc != BLE_HS_ENONE) {
        return BLE_HS_ENOMEM;
    }

    ble_sm_sec_req_write(txom->om_data, txom->om_len, cmd);

    BLE_SM_LOG_CMD(TRUE, "sec req", conn_handle, ble_sm_sec_req_log, cmd);

    rc = ble_sm_tx(conn_handle, txom);
    if (rc != BLE_HS_ENONE) {
        return rc;
    }

    return BLE_HS_ENONE;
}
Beispiel #5
0
int
ble_sm_sign_info_tx(uint16_t conn_handle, struct ble_sm_sign_info *cmd)
{
    struct os_mbuf *txom;
    int rc;

    BLE_SM_LOG_CMD(TRUE, "sign info", conn_handle, ble_sm_sign_info_log, cmd);

    rc = ble_sm_init_req(BLE_SM_SIGN_INFO_SZ, &txom);
    if (rc != BLE_HS_ENONE) {
        return BLE_HS_ENOMEM;
    }

    ble_sm_sign_info_write(txom->om_data, txom->om_len, cmd);

    rc = ble_sm_tx(conn_handle, txom);
    if (rc != BLE_HS_ENONE) {
        return rc;
    }

    return BLE_HS_ENONE;
}
Beispiel #6
0
int
ble_sm_dhkey_check_tx(uint16_t conn_handle, struct ble_sm_dhkey_check *cmd)
{
    struct os_mbuf *txom;
    int rc;

    rc = ble_sm_init_req(BLE_SM_DHKEY_CHECK_SZ, &txom);
    if (rc != BLE_HS_ENONE) {
        return BLE_HS_ENOMEM;
    }

    rc = ble_sm_dhkey_check_write(txom->om_data, txom->om_len, cmd);
    assert(rc == BLE_HS_ENONE);

    BLE_SM_LOG_CMD(TRUE, "dhkey check", conn_handle, ble_sm_dhkey_check_log, cmd);

    rc = ble_sm_tx(conn_handle, txom);
    if (rc != BLE_HS_ENONE) {
        return rc;
    }

    return BLE_HS_ENONE;
}
Beispiel #7
0
int
ble_sm_public_key_tx(uint16_t conn_handle, struct ble_sm_public_key *cmd)
{
    struct os_mbuf *txom;
    int rc;

    rc = ble_sm_init_req(BLE_SM_PUBLIC_KEY_SZ, &txom);
    if (rc != BLE_HS_ENONE) {
        return BLE_HS_ENOMEM;
    }

    rc = ble_sm_public_key_write(txom->om_data, txom->om_len, cmd);
    assert(rc == BLE_HS_ENONE);

    BLE_SM_LOG_CMD(TRUE, "public key", conn_handle, ble_sm_public_key_log, cmd);

    rc = ble_sm_tx(conn_handle, txom);
    if (rc != BLE_HS_ENONE) {
        return rc;
    }

    return BLE_HS_ENONE;
}
Beispiel #8
0
int
ble_sm_master_id_tx(uint16_t conn_handle, struct ble_sm_master_id *cmd)
{
    struct os_mbuf *txom;
    int rc;

    rc = ble_sm_init_req(BLE_SM_MASTER_ID_SZ, &txom);
    if (rc != BLE_HS_ENONE) {
        return BLE_HS_ENOMEM;
    }

    txom->om_data[0] = BLE_SM_OP_MASTER_ID;
    htole16(txom->om_data + 1, cmd->ediv);
    htole64(txom->om_data + 3, cmd->rand_val);

    BLE_SM_LOG_CMD(TRUE, "master id", conn_handle, ble_sm_master_id_log, cmd);

    rc = ble_sm_tx(conn_handle, txom);
    if (rc != BLE_HS_ENONE) {
        return rc;
    }

    return BLE_HS_ENONE;
}
Beispiel #9
0
int
ble_sm_pair_cmd_tx(uint16_t conn_handle, int is_req,
                   struct ble_sm_pair_cmd *cmd)
{
    struct os_mbuf *txom;
    int rc;

    rc = ble_sm_init_req(BLE_SM_PAIR_CMD_SZ, &txom);
    if (rc != BLE_HS_ENONE) {
        return BLE_HS_ENOMEM;
    }

    ble_sm_pair_cmd_write(txom->om_data, txom->om_len, is_req, cmd);
    BLE_SM_LOG_CMD(TRUE, is_req ? "pair req" : "pair rsp", conn_handle,
                   ble_sm_pair_cmd_log, cmd);
    BLE_HS_DBG_ASSERT(ble_sm_pair_cmd_is_valid(cmd));

    rc = ble_sm_tx(conn_handle, txom);
    if (rc != BLE_HS_ENONE) {
        return rc;
    }

    return BLE_HS_ENONE;
}
void
ble_sm_sc_public_key_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
                        struct ble_sm_result *res)
{
    struct ble_sm_public_key cmd;
    struct ble_sm_proc *proc;
    struct ble_sm_proc *prev;
    uint8_t ioact;
    int rc;

    res->app_status = ble_hs_mbuf_pullup_base(om, BLE_SM_PUBLIC_KEY_SZ);
    if (res->app_status != 0) {
        res->enc_cb = 1;
        return;
    }

    res->app_status = ble_sm_sc_ensure_keys_generated();
    if (res->app_status != 0) {
        res->enc_cb = 1;
        res->sm_err = BLE_SM_ERR_UNSPECIFIED;
        return;
    }

    ble_sm_public_key_parse((*om)->om_data, (*om)->om_len, &cmd);
    BLE_SM_LOG_CMD(0, "public key", conn_handle, ble_sm_public_key_log, &cmd);

    ble_hs_lock();
    proc = ble_sm_proc_find(conn_handle, BLE_SM_PROC_STATE_PUBLIC_KEY, -1,
                            &prev);
    if (proc == NULL) {
        res->app_status = BLE_HS_ENOENT;
        res->sm_err = BLE_SM_ERR_UNSPECIFIED;
    } else {
        proc->pub_key_peer = cmd;
        rc = ble_sm_alg_gen_dhkey(proc->pub_key_peer.x,
                                  proc->pub_key_peer.y,
                                  ble_sm_sc_priv_key.u32,
                                  proc->dhkey);
        if (rc != 0) {
            res->app_status = BLE_HS_SM_US_ERR(BLE_SM_ERR_DHKEY);
            res->sm_err = BLE_SM_ERR_DHKEY;
            res->enc_cb = 1;
        } else {
            if (proc->flags & BLE_SM_PROC_F_INITIATOR) {
                proc->state = BLE_SM_PROC_STATE_CONFIRM;

                ioact = ble_sm_sc_io_action(proc);
                if (ble_sm_ioact_state(ioact) == proc->state) {
                    res->passkey_params.action = ioact;
                }

                if (ble_sm_proc_can_advance(proc) &&
                    ble_sm_sc_initiator_txes_confirm(proc)) {

                    res->execute = 1;
                }
            } else {
                res->execute = 1;
            }
        }
    }
    ble_hs_unlock();
}