配对 Numerical Comparsion Pairing

wen sir · 13次点击 · 21小时前

6626数值比较配对过程参考以 ..\ble_app_simple工程为例.


1- 代码修改 参考 飘红加粗处

image.png

main.c


int main(void)
{
    struct ob_stack_param param =
    {
        .max_connection = OB_LE_HOST_CONNECTION_NB,
        .max_ext_adv_set = OB_LE_HOST_ADV_SET_NUM,
        .max_att_mtu = OB_LE_HOST_ATT_MTU,
        .max_gatt_serv_num = OB_LE_HOST_MAX_GATT_SERV_NUM,
        .max_gatt_write_cache = OB_LE_HOST_ATT_WRITE_CACHE_SIZE,
        .smp_sc_support = OB_LE_HOST_SC_PAIRING,
    };
    drv_wdt_init(0);
    board_init();
    hardware_init();
    drv_rf_init();
       
    evt_init();
    evt_timer_init();
    shell_init(NULL);
    nvds_init(0);
    extern void ebh_smp_fsm_config_per_sc(void);
    ebh_smp_fsm_config_per_sc();  //添加sc

    omble_init(&param);

....



\src\main\app_sec.c



#define PERIPHERAL_IOCAP  OB_SMP_IOCAP_DISP_YN//IO能力配置


static void app_sec_event_cb(uint16_t evt_id, const omble_evt_t *evt)
{
    if (evt_id == OB_GAP_EVT_CONNECTED)
    {
        log_debug("OB_GAP_EVT_CONNECTED(%d): %d\n", evt->gap.conn_idx, evt->gap.connected.adv_idx);
    }
    else if (evt_id == OB_GAP_EVT_DISCONNECTED)
    {
        log_debug("OB_GAP_EVT_DISCONNECTED 0x%02X\n", evt->gap.disconnected.reason);
    }
    else if (evt_id == OB_GAP_EVT_PIN_REQUEST)
    {
        log_debug("OB_GAP_EVT_PIN_REQUEST:%d\n", evt->gap.pin_request.type);
        ob_smp_pin_t pin_info;
        switch (evt->gap.pin_request.type)
        {
            case OB_SMP_PIN_TYPE_DIS:
                log_debug("show pin:%06d\n", evt->gap.pin_request.pin_code);
            case OB_SMP_PIN_TYPE_NONE:
                ob_gap_pin_response(evt->gap.conn_idx, true, &pin_info);
                break;
            case OB_SMP_PIN_TYPE_DIS_YN: //Numeric comparsion
               log_debug("\nOB_SMP_PIN_TYPE_DIS_YN pin:%06d\n", evt->gap.pin_request.pin_code);//需要显示在LCD上的的PIN
                ob_gap_pin_response(evt->gap.conn_idx, true,NULL); //用户点击输入,此处在输入Yes/No的事件中才发送。 这里是简单直接回复了
                break;
            case OB_SMP_PIN_TYPE_PK_REQ:
            case OB_SMP_PIN_TYPE_OOB_REQ:
            {
                break;
            }
        }
    }

    else if (evt_id == OB_GAP_EVT_BONDED)

    .....

    else if (evt_id == OB_GAP_EVT_PAIRING_REQUEST)
    {
        log_debug("OB_GAP_EVT_PAIRING_REQUEST\n");
        ob_pairing_param_t response;
        response.authreq.bond_flags = 1;
        response.authreq.mitm = 1;
        response.authreq.sc = 1;  //要启用SC
        response.oob_data_flag = 0;
        response.initiator_key_distribution = OB_SMP_DIST_BIT_ENC_KEY | OB_SMP_DIST_BIT_ID_KEY;
        response.responder_key_distribution = OB_SMP_DIST_BIT_ENC_KEY;
        response.io_capability = PERIPHERAL_IOCAP; //配置好IO
        ob_gap_pairing_response(evt->gap.conn_idx, &response);

    }

.....


被收藏 0  ∙  0 赞  
加入收藏
点赞
0 回复  
善言善语 (您需要 登录 后才能回复 没有账号 ?)

请先登录网站