Fixed HO with ciphering

master
Ismael Gomez 7 years ago
parent 997a22a1c6
commit 5c31800ccb

@ -191,7 +191,6 @@ class rrc_interface_rlc
{
public:
virtual void max_retx_attempted() = 0;
virtual std::string get_rb_name(uint32_t lcid) = 0;
};
// PDCP interface for GW
@ -215,6 +214,10 @@ public:
uint8_t *k_int_,
srslte::CIPHERING_ALGORITHM_ID_ENUM cipher_algo_,
srslte::INTEGRITY_ALGORITHM_ID_ENUM integ_algo_) = 0;
virtual void config_security_all(uint8_t *k_enc_,
uint8_t *k_int_,
srslte::CIPHERING_ALGORITHM_ID_ENUM cipher_algo_,
srslte::INTEGRITY_ALGORITHM_ID_ENUM integ_algo_) = 0;
virtual void enable_integrity(uint32_t lcid) = 0;
virtual void enable_encryption(uint32_t lcid) = 0;
};

@ -63,6 +63,10 @@ public:
uint8_t *k_int,
CIPHERING_ALGORITHM_ID_ENUM cipher_algo,
INTEGRITY_ALGORITHM_ID_ENUM integ_algo);
void config_security_all(uint8_t *k_enc,
uint8_t *k_int,
CIPHERING_ALGORITHM_ID_ENUM cipher_algo,
INTEGRITY_ALGORITHM_ID_ENUM integ_algo);
void enable_integrity(uint32_t lcid);
void enable_encryption(uint32_t lcid);

@ -66,7 +66,6 @@ public:
void write_sdu(uint32_t lcid, byte_buffer_t *sdu);
bool rb_is_um(uint32_t lcid);
std::string get_rb_name(uint32_t lcid);
// MAC interface
uint32_t get_buffer_state(uint32_t lcid);

@ -116,6 +116,18 @@ void pdcp::config_security(uint32_t lcid,
pdcp_array[lcid].config_security(k_enc, k_int, cipher_algo, integ_algo);
}
void pdcp::config_security_all(uint8_t *k_enc,
uint8_t *k_int,
CIPHERING_ALGORITHM_ID_ENUM cipher_algo,
INTEGRITY_ALGORITHM_ID_ENUM integ_algo)
{
for(uint32_t i=0;i<SRSLTE_N_RADIO_BEARERS;i++) {
if (pdcp_array[i].is_active()) {
pdcp_array[i].config_security(k_enc, k_int, cipher_algo, integ_algo);
}
}
}
void pdcp::enable_integrity(uint32_t lcid)
{
if(valid_lcid(lcid))

@ -84,6 +84,7 @@ void pdcp_entity::reestablish() {
} else {
if (rlc->rb_is_um(lcid)) {
tx_count = 0;
rx_count = 0;
}
}
}

@ -135,11 +135,6 @@ bool rlc::rb_is_um(uint32_t lcid) {
return rlc_array[lcid].get_mode()==RLC_MODE_UM;
}
std::string rlc::get_rb_name(uint32_t lcid)
{
return rrc->get_rb_name(lcid);
}
/*******************************************************************************
MAC interface
*******************************************************************************/

