1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 20 #ifndef H_BLE_SM_TEST_UTIL_ 21 #define H_BLE_SM_TEST_UTIL_ 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 struct ble_sm_test_passkey_info { 28 struct ble_sm_io passkey; 29 uint32_t exp_numcmp; 30 unsigned io_before_rx:1; 31 }; 32 33 struct ble_sm_test_params { 34 uint8_t init_addr_type; 35 uint8_t init_id_addr[6]; 36 uint8_t init_rpa[6]; 37 uint8_t resp_addr_type; 38 uint8_t resp_id_addr[6]; 39 uint8_t resp_rpa[6]; 40 struct ble_sm_test_passkey_info passkey_info; 41 42 struct ble_sm_sec_req sec_req; 43 struct ble_sm_pair_cmd pair_req; 44 struct ble_sm_pair_cmd pair_rsp; 45 struct ble_sm_pair_confirm confirm_req[20]; 46 struct ble_sm_pair_confirm confirm_rsp[20]; 47 struct ble_sm_pair_random random_req[20]; 48 struct ble_sm_pair_random random_rsp[20]; 49 struct ble_sm_id_info id_info_req; 50 struct ble_sm_id_info id_info_rsp; 51 struct ble_sm_id_addr_info id_addr_info_req; 52 struct ble_sm_id_addr_info id_addr_info_rsp; 53 struct ble_sm_sign_info sign_info_req; 54 struct ble_sm_sign_info sign_info_rsp; 55 struct ble_sm_pair_fail pair_fail; 56 57 int pair_alg; 58 unsigned authenticated:1; 59 60 /*** Secure connections fields. */ 61 uint8_t ltk[16]; 62 uint8_t our_priv_key[32]; 63 struct ble_sm_public_key public_key_req; 64 struct ble_sm_public_key public_key_rsp; 65 struct ble_sm_dhkey_check dhkey_check_req; 66 struct ble_sm_dhkey_check dhkey_check_rsp; 67 68 /*** Legacy fields. */ 69 uint8_t stk[16]; 70 struct ble_sm_enc_info enc_info_req; 71 struct ble_sm_enc_info enc_info_rsp; 72 struct ble_sm_master_id master_id_req; 73 struct ble_sm_master_id master_id_rsp; 74 }; 75 76 extern int ble_sm_test_gap_event; 77 extern int ble_sm_test_gap_status; 78 extern struct ble_gap_sec_state ble_sm_test_sec_state; 79 80 extern int ble_sm_test_store_obj_type; 81 extern union ble_store_key ble_sm_test_store_key; 82 extern union ble_store_value ble_sm_test_store_value; 83 84 void ble_sm_test_util_init(void); 85 int ble_sm_test_util_conn_cb(struct ble_gap_event *ctxt, void *arg); 86 void ble_sm_test_util_io_inject(struct ble_sm_test_passkey_info *passkey_info, 87 uint8_t cur_sm_state); 88 void ble_sm_test_util_io_inject_bad(uint16_t conn_handle, 89 uint8_t correct_io_act); 90 void ble_sm_test_util_io_check_pre( 91 struct ble_sm_test_passkey_info *passkey_info, 92 uint8_t cur_sm_state); 93 void ble_sm_test_util_io_check_post( 94 struct ble_sm_test_passkey_info *passkey_info, 95 uint8_t cur_sm_state); 96 void ble_sm_test_util_rx_sec_req(uint16_t conn_handle, 97 struct ble_sm_sec_req *cmd, 98 int exp_status); 99 void ble_sm_test_util_verify_tx_pair_fail(struct ble_sm_pair_fail *exp_cmd); 100 void ble_sm_test_util_us_lgcy_good(struct ble_sm_test_params *params); 101 void ble_sm_test_util_peer_fail_inval(int we_are_master, 102 uint8_t *init_addr, 103 uint8_t *resp_addr, 104 struct ble_sm_pair_cmd *pair_req, 105 struct ble_sm_pair_fail *pair_fail); 106 void ble_sm_test_util_peer_lgcy_fail_confirm( 107 uint8_t *init_addr, 108 uint8_t *resp_addr, 109 struct ble_sm_pair_cmd *pair_req, 110 struct ble_sm_pair_cmd *pair_rsp, 111 struct ble_sm_pair_confirm *confirm_req, 112 struct ble_sm_pair_confirm *confirm_rsp, 113 struct ble_sm_pair_random *random_req, 114 struct ble_sm_pair_random *random_rsp, 115 struct ble_sm_pair_fail *fail_rsp); 116 117 void ble_sm_test_util_peer_lgcy_good_once(struct ble_sm_test_params *params); 118 void ble_sm_test_util_peer_lgcy_good(struct ble_sm_test_params *params); 119 void ble_sm_test_util_peer_bonding_bad(uint16_t ediv, uint64_t rand_num); 120 void ble_sm_test_util_peer_sc_good(struct ble_sm_test_params *params); 121 void ble_sm_test_util_us_sc_good(struct ble_sm_test_params *params); 122 void ble_sm_test_util_us_fail_inval(struct ble_sm_test_params *params); 123 124 #ifdef __cplusplus 125 } 126 #endif 127 128 #endif 129