srsLTE/srsue/hdr/stack/upper/usim.h

136 lines
5.0 KiB
C
Raw Normal View History

2019-04-26 12:27:38 -07:00
/*
* Copyright 2013-2019 Software Radio Systems Limited
2017-05-18 03:52:29 -07:00
*
2019-04-26 12:27:38 -07:00
* This file is part of srsLTE.
2017-05-18 03:52:29 -07:00
*
2019-04-26 12:27:38 -07:00
* srsLTE is free software: you can redistribute it and/or modify
2017-05-18 03:52:29 -07:00
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
2019-04-26 12:27:38 -07:00
* srsLTE is distributed in the hope that it will be useful,
2017-05-18 03:52:29 -07:00
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* A copy of the GNU Affero General Public License can be found in
* the LICENSE file in the top-level directory of this distribution
* and at http://www.gnu.org/licenses/.
*
*/
2018-03-31 10:04:04 -07:00
#ifndef SRSUE_USIM_H
#define SRSUE_USIM_H
2017-05-18 03:52:29 -07:00
#include "srslte/common/common.h"
#include "srslte/common/log.h"
#include "srslte/common/security.h"
#include "srslte/interfaces/ue_interfaces.h"
#include "usim_base.h"
#include <string>
2017-05-18 03:52:29 -07:00
namespace srsue {
class usim : public usim_base
2017-05-18 03:52:29 -07:00
{
public:
usim(srslte::log* log_);
int init(usim_args_t* args);
2017-05-18 03:52:29 -07:00
void stop();
// NAS interface
2017-11-23 10:42:48 -08:00
std::string get_imsi_str();
std::string get_imei_str();
bool get_imsi_vec(uint8_t* imsi_, uint32_t n);
bool get_imei_vec(uint8_t* imei_, uint32_t n);
bool get_home_plmn_id(srslte::plmn_id_t* home_plmn_id);
2017-05-18 03:52:29 -07:00
auth_result_t generate_authentication_response(uint8_t* rand,
uint8_t* autn_enb,
uint16_t mcc,
uint16_t mnc,
uint8_t* res,
int* res_len,
uint8_t* k_asme);
void generate_nas_keys(uint8_t* k_asme,
uint8_t* k_nas_enc,
uint8_t* k_nas_int,
srslte::CIPHERING_ALGORITHM_ID_ENUM cipher_algo,
srslte::INTEGRITY_ALGORITHM_ID_ENUM integ_algo);
2017-05-18 03:52:29 -07:00
// RRC interface
void generate_as_keys(uint8_t* k_asme,
uint32_t count_ul,
uint8_t* k_rrc_enc,
uint8_t* k_rrc_int,
uint8_t* k_up_enc,
uint8_t* k_up_int,
srslte::CIPHERING_ALGORITHM_ID_ENUM cipher_algo,
srslte::INTEGRITY_ALGORITHM_ID_ENUM integ_algo);
2017-05-18 03:52:29 -07:00
void generate_as_keys_ho(uint32_t pci,
uint32_t earfcn,
int ncc,
uint8_t* k_rrc_enc,
uint8_t* k_rrc_int,
uint8_t* k_up_enc,
uint8_t* k_up_int,
2017-11-23 10:46:34 -08:00
srslte::CIPHERING_ALGORITHM_ID_ENUM cipher_algo,
srslte::INTEGRITY_ALGORITHM_ID_ENUM integ_algo);
2017-05-18 03:52:29 -07:00
private:
auth_result_t gen_auth_res_milenage(uint8_t* rand,
uint8_t* autn_enb,
uint16_t mcc,
uint16_t mnc,
uint8_t* res,
int* res_len,
uint8_t* k_asme);
auth_result_t gen_auth_res_xor(uint8_t* rand,
uint8_t* autn_enb,
uint16_t mcc,
uint16_t mnc,
uint8_t* res,
int* res_len,
uint8_t* k_asme);
void str_to_hex(std::string str, uint8_t* hex);
2017-05-18 03:52:29 -07:00
srslte::log* usim_log = nullptr;
2017-05-18 03:52:29 -07:00
// User data
auth_algo_t auth_algo = auth_algo_milenage;
uint8_t amf[2] = {}; // 3GPP 33.102 v10.0.0 Annex H
uint8_t op[16] = {};
uint8_t opc[16] = {};
uint64_t imsi = 0;
uint64_t imei = 0;
uint8_t k[16] = {};
2017-05-18 03:52:29 -07:00
2017-11-23 10:42:48 -08:00
std::string imsi_str;
std::string imei_str;
2017-05-18 03:52:29 -07:00
// Security variables
uint8_t rand[16] = {};
uint8_t ck[16] = {};
uint8_t ik[16] = {};
uint8_t ak[6] = {};
uint8_t mac[8] = {};
uint8_t autn[16] = {};
uint8_t k_asme[32] = {};
uint8_t nh[32] = {};
uint8_t k_enb_initial[32] = {};
uint8_t k_enb[32] = {};
uint8_t k_enb_star[32] = {};
uint32_t current_ncc = 0;
bool is_first_ncc = false;
bool initiated = false;
2017-05-18 03:52:29 -07:00
};
} // namespace srsue
2018-03-31 10:04:04 -07:00
#endif // SRSUE_USIM_H