@ -238,30 +238,6 @@ private:
bool thread_running;
void run_thread();
// Radio bearers
typedef enum{
RB_ID_SRB0 = 0,
RB_ID_SRB1,
RB_ID_SRB2,
RB_ID_DRB1,
RB_ID_DRB2,
RB_ID_DRB3,
RB_ID_DRB4,
RB_ID_DRB5,
RB_ID_DRB6,
RB_ID_DRB7,
RB_ID_DRB8,
RB_ID_MAX
} rb_id_t;
std::string get_rb_name(uint32_t lcid) {
if (lcid < RB_ID_MAX) {
return rb_id_str[lcid];
} else {
return std::string("INVALID_RB");
}
}
// Measurements sub-class
class rrc_meas {
public:

@ -672,9 +672,9 @@ void phch_recv::run_thread()
workers_pool->start_worker(worker);
// Substract PSS/SSS from current cell before computing intra-frequency
if ((tti%5) == 0) {
/*if ((tti%5) == 0) {
substract_sync(buffer[0], cell.nof_prb, &ue_sync.strack);
}
}*/
intra_freq_meas.write(tti, buffer[0], SRSLTE_SF_LEN_PRB(cell.nof_prb));
out_of_sync_cnt = 0;
break;
@ -1164,7 +1164,7 @@ phch_recv::measure::ret_code phch_recv::measure::run_subframe(uint32_t sf_idx)
float snr = 10*log10(srslte_chest_dl_get_snr(&ue_dl.chest));
if (cnt == 0) {
mean_rsrp = rsrp;
mean_rsrp = rsrp;
mean_rsrq = rsrq;
mean_snr = snr;
} else {
@ -1175,7 +1175,7 @@ phch_recv::measure::ret_code phch_recv::measure::run_subframe(uint32_t sf_idx)
}
cnt++;
log_h->info("SYNC: Measuring RSRP %d/%d, sf_idx=%d, RSRP=%.1f dBm, SNR=%.1f dB\n",
log_h->debug("SYNC: Measuring RSRP %d/%d, sf_idx=%d, RSRP=%.1f dBm, SNR=%.1f dB\n",
cnt, nof_subframes, sf_idx, rsrp, snr);
if (cnt >= nof_subframes) {
@ -1259,76 +1259,76 @@ int phch_recv::scell_recv::find_cells(cf_t *input_buffer, float rx_gain_offset,
for (uint32_t n_id_2=0;n_id_2<3;n_id_2++) {
if (cell.id%3 != n_id_2) {
srslte_sync_set_N_id_2(&sync_find, n_id_2);
srslte_sync_find_ret_t sync_res;
do {
srslte_sync_reset(&sync_find);
srslte_sync_cfo_reset(&sync_find);
sync_res = srslte_sync_find(&sync_find, input_buffer, 0, &peak_idx);
switch(sync_res) {
case SRSLTE_SYNC_ERROR:
return SRSLTE_ERROR;
fprintf(stderr, "Error finding correlation peak\n");
return SRSLTE_ERROR;
case SRSLTE_SYNC_FOUND:
sf_idx = srslte_sync_get_sf_idx(&sync_find);
cell_id = srslte_sync_get_cell_id(&sync_find);
if (cell_id >= 0) {
// We found the same cell as before, look another N_id_2
if ((uint32_t) cell_id == found_cell.id) {
sync_res = SRSLTE_SYNC_NOFOUND;
} else {
// We found a new cell ID
found_cell.id = cell_id;
found_cell.nof_ports = 1; // Use port 0 only for measurement
measure_p.set_cell(found_cell);
// Correct CFO
srslte_cfo_correct(&sync_find.cfo_corr_frame,
input_buffer,
input_cfo_corrected,
-srslte_sync_get_cfo(&sync_find)/sync_find.fft_size);
switch(measure_p.run_multiple_subframes(input_cfo_corrected, peak_idx, sf_idx, nof_sf)) {
case measure::MEASURE_OK:
cells[nof_cells].pci = found_cell.id;
cells[nof_cells].rsrp = measure_p.rsrp();
cells[nof_cells].rsrq = measure_p.rsrq();
cells[nof_cells].offset = measure_p.frame_st_idx();
nof_cells++;
// Substract interference from input buffer (for the next cell)
substract_sync(&input_buffer[measure_p.frame_st_idx()], cell.nof_prb, &sync_find);
Info("INTRA: Found neighbour cell: pci=%d, rsrp=%.1f dBm, peak_idx=%d, n_id_2=%d, cfo=%.1f Hz\n",
cell_id, measure_p.rsrq(), peak_idx, n_id_2, 15000*srslte_sync_get_cfo(&sync_find));
break;
case measure::ERROR:
Error("Measuring neighbour cell\n");
return SRSLTE_ERROR;
default:
break;
}
}
} else {
srslte_sync_set_N_id_2(&sync_find, n_id_2);
srslte_sync_find_ret_t sync_res;
//do {
srslte_sync_reset(&sync_find);
srslte_sync_cfo_reset(&sync_find);
sync_res = srslte_sync_find(&sync_find, input_buffer, 0, &peak_idx);
switch(sync_res) {
case SRSLTE_SYNC_ERROR:
return SRSLTE_ERROR;
fprintf(stderr, "Error finding correlation peak\n");
return SRSLTE_ERROR;
case SRSLTE_SYNC_FOUND:
sf_idx = srslte_sync_get_sf_idx(&sync_find);
cell_id = srslte_sync_get_cell_id(&sync_find);
if (cell_id >= 0) {
// We found the same cell as before, look another N_id_2
if ((uint32_t) cell_id == found_cell.id || (uint32_t) cell_id == cell.id) {
sync_res = SRSLTE_SYNC_NOFOUND;
} else {
// We found a new cell ID
found_cell.id = cell_id;
found_cell.nof_ports = 1; // Use port 0 only for measurement
measure_p.set_cell(found_cell);
// Correct CFO
/*
srslte_cfo_correct(&sync_find.cfo_corr_frame,
input_buffer,
input_cfo_corrected,
-srslte_sync_get_cfo(&sync_find)/sync_find.fft_size);
*/
switch(measure_p.run_multiple_subframes(input_buffer, peak_idx, sf_idx, nof_sf)) {
case measure::MEASURE_OK:
cells[nof_cells].pci = found_cell.id;
cells[nof_cells].rsrp = measure_p.rsrp();
cells[nof_cells].rsrq = measure_p.rsrq();
cells[nof_cells].offset = measure_p.frame_st_idx();
nof_cells++;
// Substract interference from input buffer (for the next cell)
//substract_sync(&input_buffer[measure_p.frame_st_idx()], cell.nof_prb, &sync_find);
Info("INTRA: Found neighbour cell: PCI=%03d, RSRP=%5.1f dBm, peak_idx=%5d, peak_value=%3.2f n_id_2=%d, CFO=%6.1f Hz\n",
cell_id, measure_p.rsrp(), measure_p.frame_st_idx(), sync_find.peak_value, n_id_2, 15000*srslte_sync_get_cfo(&sync_find));
break;
case measure::ERROR:
Error("Measuring neighbour cell\n");
return SRSLTE_ERROR;
default:
break;
}
}
break;
case SRSLTE_SYNC_FOUND_NOSPACE:
/* If a peak was found but there is not enough space for SSS/CP detection, discard a few samples */
break;
default:
break;
}
} while(sync_res == SRSLTE_SYNC_FOUND);
}
} else {
sync_res = SRSLTE_SYNC_NOFOUND;
}
break;
case SRSLTE_SYNC_FOUND_NOSPACE:
/* If a peak was found but there is not enough space for SSS/CP detection, discard a few samples */
break;
default:
break;
}
//} while(sync_res == SRSLTE_SYNC_FOUND);
}
return nof_cells;
}
@ -1476,8 +1476,6 @@ void phch_recv::intra_measure::run_thread()
}
if (running) {
Info("INTRA: Running intra-frequency measurements\n");
// Read 15 ms data from buffer
srslte_ringbuffer_read(&ring_buffer, search_buffer, CAPTURE_LEN_SF*current_sflen*sizeof(cf_t));
int found_cells = scell.find_cells(search_buffer, common->rx_gain_offset, primary_cell, CAPTURE_LEN_SF, info);

@ -30,6 +30,7 @@
#include <sstream>
#include <stdlib.h>
#include <time.h>
#include <srslte/asn1/liblte_rrc.h>
#include "upper/rrc.h"
#include "srslte/asn1/liblte_rrc.h"
#include "srslte/common/security.h"
@ -1041,12 +1042,24 @@ bool rrc::ho_prepare() {
int ncc = -1;
if (mob_reconf.sec_cnfg_ho_present) {
ncc = mob_reconf.sec_cnfg_ho.intra_lte.next_hop_chaining_count;
if (mob_reconf.sec_cnfg_ho.intra_lte.key_change_ind) {
rrc_log->console("keyChangeIndicator in securityConfigHO not supported\n");
return false;
}
if (mob_reconf.sec_cnfg_ho.intra_lte.sec_alg_cnfg_present) {
cipher_algo = (CIPHERING_ALGORITHM_ID_ENUM) mob_reconf.sec_cnfg_ho.intra_lte.sec_alg_cnfg.cipher_alg;
integ_algo = (INTEGRITY_ALGORITHM_ID_ENUM) mob_reconf.sec_cnfg_ho.intra_lte.sec_alg_cnfg.int_alg;
rrc_log->console("Warning changed Cipering to %s and Integrity to %s\n",
ciphering_algorithm_id_text[cipher_algo],
integrity_algorithm_id_text[integ_algo]);
}
}
usim->generate_as_keys_ho(mob_reconf.mob_ctrl_info.target_pci, phy->get_current_earfcn(),
ncc,
k_rrc_enc, k_rrc_int, k_up_enc, k_up_int, cipher_algo, integ_algo);
pdcp->config_security(1, k_rrc_enc, k_rrc_int, cipher_algo, integ_algo);
pdcp->config_security_all(k_rrc_enc, k_rrc_int, cipher_algo, integ_algo);
send_rrc_con_reconfig_complete(NULL);
}
return true;
@ -1423,7 +1436,7 @@ void rrc::send_ul_dcch_msg(byte_buffer_t *pdu)
void rrc::write_sdu(uint32_t lcid, byte_buffer_t *sdu) {
rrc_log->info_hex(sdu->msg, sdu->N_bytes, "TX %s SDU", get_rb_name(lcid).c_str());
rrc_log->info_hex(sdu->msg, sdu->N_bytes, "TX %s SDU", get_rb_name(lcid));
switch (state) {
case RRC_STATE_CONNECTING:
send_con_setup_complete(sdu);
@ -1438,7 +1451,7 @@ void rrc::write_sdu(uint32_t lcid, byte_buffer_t *sdu) {
}
void rrc::write_pdu(uint32_t lcid, byte_buffer_t *pdu) {
rrc_log->info_hex(pdu->msg, pdu->N_bytes, "RX %s PDU", get_rb_name(lcid).c_str());
rrc_log->info_hex(pdu->msg, pdu->N_bytes, "RX %s PDU", get_rb_name(lcid));
switch (lcid) {
case RB_ID_SRB0:
@ -1528,8 +1541,8 @@ void rrc::parse_dl_dcch(uint32_t lcid, byte_buffer_t *pdu) {
nas->get_k_asme(k_asme, 32);
usim->generate_as_keys(k_asme, nas->get_ul_count()-1, k_rrc_enc, k_rrc_int, k_up_enc, k_up_int, cipher_algo, integ_algo);
rrc_log->debug_hex(k_rrc_enc, 32, "RRC encryption key - k_rrc_enc");
rrc_log->debug_hex(k_rrc_int, 32, "RRC integrity key - k_rrc_int");
rrc_log->debug_hex(k_up_enc, 32, "UP encryption key - k_up_enc");
rrc_log->debug_hex(k_rrc_int, 32, "RRC integrity key - k_rrc_int");
rrc_log->debug_hex(k_up_enc, 32, "UP encryption key - k_up_enc");
// Configure PDCP for security
pdcp->config_security(lcid, k_rrc_enc, k_rrc_int, cipher_algo, integ_algo);

Loading…
Cancel
Save