Merge branch 'next' of github.com:softwareradiosystems/srsLTE into next

This commit is contained in:
Ismael Gomez 2018-04-26 14:03:49 +02:00
commit 785298e4c5
3 changed files with 53 additions and 18 deletions

View File

@ -116,15 +116,17 @@ public:
byte_buffer_t():N_bytes(0)
{
timestamp_is_set = false;
bzero(buffer, SRSLTE_MAX_BUFFER_SIZE_BYTES);
timestamp_is_set = false;
msg = &buffer[SRSLTE_BUFFER_HEADER_OFFSET];
next = NULL;
#ifdef SRSLTE_BUFFER_POOL_LOG_ENABLED
debug_name[0] = 0;
bzero(debug_name, SRSLTE_BUFFER_POOL_LOG_NAME_LEN);
#endif
}
byte_buffer_t(const byte_buffer_t& buf)
{
bzero(buffer, SRSLTE_MAX_BUFFER_SIZE_BYTES);
N_bytes = buf.N_bytes;
memcpy(msg, buf.msg, N_bytes);
}
@ -133,6 +135,7 @@ public:
// avoid self assignment
if (&buf == this)
return *this;
bzero(buffer, SRSLTE_MAX_BUFFER_SIZE_BYTES);
N_bytes = buf.N_bytes;
memcpy(msg, buf.msg, N_bytes);
return *this;

View File

