|
|
|
@ -25,35 +25,37 @@
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include "upper/usim.h"
|
|
|
|
|
#include "upper/nas.h"
|
|
|
|
|
#include "srslte/upper/rlc.h"
|
|
|
|
|
#include "upper/rrc.h"
|
|
|
|
|
#include "mac/mac.h"
|
|
|
|
|
#include "srslte/common/log_filter.h"
|
|
|
|
|
#include "srslte/upper/pdcp_entity.h"
|
|
|
|
|
#include "srslte/upper/pdcp.h"
|
|
|
|
|
#include "srslte/common/log_stdout.h"
|
|
|
|
|
#include "srslte/interfaces/ue_interfaces.h"
|
|
|
|
|
#include "srslte/common/bcd_helpers.h"
|
|
|
|
|
|
|
|
|
|
using namespace srsue;
|
|
|
|
|
|
|
|
|
|
using namespace srsue;
|
|
|
|
|
|
|
|
|
|
#define LCID 1
|
|
|
|
|
|
|
|
|
|
uint8_t pdu1[] = {
|
|
|
|
|
0x03, 0x22, 0x16, 0x15, 0xe8 , 0x00 , 0x00 , 0x03 , 0x13 , 0xb0 , 0x00 , 0x02 , 0x90 , 0x08,
|
|
|
|
|
0x79, 0xf0, 0x00, 0x00, 0x40 , 0xb5 , 0x01 , 0x25 , 0x40 , 0xcc , 0x1d , 0x08 , 0x04 , 0x3c , 0x18 , 0x00,
|
|
|
|
|
0x4c, 0x02, 0x20, 0x0f, 0xa8 , 0x00 , 0x65 , 0x48 , 0x07 , 0x04 , 0x04 , 0x24 , 0x1c , 0x19 , 0x05 , 0x41,
|
|
|
|
|
0x39, 0x39, 0x4d, 0x38, 0x14 , 0x04 , 0x28 , 0xd1 , 0x5e , 0x6d , 0x78 , 0x13 , 0xfb , 0xf9 , 0x01 , 0xb1,
|
|
|
|
|
0x40, 0x2f, 0xd8, 0x4c, 0x02 , 0x20 , 0x00 , 0x5b , 0x78 , 0x00 , 0x07 , 0xa1 , 0x25 , 0xa9 , 0xc1 , 0x3f,
|
|
|
|
|
0xd9, 0x40, 0x41, 0xf5, 0x1b , 0x58 , 0x2f , 0x27 , 0x28 , 0xa0 , 0xed , 0xde , 0x54 , 0x43 , 0x48 , 0xc0,
|
|
|
|
|
0x56, 0xcc, 0x00, 0x02, 0x84 , 0x00 , 0x42 , 0x0a , 0xf1 , 0x63 };
|
|
|
|
|
uint8_t auth_request_pdu[] = { 0x07, 0x52, 0x01, 0x17, 0xf2, 0x2b, 0x2b, 0xaa, 0x2c, 0x53,
|
|
|
|
|
0x52, 0xf1, 0xaf, 0x2e, 0x2f, 0x6f, 0x72, 0xd0, 0x54, 0x10,
|
|
|
|
|
0x18, 0xee, 0x79, 0x35, 0x25, 0x3b, 0x90, 0x01, 0x17, 0xe3,
|
|
|
|
|
0x09, 0x18, 0xee, 0x3b, 0xa5, 0x24 };
|
|
|
|
|
|
|
|
|
|
uint32_t PDU1_LEN = 104;
|
|
|
|
|
uint8_t sec_mode_command_pdu[] = { 0x37, 0x45, 0x62, 0x29, 0xdf, 0x00, 0x07, 0x5d, 0x02, 0x01,
|
|
|
|
|
0x02, 0x80, 0xe0, 0xc1 };
|
|
|
|
|
|
|
|
|
|
uint16 mcc = 61441;
|
|
|
|
|
uint16 mnc = 65281;
|
|
|
|
|
|
|
|
|
|
#define LCID 3
|
|
|
|
|
using namespace srslte;
|
|
|
|
|
|
|
|
|
|
namespace srsue {
|
|
|
|
|
namespace srslte {
|
|
|
|
|
|
|
|
|
|
// fake classes
|
|
|
|
|
class pdcp_dummy : public rrc_interface_pdcp
|
|
|
|
@ -63,121 +65,154 @@ public:
|
|
|
|
|
void write_pdu_bcch_bch(byte_buffer_t *pdu) {}
|
|
|
|
|
void write_pdu_bcch_dlsch(byte_buffer_t *pdu) {}
|
|
|
|
|
void write_pdu_pcch(byte_buffer_t *pdu) {}
|
|
|
|
|
std::string get_rb_name(uint32_t lcid) { return std::string("lcid"); }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class rrc_dummy : public rrc_interface_nas
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
void write_sdu(uint32_t lcid, byte_buffer_t *sdu)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
printf("NAS generated SDU (len=%d):\n", sdu->N_bytes);
|
|
|
|
|
last_sdu_len = sdu->N_bytes;
|
|
|
|
|
srslte_vec_fprint_byte(stdout, sdu->msg, sdu->N_bytes);
|
|
|
|
|
}
|
|
|
|
|
std::string get_rb_name(uint32_t lcid) { return std::string("lcid"); }
|
|
|
|
|
uint32_t get_last_sdu_len() { return last_sdu_len; }
|
|
|
|
|
|
|
|
|
|
uint16_t get_mcc() { return 0x11; }
|
|
|
|
|
uint16_t get_mnc() { return 0xff; }
|
|
|
|
|
void enable_capabilities() {
|
|
|
|
|
void plmn_search() {};
|
|
|
|
|
void plmn_select(LIBLTE_RRC_PLMN_IDENTITY_STRUCT plmn_id) {};
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
uint16_t get_mcc() { return mcc; }
|
|
|
|
|
uint16_t get_mnc() { return mnc; }
|
|
|
|
|
void enable_capabilities() {}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
uint32_t last_sdu_len;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class gw_dummy : public gw_interface_nas, public gw_interface_pdcp
|
|
|
|
|
{
|
|
|
|
|
error_t setup_if_addr(uint32_t ip_addr, char *err_str) {}
|
|
|
|
|
error_t setup_if_addr(uint32_t ip_addr, char *err_str) { return ERROR_NONE; }
|
|
|
|
|
void write_pdu(uint32_t lcid, byte_buffer_t *pdu) {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class usim_dummy : public usim_interface_nas
|
|
|
|
|
{
|
|
|
|
|
void get_imsi_vec(uint8_t* imsi_, uint32_t n){
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
void get_imei_vec(uint8_t* imei_, uint32_t n){
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
void generate_authentication_response(uint8_t *rand,
|
|
|
|
|
uint8_t *autn_enb,
|
|
|
|
|
uint16_t mcc,
|
|
|
|
|
uint16_t mnc,
|
|
|
|
|
bool *net_valid,
|
|
|
|
|
uint8_t *res){
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void generate_nas_keys(uint8_t *k_nas_enc,
|
|
|
|
|
uint8_t *k_nas_int,
|
|
|
|
|
CIPHERING_ALGORITHM_ID_ENUM cipher_algo,
|
|
|
|
|
INTEGRITY_ALGORITHM_ID_ENUM integ_algo){
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
|
int security_command_test()
|
|
|
|
|
{
|
|
|
|
|
srslte::log_stdout nas_log("NAS");
|
|
|
|
|
srslte::log_stdout pdcp_entity_log("PDCP");
|
|
|
|
|
srslte::log_stdout rrc_log("RRC");
|
|
|
|
|
srslte::log_stdout mac_log("MAC");
|
|
|
|
|
|
|
|
|
|
int ret = SRSLTE_ERROR;
|
|
|
|
|
srslte::log_filter nas_log("NAS");
|
|
|
|
|
srslte::log_filter rrc_log("RRC");
|
|
|
|
|
srslte::log_filter mac_log("MAC");
|
|
|
|
|
srslte::log_filter usim_log("USIM");
|
|
|
|
|
|
|
|
|
|
nas_log.set_level(srslte::LOG_LEVEL_DEBUG);
|
|
|
|
|
pdcp_entity_log.set_level(srslte::LOG_LEVEL_DEBUG);
|
|
|
|
|
rrc_log.set_level(srslte::LOG_LEVEL_DEBUG);
|
|
|
|
|
|
|
|
|
|
nas_log.set_hex_limit(100000);
|
|
|
|
|
rrc_log.set_hex_limit(100000);
|
|
|
|
|
|
|
|
|
|
usim_dummy usim;
|
|
|
|
|
rrc_dummy rrc_dummy;
|
|
|
|
|
gw_dummy gw;
|
|
|
|
|
|
|
|
|
|
pdcp_dummy pdcp_dummy;
|
|
|
|
|
|
|
|
|
|
usim_args_t args;
|
|
|
|
|
args.algo = "xor";
|
|
|
|
|
args.amf = "9001";
|
|
|
|
|
args.imei = "353490069873319";
|
|
|
|
|
args.imsi = "001010123456789";
|
|
|
|
|
args.k = "00112233445566778899aabbccddeeff";
|
|
|
|
|
args.op = "63BFA50EE6523365FF14C1F45F88737D";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// init USIM
|
|
|
|
|
srsue::usim usim;
|
|
|
|
|
bool net_valid;
|
|
|
|
|
uint8_t res[16];
|
|
|
|
|
usim.init(&args, &usim_log);
|
|
|
|
|
|
|
|
|
|
buffer_pool *pool;
|
|
|
|
|
pool = buffer_pool::get_instance();
|
|
|
|
|
srslte::byte_buffer_pool *pool;
|
|
|
|
|
pool = byte_buffer_pool::get_instance();
|
|
|
|
|
|
|
|
|
|
srsue::nas nas;
|
|
|
|
|
nas.init(&usim, &rrc_dummy, &gw, &nas_log);
|
|
|
|
|
srslte_nas_config_t cfg;
|
|
|
|
|
nas.init(&usim, &rrc_dummy, &gw, &nas_log, cfg);
|
|
|
|
|
|
|
|
|
|
// push auth request PDU to NAS to generate security context
|
|
|
|
|
byte_buffer_t* tmp = pool->allocate();
|
|
|
|
|
memcpy(tmp->msg, auth_request_pdu, sizeof(auth_request_pdu));
|
|
|
|
|
tmp->N_bytes = sizeof(auth_request_pdu);
|
|
|
|
|
nas.write_pdu(LCID, tmp);
|
|
|
|
|
|
|
|
|
|
// TODO: add check for authentication response
|
|
|
|
|
|
|
|
|
|
// reuse buffer for security mode command
|
|
|
|
|
memcpy(tmp->msg, sec_mode_command_pdu, sizeof(sec_mode_command_pdu));
|
|
|
|
|
tmp->N_bytes = sizeof(sec_mode_command_pdu);
|
|
|
|
|
nas.write_pdu(LCID, tmp);
|
|
|
|
|
|
|
|
|
|
byte_buffer_t* tmp = pool_allocate;
|
|
|
|
|
memcpy(tmp->msg, &pdu1[0], PDU1_LEN);
|
|
|
|
|
tmp->N_bytes = PDU1_LEN;
|
|
|
|
|
// check length of generated NAS SDU
|
|
|
|
|
if (rrc_dummy.get_last_sdu_len() > 3) {
|
|
|
|
|
ret = SRSLTE_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//byte_buffer_t tmp2;
|
|
|
|
|
//memcpy(tmp2.msg, &pdu1[0], PDU1_LEN);
|
|
|
|
|
//tmp2.N_bytes = PDU1_LEN;
|
|
|
|
|
pool->cleanup();
|
|
|
|
|
|
|
|
|
|
//srsue::mac mac;
|
|
|
|
|
//mac.init(NULL, NULL, NULL, &mac_log);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
srsue::rrc rrc;
|
|
|
|
|
rrc.init(NULL, NULL, NULL, NULL, &nas, NULL, NULL, &rrc_log);
|
|
|
|
|
//rrc.init(&phy, &mac, &rlc, &pdcp, &nas, &usim, &mac, &rrc_log);
|
|
|
|
|
|
|
|
|
|
int mme_attach_request_test()
|
|
|
|
|
{
|
|
|
|
|
int ret = SRSLTE_ERROR;
|
|
|
|
|
srslte::log_filter nas_log("NAS");
|
|
|
|
|
srslte::log_filter rrc_log("RRC");
|
|
|
|
|
srslte::log_filter mac_log("MAC");
|
|
|
|
|
srslte::log_filter usim_log("USIM");
|
|
|
|
|
|
|
|
|
|
srsue::pdcp_entity pdcp_entity;
|
|
|
|
|
pdcp_entity.init(NULL, &rrc, &gw, &pdcp_entity_log, RB_ID_SRB1, NULL);
|
|
|
|
|
nas_log.set_level(srslte::LOG_LEVEL_DEBUG);
|
|
|
|
|
rrc_log.set_level(srslte::LOG_LEVEL_DEBUG);
|
|
|
|
|
nas_log.set_hex_limit(100000);
|
|
|
|
|
rrc_log.set_hex_limit(100000);
|
|
|
|
|
|
|
|
|
|
pdcp_entity.write_pdu(tmp);
|
|
|
|
|
rrc_dummy rrc_dummy;
|
|
|
|
|
gw_dummy gw;
|
|
|
|
|
srsue::usim usim;
|
|
|
|
|
usim_args_t args;
|
|
|
|
|
args.algo = "xor";
|
|
|
|
|
args.amf = "9001";
|
|
|
|
|
args.imei = "353490069873319";
|
|
|
|
|
args.imsi = "001010123456789";
|
|
|
|
|
args.k = "00112233445566778899aabbccddeeff";
|
|
|
|
|
args.op = "63BFA50EE6523365FF14C1F45F88737D";
|
|
|
|
|
usim.init(&args, &usim_log);
|
|
|
|
|
|
|
|
|
|
srslte_nas_config_t nas_cfg;
|
|
|
|
|
srsue::nas nas;
|
|
|
|
|
nas.init(&usim, &rrc_dummy, &gw, &nas_log, nas_cfg);
|
|
|
|
|
|
|
|
|
|
nas.attach_request();
|
|
|
|
|
nas.notify_connection_setup();
|
|
|
|
|
|
|
|
|
|
//rrc.write_sdu(RB_ID_SRB2, tmp);
|
|
|
|
|
// check length of generated NAS SDU
|
|
|
|
|
if (rrc_dummy.get_last_sdu_len() > 3) {
|
|
|
|
|
ret = SRSLTE_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//nas.write_pdu(LCID, tmp);
|
|
|
|
|
|
|
|
|
|
pool->cleanup();
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
|
{
|
|
|
|
|
if (security_command_test()) {
|
|
|
|
|
printf("Security command test failed.\n");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mme_attach_request_test()) {
|
|
|
|
|
printf("Attach request test failed.\n");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|