@ -49,6 +49,9 @@ nas::nas()
{
ctxt.rx_count = 0;
ctxt.tx_count = 0;
ctxt.cipher_algo = CIPHERING_ALGORITHM_ID_EEA0;
ctxt.integ_algo = INTEGRITY_ALGORITHM_ID_EIA0;
plmn_is_selected = false;
}
void nas::init(usim_interface_nas *usim_,
@ -103,7 +106,6 @@ bool nas::attach_request() {
rrc_interface_nas::found_plmn_t found_plmns[rrc_interface_nas::MAX_FOUND_PLMNS];
int nof_plmns = 0;
uint32_t tout = 0;
nas_log->info("Attach Request\n");
switch (state) {
case EMM_STATE_DEREGISTERED:
@ -233,7 +235,7 @@ bool nas::rrc_connect() {
nas_log->info("EMM Registered correctly\n");
return true;
} else if (state == EMM_STATE_DEREGISTERED) {
nas_log->error("Received attach reject while trying to attach\n");
nas_log->error("Timeout or received attach reject while trying to attach\n");
nas_log->console("Failed to Attach\n");
} else if (!rrc->is_connected()) {
nas_log->error("Was disconnected while attaching\n");
@ -423,7 +425,7 @@ bool nas::integrity_check(byte_buffer_t *pdu)
return NULL;
}
if (pdu->N_bytes > 5) {
uint8_t exp_mac[4];
uint8_t exp_mac[4] = {0};
uint8_t *mac = &pdu->msg[1];
int i;
@ -481,7 +483,7 @@ void nas::cipher_encrypt(byte_buffer_t *pdu)
memcpy(&pdu->msg[6], &pdu_tmp.msg[6], pdu->N_bytes-6);
break;
default:
nas_log->error("Ciphering algorithmus not known");
nas_log->error("Ciphering algorithm not known\n");
break;
}
}

View File

@ -50,6 +50,15 @@ uint8_t auth_request_pdu[] = { 0x07, 0x52, 0x01, 0x0c, 0x63, 0xa8, 0x54, 0x13, 0
uint8_t sec_mode_command_pdu[] = { 0x37, 0x37, 0xc7, 0x67, 0xae, 0x00, 0x07, 0x5d, 0x02, 0x01,
0x02, 0xe0, 0x60, 0xc1 };
uint8_t attach_accept_pdu[] = { 0x27, 0x0f, 0x4f, 0xb3, 0xef, 0x01, 0x07, 0x42, 0x01, 0x3e,
0x06, 0x00, 0x00, 0xf1, 0x10, 0x00, 0x01, 0x00, 0x2a, 0x52,
0x01, 0xc1, 0x01, 0x04, 0x1b, 0x07, 0x74, 0x65, 0x73, 0x74,
0x31, 0x32, 0x33, 0x06, 0x6d, 0x6e, 0x63, 0x30, 0x30, 0x31,
0x06, 0x6d, 0x63, 0x63, 0x30, 0x30, 0x31, 0x04, 0x67, 0x70,
0x72, 0x73, 0x05, 0x01, 0xc0, 0xa8, 0x05, 0x02, 0x27, 0x01,
0x80, 0x50, 0x0b, 0xf6, 0x00, 0xf1, 0x10, 0x80, 0x01, 0x01,
0x35, 0x16, 0x6d, 0xbc, 0x64, 0x01, 0x00 };
uint16 mcc = 61441;
uint16 mnc = 65281;
@ -71,22 +80,35 @@ public:
class rrc_dummy : public rrc_interface_nas
{
public:
rrc_dummy() : last_sdu_len(0) {
plmns.plmn_id.mcc = mcc;
plmns.plmn_id.mnc = mnc;
plmns.tac = 0xffff;
}
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);
//printf("NAS generated SDU (len=%d):\n", sdu->N_bytes);
//srslte_vec_fprint_byte(stdout, sdu->msg, sdu->N_bytes);
byte_buffer_pool::get_instance()->deallocate(sdu);
}
std::string get_rb_name(uint32_t lcid) { return std::string("lcid"); }
uint32_t get_last_sdu_len() { return last_sdu_len; }
int plmn_search(srsue::rrc_interface_nas::found_plmn_t*) { return 0; };
int plmn_search(srsue::rrc_interface_nas::found_plmn_t* found) {
memcpy(found, &plmns, sizeof(found_plmn_t));
return 1;
};
void plmn_select(LIBLTE_RRC_PLMN_IDENTITY_STRUCT plmn_id) {};
void set_ue_idenity(LIBLTE_RRC_S_TMSI_STRUCT s_tmsi) {}
bool connection_request(LIBLTE_RRC_CON_REQ_EST_CAUSE_ENUM cause,
srslte::byte_buffer_t *dedicatedInfoNAS) {return true;}
bool is_connected() {return true;}
bool connection_request(LIBLTE_RRC_CON_REQ_EST_CAUSE_ENUM cause, srslte::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);
byte_buffer_pool::get_instance()->deallocate(sdu);
return true;
}
bool is_connected() {return false;}
uint16_t get_mcc() { return mcc; }
uint16_t get_mnc() { return mnc; }
@ -94,6 +116,7 @@ public:
private:
uint32_t last_sdu_len;
found_plmn_t plmns;
};
class gw_dummy : public gw_interface_nas, public gw_interface_pdcp
@ -134,15 +157,12 @@ int security_command_test()
uint8_t res[16];
usim.init(&args, &usim_log);
srslte::byte_buffer_pool *pool;
pool = byte_buffer_pool::get_instance();
srsue::nas nas;
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();
byte_buffer_t* tmp = byte_buffer_pool::get_instance()->allocate();
memcpy(tmp->msg, auth_request_pdu, sizeof(auth_request_pdu));
tmp->N_bytes = sizeof(auth_request_pdu);
nas.write_pdu(LCID, tmp);
@ -159,7 +179,7 @@ int security_command_test()
ret = SRSLTE_SUCCESS;
}
pool->cleanup();
byte_buffer_pool::get_instance()->cleanup();
return ret;
}
@ -195,11 +215,21 @@ int mme_attach_request_test()
nas.attach_request();
// check length of generated NAS SDU
// this will time out in the first place
// finally push attach accept
byte_buffer_t* tmp = byte_buffer_pool::get_instance()->allocate();
memcpy(tmp->msg, attach_accept_pdu, sizeof(attach_accept_pdu));
tmp->N_bytes = sizeof(attach_accept_pdu);
nas.write_pdu(LCID, tmp);
// check length of generated NAS SDU (attach complete)
if (rrc_dummy.get_last_sdu_len() > 3) {
ret = SRSLTE_SUCCESS;
}
byte_buffer_pool::get_instance()->cleanup();
return ret;
}