diff --git a/openair2/LAYER2/openair2_proc.c b/openair2/LAYER2/openair2_proc.c index 56982d565d0a24c5fe6c5886895eef48b7bc8d04..50c8ac58b430881edf33360a2c9e8b5591d4b881 100644 --- a/openair2/LAYER2/openair2_proc.c +++ b/openair2/LAYER2/openair2_proc.c @@ -39,586 +39,586 @@ #include "common/ran_context.h" static mapping rrc_status_names[] = { - {"RRC_INACTIVE", 0}, - {"RRC_IDLE", 1}, - {"RRC_SI_RECEIVED",2}, - {"RRC_CONNECTED",3}, - {"RRC_RECONFIGURED",4}, - {"RRC_HO_EXECUTION",5}, - {NULL, -1} + {"RRC_INACTIVE", 0}, + {"RRC_IDLE", 1}, + {"RRC_SI_RECEIVED",2}, + {"RRC_CONNECTED",3}, + {"RRC_RECONFIGURED",4}, + {"RRC_HO_EXECUTION",5}, + {NULL, -1} }; extern RAN_CONTEXT_t RC; int dump_eNB_l2_stats(char *buffer, int length) { - int eNB_id,UE_id,number_of_cards; - int len= length; - int CC_id=0; - int i; - protocol_ctxt_t ctxt; - rlc_op_status_t rlc_status; - unsigned int stat_rlc_mode; - unsigned int stat_tx_pdcp_sdu; - unsigned int stat_tx_pdcp_bytes; - unsigned int stat_tx_pdcp_sdu_discarded; - unsigned int stat_tx_pdcp_bytes_discarded; - unsigned int stat_tx_data_pdu; - unsigned int stat_tx_data_bytes; - unsigned int stat_tx_retransmit_pdu_by_status; - unsigned int stat_tx_retransmit_bytes_by_status; - unsigned int stat_tx_retransmit_pdu; - unsigned int stat_tx_retransmit_bytes; - unsigned int stat_tx_control_pdu; - unsigned int stat_tx_control_bytes; - unsigned int stat_rx_pdcp_sdu; - unsigned int stat_rx_pdcp_bytes; - unsigned int stat_rx_data_pdus_duplicate; - unsigned int stat_rx_data_bytes_duplicate; - unsigned int stat_rx_data_pdu; - unsigned int stat_rx_data_bytes; - unsigned int stat_rx_data_pdu_dropped; - unsigned int stat_rx_data_bytes_dropped; - unsigned int stat_rx_data_pdu_out_of_window; - unsigned int stat_rx_data_bytes_out_of_window; - unsigned int stat_rx_control_pdu; - unsigned int stat_rx_control_bytes; - unsigned int stat_timer_reordering_timed_out; - unsigned int stat_timer_poll_retransmit_timed_out; - unsigned int stat_timer_status_prohibit_timed_out; + int eNB_id,UE_id,number_of_cards; + int len= length; + int CC_id=0; + int i; + protocol_ctxt_t ctxt; + rlc_op_status_t rlc_status; + unsigned int stat_rlc_mode; + unsigned int stat_tx_pdcp_sdu; + unsigned int stat_tx_pdcp_bytes; + unsigned int stat_tx_pdcp_sdu_discarded; + unsigned int stat_tx_pdcp_bytes_discarded; + unsigned int stat_tx_data_pdu; + unsigned int stat_tx_data_bytes; + unsigned int stat_tx_retransmit_pdu_by_status; + unsigned int stat_tx_retransmit_bytes_by_status; + unsigned int stat_tx_retransmit_pdu; + unsigned int stat_tx_retransmit_bytes; + unsigned int stat_tx_control_pdu; + unsigned int stat_tx_control_bytes; + unsigned int stat_rx_pdcp_sdu; + unsigned int stat_rx_pdcp_bytes; + unsigned int stat_rx_data_pdus_duplicate; + unsigned int stat_rx_data_bytes_duplicate; + unsigned int stat_rx_data_pdu; + unsigned int stat_rx_data_bytes; + unsigned int stat_rx_data_pdu_dropped; + unsigned int stat_rx_data_bytes_dropped; + unsigned int stat_rx_data_pdu_out_of_window; + unsigned int stat_rx_data_bytes_out_of_window; + unsigned int stat_rx_control_pdu; + unsigned int stat_rx_control_bytes; + unsigned int stat_timer_reordering_timed_out; + unsigned int stat_timer_poll_retransmit_timed_out; + unsigned int stat_timer_status_prohibit_timed_out; #ifdef EXMIMO - number_of_cards=1; + number_of_cards=1; #else - number_of_cards=NB_eNB_INST; + number_of_cards=NB_eNB_INST; #endif - eNB_MAC_INST *eNB; - UE_list_t *UE_list; - - for (eNB_id=0; eNB_id<number_of_cards; eNB_id++) { - /* reset the values */ - eNB = RC.mac[eNB_id]; - UE_list = &eNB->UE_list; - - for (CC_id=0 ; CC_id < MAX_NUM_CCs; CC_id++) { - eNB->eNB_stats[CC_id].dlsch_bitrate= 0; - len += sprintf(&buffer[len],"eNB %d CC %d Frame %d: Active UEs %d, Available PRBs %d, nCCE %d, Scheduling decisions %d, Missed Deadlines %d \n", - eNB_id, CC_id, eNB->frame, - eNB->eNB_stats[CC_id].num_dlactive_UEs, - eNB->eNB_stats[CC_id].available_prbs, - eNB->eNB_stats[CC_id].available_ncces, - eNB->eNB_stats[CC_id].sched_decisions, - eNB->eNB_stats[CC_id].missed_deadlines); - len += sprintf(&buffer[len],"BCCH , NB_TX_MAC = %d, transmitted bytes (TTI %d, total %d) MCS (TTI %d)\n", - eNB->eNB_stats[CC_id].total_num_bcch_pdu, - eNB->eNB_stats[CC_id].bcch_buffer, - eNB->eNB_stats[CC_id].total_bcch_buffer, - eNB->eNB_stats[CC_id].bcch_mcs); - len += sprintf(&buffer[len],"PCCH , NB_TX_MAC = %d, transmitted bytes (TTI %d, total %d) MCS (TTI %d)\n", - eNB->eNB_stats[CC_id].total_num_pcch_pdu, - eNB->eNB_stats[CC_id].pcch_buffer, - eNB->eNB_stats[CC_id].total_pcch_buffer, - eNB->eNB_stats[CC_id].pcch_mcs); - eNB->eNB_stats[CC_id].dlsch_bitrate=((eNB->eNB_stats[CC_id].dlsch_bytes_tx*8)/((eNB->frame + 1)*10)); - eNB->eNB_stats[CC_id].total_dlsch_pdus_tx+=eNB->eNB_stats[CC_id].dlsch_pdus_tx; - eNB->eNB_stats[CC_id].total_dlsch_bytes_tx+=eNB->eNB_stats[CC_id].dlsch_bytes_tx; - eNB->eNB_stats[CC_id].total_dlsch_bitrate=((eNB->eNB_stats[CC_id].total_dlsch_bytes_tx*8)/((eNB->frame + 1)*10)); - eNB->eNB_stats[CC_id].ulsch_bitrate=((eNB->eNB_stats[CC_id].ulsch_bytes_rx*8)/((eNB->frame + 1)*10)); - eNB->eNB_stats[CC_id].total_ulsch_bitrate=((eNB->eNB_stats[CC_id].total_ulsch_bytes_rx*8)/((eNB->frame + 1)*10)); - len += sprintf(&buffer[len],"DLSCH bitrate (TTI %u, avg %u) kbps, Transmitted bytes (TTI %u, total %u), Transmitted PDU (TTI %u, total %u) \n", - eNB->eNB_stats[CC_id].dlsch_bitrate, - eNB->eNB_stats[CC_id].total_dlsch_bitrate, - eNB->eNB_stats[CC_id].dlsch_bytes_tx, - eNB->eNB_stats[CC_id].total_dlsch_bytes_tx, - eNB->eNB_stats[CC_id].dlsch_pdus_tx, - eNB->eNB_stats[CC_id].total_dlsch_pdus_tx); - len += sprintf(&buffer[len],"ULSCH bitrate (TTI %u, avg %u) kbps, Received bytes (TTI %u, total %u), Received PDU (TTI %lu, total %u) \n", - eNB->eNB_stats[CC_id].ulsch_bitrate, - eNB->eNB_stats[CC_id].total_ulsch_bitrate, - eNB->eNB_stats[CC_id].ulsch_bytes_rx, - eNB->eNB_stats[CC_id].total_ulsch_bytes_rx, - eNB->eNB_stats[CC_id].ulsch_pdus_rx, - eNB->eNB_stats[CC_id].total_ulsch_pdus_rx); - } + eNB_MAC_INST *eNB; + UE_list_t *UE_list; + + for (eNB_id=0; eNB_id<number_of_cards; eNB_id++) { + /* reset the values */ + eNB = RC.mac[eNB_id]; + UE_list = &eNB->UE_list; + + for (CC_id=0 ; CC_id < MAX_NUM_CCs; CC_id++) { + eNB->eNB_stats[CC_id].dlsch_bitrate= 0; + len += sprintf(&buffer[len],"eNB %d CC %d Frame %d: Active UEs %d, Available PRBs %d, nCCE %d, Scheduling decisions %d, Missed Deadlines %d \n", + eNB_id, CC_id, eNB->frame, + eNB->eNB_stats[CC_id].num_dlactive_UEs, + eNB->eNB_stats[CC_id].available_prbs, + eNB->eNB_stats[CC_id].available_ncces, + eNB->eNB_stats[CC_id].sched_decisions, + eNB->eNB_stats[CC_id].missed_deadlines); + len += sprintf(&buffer[len],"BCCH , NB_TX_MAC = %d, transmitted bytes (TTI %d, total %d) MCS (TTI %d)\n", + eNB->eNB_stats[CC_id].total_num_bcch_pdu, + eNB->eNB_stats[CC_id].bcch_buffer, + eNB->eNB_stats[CC_id].total_bcch_buffer, + eNB->eNB_stats[CC_id].bcch_mcs); + len += sprintf(&buffer[len],"PCCH , NB_TX_MAC = %d, transmitted bytes (TTI %d, total %d) MCS (TTI %d)\n", + eNB->eNB_stats[CC_id].total_num_pcch_pdu, + eNB->eNB_stats[CC_id].pcch_buffer, + eNB->eNB_stats[CC_id].total_pcch_buffer, + eNB->eNB_stats[CC_id].pcch_mcs); + eNB->eNB_stats[CC_id].dlsch_bitrate=((eNB->eNB_stats[CC_id].dlsch_bytes_tx*8)/((eNB->frame + 1)*10)); + eNB->eNB_stats[CC_id].total_dlsch_pdus_tx+=eNB->eNB_stats[CC_id].dlsch_pdus_tx; + eNB->eNB_stats[CC_id].total_dlsch_bytes_tx+=eNB->eNB_stats[CC_id].dlsch_bytes_tx; + eNB->eNB_stats[CC_id].total_dlsch_bitrate=((eNB->eNB_stats[CC_id].total_dlsch_bytes_tx*8)/((eNB->frame + 1)*10)); + eNB->eNB_stats[CC_id].ulsch_bitrate=((eNB->eNB_stats[CC_id].ulsch_bytes_rx*8)/((eNB->frame + 1)*10)); + eNB->eNB_stats[CC_id].total_ulsch_bitrate=((eNB->eNB_stats[CC_id].total_ulsch_bytes_rx*8)/((eNB->frame + 1)*10)); + len += sprintf(&buffer[len],"DLSCH bitrate (TTI %u, avg %u) kbps, Transmitted bytes (TTI %u, total %u), Transmitted PDU (TTI %u, total %u) \n", + eNB->eNB_stats[CC_id].dlsch_bitrate, + eNB->eNB_stats[CC_id].total_dlsch_bitrate, + eNB->eNB_stats[CC_id].dlsch_bytes_tx, + eNB->eNB_stats[CC_id].total_dlsch_bytes_tx, + eNB->eNB_stats[CC_id].dlsch_pdus_tx, + eNB->eNB_stats[CC_id].total_dlsch_pdus_tx); + len += sprintf(&buffer[len],"ULSCH bitrate (TTI %u, avg %u) kbps, Received bytes (TTI %u, total %u), Received PDU (TTI %lu, total %u) \n", + eNB->eNB_stats[CC_id].ulsch_bitrate, + eNB->eNB_stats[CC_id].total_ulsch_bitrate, + eNB->eNB_stats[CC_id].ulsch_bytes_rx, + eNB->eNB_stats[CC_id].total_ulsch_bytes_rx, + eNB->eNB_stats[CC_id].ulsch_pdus_rx, + eNB->eNB_stats[CC_id].total_ulsch_pdus_rx); + } + + len += sprintf(&buffer[len],"\n"); + + for (UE_id=UE_list->head; UE_id>=0; UE_id=UE_list->next[UE_id]) { + for (i=0; i<UE_list->numactiveCCs[UE_id]; i++) { + CC_id=UE_list->ordered_CCids[i][UE_id]; + UE_list->eNB_UE_stats[CC_id][UE_id].dlsch_bitrate=((UE_list->eNB_UE_stats[CC_id][UE_id].TBS*8)/((eNB->frame + 1)*10)); + UE_list->eNB_UE_stats[CC_id][UE_id].total_dlsch_bitrate= ((UE_list->eNB_UE_stats[CC_id][UE_id].total_pdu_bytes*8)/((eNB->frame + 1)*10)); + UE_list->eNB_UE_stats[CC_id][UE_id].total_overhead_bytes+= UE_list->eNB_UE_stats[CC_id][UE_id].overhead_bytes; + UE_list->eNB_UE_stats[CC_id][UE_id].avg_overhead_bytes=((UE_list->eNB_UE_stats[CC_id][UE_id].total_overhead_bytes*8)/((eNB->frame + 1)*10)); + UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_bitrate=((UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_TBS*8)/((eNB->frame + 1)*10)); + UE_list->eNB_UE_stats[CC_id][UE_id].total_ulsch_bitrate= ((UE_list->eNB_UE_stats[CC_id][UE_id].total_pdu_bytes_rx*8)/((eNB->frame + 1)*10)); + len += sprintf(&buffer[len],"[MAC] UE %d (DLSCH),status %s, RNTI %x : CQI %d, MCS1 %d, MCS2 %d, RB (tx %d, retx %d, total %d), ncce (tx %d, retx %d) \n", + UE_id, + map_int_to_str(rrc_status_names, UE_list->eNB_UE_stats[CC_id][UE_id].rrc_status), + UE_list->eNB_UE_stats[CC_id][UE_id].crnti, + UE_list->UE_sched_ctrl[UE_id].dl_cqi[CC_id], + UE_list->eNB_UE_stats[CC_id][UE_id].dlsch_mcs1, + UE_list->eNB_UE_stats[CC_id][UE_id].dlsch_mcs2, + UE_list->eNB_UE_stats[CC_id][UE_id].rbs_used, + UE_list->eNB_UE_stats[CC_id][UE_id].rbs_used_retx, + UE_list->eNB_UE_stats[CC_id][UE_id].total_rbs_used, + UE_list->eNB_UE_stats[CC_id][UE_id].ncce_used, + UE_list->eNB_UE_stats[CC_id][UE_id].ncce_used_retx + ); + len += sprintf(&buffer[len], + "[MAC] DLSCH bitrate (TTI %d, avg %d), Transmitted bytes " + "(TTI %d, total %"PRIu64"), Total Transmitted PDU %d, Overhead " + "(TTI %"PRIu64", total %"PRIu64", avg %"PRIu64")\n", + UE_list->eNB_UE_stats[CC_id][UE_id].dlsch_bitrate, + UE_list->eNB_UE_stats[CC_id][UE_id].total_dlsch_bitrate, + UE_list->eNB_UE_stats[CC_id][UE_id].TBS, + UE_list->eNB_UE_stats[CC_id][UE_id].total_pdu_bytes, + UE_list->eNB_UE_stats[CC_id][UE_id].total_num_pdus, + UE_list->eNB_UE_stats[CC_id][UE_id].overhead_bytes, + UE_list->eNB_UE_stats[CC_id][UE_id].total_overhead_bytes, + UE_list->eNB_UE_stats[CC_id][UE_id].avg_overhead_bytes + ); + len += sprintf(&buffer[len],"[MAC] UE %d (ULSCH), Status %s, Failute timer %d, RNTI %x : rx power (normalized %d, target %d), MCS (pre %d, post %d), RB (rx %d, retx %d, total %d), Current TBS %d \n", + UE_id, + map_int_to_str(rrc_status_names, UE_list->eNB_UE_stats[CC_id][UE_id].rrc_status), + UE_list->UE_sched_ctrl[UE_id].ul_failure_timer, + UE_list->eNB_UE_stats[CC_id][UE_id].crnti, + UE_list->eNB_UE_stats[CC_id][UE_id].normalized_rx_power, + UE_list->eNB_UE_stats[CC_id][UE_id].target_rx_power, + UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_mcs1, + UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_mcs2, + UE_list->eNB_UE_stats[CC_id][UE_id].rbs_used_rx, + UE_list->eNB_UE_stats[CC_id][UE_id].rbs_used_retx_rx, + UE_list->eNB_UE_stats[CC_id][UE_id].total_rbs_used_rx, + UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_TBS + ); + len += sprintf(&buffer[len], + "[MAC] ULSCH bitrate (TTI %d, avg %d), received bytes (total %"PRIu64")," + "Total received PDU %d, Total errors %d\n", + UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_bitrate, + UE_list->eNB_UE_stats[CC_id][UE_id].total_ulsch_bitrate, + UE_list->eNB_UE_stats[CC_id][UE_id].total_pdu_bytes_rx, + UE_list->eNB_UE_stats[CC_id][UE_id].total_num_pdus_rx, + UE_list->eNB_UE_stats[CC_id][UE_id].num_errors_rx); + len+= sprintf(&buffer[len],"[MAC] Received PHR PH = %d (db)\n", UE_list->UE_template[CC_id][UE_id].phr_info); + len+= sprintf(&buffer[len],"[MAC] Estimated size LCGID[0][1][2][3] = %u %u %u %u\n", + UE_list->UE_template[CC_id][UE_id].ul_buffer_info[LCGID0], + UE_list->UE_template[CC_id][UE_id].ul_buffer_info[LCGID1], + UE_list->UE_template[CC_id][UE_id].ul_buffer_info[LCGID2], + UE_list->UE_template[CC_id][UE_id].ul_buffer_info[LCGID3] + ); + } + + PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, + eNB_id, + ENB_FLAG_YES, + UE_list->eNB_UE_stats[0][UE_id].crnti,//UE_PCCID(eNB_id,UE_id)][UE_id].crnti, + eNB->frame, + eNB->subframe, + eNB_id); + rlc_status = rlc_stat_req(&ctxt, + SRB_FLAG_YES, + DCCH, + &stat_rlc_mode, + &stat_tx_pdcp_sdu, + &stat_tx_pdcp_bytes, + &stat_tx_pdcp_sdu_discarded, + &stat_tx_pdcp_bytes_discarded, + &stat_tx_data_pdu, + &stat_tx_data_bytes, + &stat_tx_retransmit_pdu_by_status, + &stat_tx_retransmit_bytes_by_status, + &stat_tx_retransmit_pdu, + &stat_tx_retransmit_bytes, + &stat_tx_control_pdu, + &stat_tx_control_bytes, + &stat_rx_pdcp_sdu, + &stat_rx_pdcp_bytes, + &stat_rx_data_pdus_duplicate, + &stat_rx_data_bytes_duplicate, + &stat_rx_data_pdu, + &stat_rx_data_bytes, + &stat_rx_data_pdu_dropped, + &stat_rx_data_bytes_dropped, + &stat_rx_data_pdu_out_of_window, + &stat_rx_data_bytes_out_of_window, + &stat_rx_control_pdu, + &stat_rx_control_bytes, + &stat_timer_reordering_timed_out, + &stat_timer_poll_retransmit_timed_out, + &stat_timer_status_prohibit_timed_out); + + if (rlc_status == RLC_OP_STATUS_OK) { + len+=sprintf(&buffer[len],"[RLC] DCCH Mode %s, NB_SDU_TO_TX = %u (bytes %u)\tNB_SDU_TO_TX_DISC %u (bytes %u)\n", + (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE", + stat_tx_pdcp_sdu, + stat_tx_pdcp_bytes, + stat_tx_pdcp_sdu_discarded, + stat_tx_pdcp_bytes_discarded); + len+=sprintf(&buffer[len],"[RLC] DCCH Mode %s, NB_TX_DATA = %u (bytes %u)\tNB_TX_CONTROL %u (bytes %u)\tNB_TX_RETX %u (bytes %u)\tNB_TX_RETX_BY_STATUS = %u (bytes %u)\n", + (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE", + stat_tx_data_pdu, + stat_tx_data_bytes, + stat_tx_control_pdu, + stat_tx_control_bytes, + stat_tx_retransmit_pdu, + stat_tx_retransmit_bytes, + stat_tx_retransmit_pdu_by_status, + stat_tx_retransmit_bytes_by_status); + len+=sprintf(&buffer[len],"[RLC] DCCH Mode %s, NB_RX_DATA = %u (bytes %u)\tNB_RX_CONTROL %u (bytes %u)\tNB_RX_DUPL %u (bytes %u)\tNB_RX_DROP = %u (bytes %u)\tNB_RX_OUT_OF_WINDOW = %u (bytes %u)\n", + (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE", + stat_rx_data_pdu, + stat_rx_data_bytes, + stat_rx_control_pdu, + stat_rx_control_bytes, + stat_rx_data_pdus_duplicate, + stat_rx_data_bytes_duplicate, + stat_rx_data_pdu_dropped, + stat_rx_data_bytes_dropped, + stat_rx_data_pdu_out_of_window, + stat_rx_data_bytes_out_of_window); + len+=sprintf(&buffer[len],"[RLC] DCCH Mode %s, RX_REODERING_TIMEOUT = %u\tRX_POLL_RET_TIMEOUT %u\tRX_PROHIBIT_TIME_OUT %u\n", + (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE", + stat_timer_reordering_timed_out, + stat_timer_poll_retransmit_timed_out, + stat_timer_status_prohibit_timed_out); + len+=sprintf(&buffer[len],"[RLC] DCCH Mode %s, NB_SDU_TO_RX = %u (bytes %u)\n", + (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE", + stat_rx_pdcp_sdu, + stat_rx_pdcp_bytes); + } - len += sprintf(&buffer[len],"\n"); - - for (UE_id=UE_list->head; UE_id>=0; UE_id=UE_list->next[UE_id]) { - for (i=0; i<UE_list->numactiveCCs[UE_id]; i++) { - CC_id=UE_list->ordered_CCids[i][UE_id]; - UE_list->eNB_UE_stats[CC_id][UE_id].dlsch_bitrate=((UE_list->eNB_UE_stats[CC_id][UE_id].TBS*8)/((eNB->frame + 1)*10)); - UE_list->eNB_UE_stats[CC_id][UE_id].total_dlsch_bitrate= ((UE_list->eNB_UE_stats[CC_id][UE_id].total_pdu_bytes*8)/((eNB->frame + 1)*10)); - UE_list->eNB_UE_stats[CC_id][UE_id].total_overhead_bytes+= UE_list->eNB_UE_stats[CC_id][UE_id].overhead_bytes; - UE_list->eNB_UE_stats[CC_id][UE_id].avg_overhead_bytes=((UE_list->eNB_UE_stats[CC_id][UE_id].total_overhead_bytes*8)/((eNB->frame + 1)*10)); - UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_bitrate=((UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_TBS*8)/((eNB->frame + 1)*10)); - UE_list->eNB_UE_stats[CC_id][UE_id].total_ulsch_bitrate= ((UE_list->eNB_UE_stats[CC_id][UE_id].total_pdu_bytes_rx*8)/((eNB->frame + 1)*10)); - len += sprintf(&buffer[len],"[MAC] UE %d (DLSCH),status %s, RNTI %x : CQI %d, MCS1 %d, MCS2 %d, RB (tx %d, retx %d, total %d), ncce (tx %d, retx %d) \n", - UE_id, - map_int_to_str(rrc_status_names, UE_list->eNB_UE_stats[CC_id][UE_id].rrc_status), - UE_list->eNB_UE_stats[CC_id][UE_id].crnti, - UE_list->UE_sched_ctrl[UE_id].dl_cqi[CC_id], - UE_list->eNB_UE_stats[CC_id][UE_id].dlsch_mcs1, - UE_list->eNB_UE_stats[CC_id][UE_id].dlsch_mcs2, - UE_list->eNB_UE_stats[CC_id][UE_id].rbs_used, - UE_list->eNB_UE_stats[CC_id][UE_id].rbs_used_retx, - UE_list->eNB_UE_stats[CC_id][UE_id].total_rbs_used, - UE_list->eNB_UE_stats[CC_id][UE_id].ncce_used, - UE_list->eNB_UE_stats[CC_id][UE_id].ncce_used_retx - ); - len += sprintf(&buffer[len], - "[MAC] DLSCH bitrate (TTI %d, avg %d), Transmitted bytes " - "(TTI %d, total %"PRIu64"), Total Transmitted PDU %d, Overhead " - "(TTI %"PRIu64", total %"PRIu64", avg %"PRIu64")\n", - UE_list->eNB_UE_stats[CC_id][UE_id].dlsch_bitrate, - UE_list->eNB_UE_stats[CC_id][UE_id].total_dlsch_bitrate, - UE_list->eNB_UE_stats[CC_id][UE_id].TBS, - UE_list->eNB_UE_stats[CC_id][UE_id].total_pdu_bytes, - UE_list->eNB_UE_stats[CC_id][UE_id].total_num_pdus, - UE_list->eNB_UE_stats[CC_id][UE_id].overhead_bytes, - UE_list->eNB_UE_stats[CC_id][UE_id].total_overhead_bytes, - UE_list->eNB_UE_stats[CC_id][UE_id].avg_overhead_bytes - ); - len += sprintf(&buffer[len],"[MAC] UE %d (ULSCH), Status %s, Failute timer %d, RNTI %x : rx power (normalized %d, target %d), MCS (pre %d, post %d), RB (rx %d, retx %d, total %d), Current TBS %d \n", - UE_id, - map_int_to_str(rrc_status_names, UE_list->eNB_UE_stats[CC_id][UE_id].rrc_status), - UE_list->UE_sched_ctrl[UE_id].ul_failure_timer, - UE_list->eNB_UE_stats[CC_id][UE_id].crnti, - UE_list->eNB_UE_stats[CC_id][UE_id].normalized_rx_power, - UE_list->eNB_UE_stats[CC_id][UE_id].target_rx_power, - UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_mcs1, - UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_mcs2, - UE_list->eNB_UE_stats[CC_id][UE_id].rbs_used_rx, - UE_list->eNB_UE_stats[CC_id][UE_id].rbs_used_retx_rx, - UE_list->eNB_UE_stats[CC_id][UE_id].total_rbs_used_rx, - UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_TBS - ); - len += sprintf(&buffer[len], - "[MAC] ULSCH bitrate (TTI %d, avg %d), received bytes (total %"PRIu64")," - "Total received PDU %d, Total errors %d\n", - UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_bitrate, - UE_list->eNB_UE_stats[CC_id][UE_id].total_ulsch_bitrate, - UE_list->eNB_UE_stats[CC_id][UE_id].total_pdu_bytes_rx, - UE_list->eNB_UE_stats[CC_id][UE_id].total_num_pdus_rx, - UE_list->eNB_UE_stats[CC_id][UE_id].num_errors_rx); - len+= sprintf(&buffer[len],"[MAC] Received PHR PH = %d (db)\n", UE_list->UE_template[CC_id][UE_id].phr_info); - len+= sprintf(&buffer[len],"[MAC] Estimated size LCGID[0][1][2][3] = %u %u %u %u\n", - UE_list->UE_template[CC_id][UE_id].ul_buffer_info[LCGID0], - UE_list->UE_template[CC_id][UE_id].ul_buffer_info[LCGID1], - UE_list->UE_template[CC_id][UE_id].ul_buffer_info[LCGID2], - UE_list->UE_template[CC_id][UE_id].ul_buffer_info[LCGID3] - ); - } - - PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, - eNB_id, - ENB_FLAG_YES, - UE_list->eNB_UE_stats[0][UE_id].crnti,//UE_PCCID(eNB_id,UE_id)][UE_id].crnti, - eNB->frame, - eNB->subframe, - eNB_id); - rlc_status = rlc_stat_req(&ctxt, - SRB_FLAG_YES, - DCCH, - &stat_rlc_mode, - &stat_tx_pdcp_sdu, - &stat_tx_pdcp_bytes, - &stat_tx_pdcp_sdu_discarded, - &stat_tx_pdcp_bytes_discarded, - &stat_tx_data_pdu, - &stat_tx_data_bytes, - &stat_tx_retransmit_pdu_by_status, - &stat_tx_retransmit_bytes_by_status, - &stat_tx_retransmit_pdu, - &stat_tx_retransmit_bytes, - &stat_tx_control_pdu, - &stat_tx_control_bytes, - &stat_rx_pdcp_sdu, - &stat_rx_pdcp_bytes, - &stat_rx_data_pdus_duplicate, - &stat_rx_data_bytes_duplicate, - &stat_rx_data_pdu, - &stat_rx_data_bytes, - &stat_rx_data_pdu_dropped, - &stat_rx_data_bytes_dropped, - &stat_rx_data_pdu_out_of_window, - &stat_rx_data_bytes_out_of_window, - &stat_rx_control_pdu, - &stat_rx_control_bytes, - &stat_timer_reordering_timed_out, - &stat_timer_poll_retransmit_timed_out, - &stat_timer_status_prohibit_timed_out); - - if (rlc_status == RLC_OP_STATUS_OK) { - len+=sprintf(&buffer[len],"[RLC] DCCH Mode %s, NB_SDU_TO_TX = %d (bytes %d)\tNB_SDU_TO_TX_DISC %d (bytes %d)\n", - (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE", - stat_tx_pdcp_sdu, - stat_tx_pdcp_bytes, - stat_tx_pdcp_sdu_discarded, - stat_tx_pdcp_bytes_discarded); - len+=sprintf(&buffer[len],"[RLC] DCCH Mode %s, NB_TX_DATA = %d (bytes %d)\tNB_TX_CONTROL %d (bytes %d)\tNB_TX_RETX %d (bytes %d)\tNB_TX_RETX_BY_STATUS = %d (bytes %d)\n", - (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE", - stat_tx_data_pdu, - stat_tx_data_bytes, - stat_tx_control_pdu, - stat_tx_control_bytes, - stat_tx_retransmit_pdu, - stat_tx_retransmit_bytes, - stat_tx_retransmit_pdu_by_status, - stat_tx_retransmit_bytes_by_status); - len+=sprintf(&buffer[len],"[RLC] DCCH Mode %s, NB_RX_DATA = %d (bytes %d)\tNB_RX_CONTROL %d (bytes %d)\tNB_RX_DUPL %d (bytes %d)\tNB_RX_DROP = %d (bytes %d)\tNB_RX_OUT_OF_WINDOW = %d (bytes %d)\n", - (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE", - stat_rx_data_pdu, - stat_rx_data_bytes, - stat_rx_control_pdu, - stat_rx_control_bytes, - stat_rx_data_pdus_duplicate, - stat_rx_data_bytes_duplicate, - stat_rx_data_pdu_dropped, - stat_rx_data_bytes_dropped, - stat_rx_data_pdu_out_of_window, - stat_rx_data_bytes_out_of_window); - len+=sprintf(&buffer[len],"[RLC] DCCH Mode %s, RX_REODERING_TIMEOUT = %d\tRX_POLL_RET_TIMEOUT %d\tRX_PROHIBIT_TIME_OUT %d\n", - (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE", - stat_timer_reordering_timed_out, - stat_timer_poll_retransmit_timed_out, - stat_timer_status_prohibit_timed_out); - len+=sprintf(&buffer[len],"[RLC] DCCH Mode %s, NB_SDU_TO_RX = %d (bytes %d)\n", - (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE", - stat_rx_pdcp_sdu, - stat_rx_pdcp_bytes); - } - - rlc_status = rlc_stat_req(&ctxt, - SRB_FLAG_NO, - DTCH-2, // DRB_IDENTITY - &stat_rlc_mode, - &stat_tx_pdcp_sdu, - &stat_tx_pdcp_bytes, - &stat_tx_pdcp_sdu_discarded, - &stat_tx_pdcp_bytes_discarded, - &stat_tx_data_pdu, - &stat_tx_data_bytes, - &stat_tx_retransmit_pdu_by_status, - &stat_tx_retransmit_bytes_by_status, - &stat_tx_retransmit_pdu, - &stat_tx_retransmit_bytes, - &stat_tx_control_pdu, - &stat_tx_control_bytes, - &stat_rx_pdcp_sdu, - &stat_rx_pdcp_bytes, - &stat_rx_data_pdus_duplicate, - &stat_rx_data_bytes_duplicate, - &stat_rx_data_pdu, - &stat_rx_data_bytes, - &stat_rx_data_pdu_dropped, - &stat_rx_data_bytes_dropped, - &stat_rx_data_pdu_out_of_window, - &stat_rx_data_bytes_out_of_window, - &stat_rx_control_pdu, - &stat_rx_control_bytes, - &stat_timer_reordering_timed_out, - &stat_timer_poll_retransmit_timed_out, - &stat_timer_status_prohibit_timed_out); - - if (rlc_status == RLC_OP_STATUS_OK) { - len+=sprintf(&buffer[len],"[RLC] DTCH Mode %s, NB_SDU_TO_TX = %d (bytes %d)\tNB_SDU_TO_TX_DISC %d (bytes %d)\n", - (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE", - stat_tx_pdcp_sdu, - stat_tx_pdcp_bytes, - stat_tx_pdcp_sdu_discarded, - stat_tx_pdcp_bytes_discarded); - len+=sprintf(&buffer[len],"[RLC] DTCH Mode %s, NB_TX_DATA = %d (bytes %d)\tNB_TX_CONTROL %d (bytes %d)\tNB_TX_RETX %d (bytes %d)\tNB_TX_RETX_BY_STATUS = %d (bytes %d)\n", - (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE", - stat_tx_data_pdu, - stat_tx_data_bytes, - stat_tx_control_pdu, - stat_tx_control_bytes, - stat_tx_retransmit_pdu, - stat_tx_retransmit_bytes, - stat_tx_retransmit_pdu_by_status, - stat_tx_retransmit_bytes_by_status); - len+=sprintf(&buffer[len],"[RLC] DTCH Mode %s, NB_RX_DATA = %d (bytes %d)\tNB_RX_CONTROL %d (bytes %d)\tNB_RX_DUPL %d (bytes %d)\tNB_RX_DROP = %d (bytes %d)\tNB_RX_OUT_OF_WINDOW = %d (bytes %d)\n", - (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE", - stat_rx_data_pdu, - stat_rx_data_bytes, - stat_rx_control_pdu, - stat_rx_control_bytes, - stat_rx_data_pdus_duplicate, - stat_rx_data_bytes_duplicate, - stat_rx_data_pdu_dropped, - stat_rx_data_bytes_dropped, - stat_rx_data_pdu_out_of_window, - stat_rx_data_bytes_out_of_window); - len+=sprintf(&buffer[len],"[RLC] DTCH Mode %s, RX_REODERING_TIMEOUT = %d\tRX_POLL_RET_TIMEOUT %d\tRX_PROHIBIT_TIME_OUT %d\n", - (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE", - stat_timer_reordering_timed_out, - stat_timer_poll_retransmit_timed_out, - stat_timer_status_prohibit_timed_out); - len+=sprintf(&buffer[len],"[RLC] DTCH Mode %s, NB_SDU_TO_RX = %d (bytes %d)\n", - (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE", - stat_rx_pdcp_sdu, - stat_rx_pdcp_bytes); - } + rlc_status = rlc_stat_req(&ctxt, + SRB_FLAG_NO, + DTCH-2, // DRB_IDENTITY + &stat_rlc_mode, + &stat_tx_pdcp_sdu, + &stat_tx_pdcp_bytes, + &stat_tx_pdcp_sdu_discarded, + &stat_tx_pdcp_bytes_discarded, + &stat_tx_data_pdu, + &stat_tx_data_bytes, + &stat_tx_retransmit_pdu_by_status, + &stat_tx_retransmit_bytes_by_status, + &stat_tx_retransmit_pdu, + &stat_tx_retransmit_bytes, + &stat_tx_control_pdu, + &stat_tx_control_bytes, + &stat_rx_pdcp_sdu, + &stat_rx_pdcp_bytes, + &stat_rx_data_pdus_duplicate, + &stat_rx_data_bytes_duplicate, + &stat_rx_data_pdu, + &stat_rx_data_bytes, + &stat_rx_data_pdu_dropped, + &stat_rx_data_bytes_dropped, + &stat_rx_data_pdu_out_of_window, + &stat_rx_data_bytes_out_of_window, + &stat_rx_control_pdu, + &stat_rx_control_bytes, + &stat_timer_reordering_timed_out, + &stat_timer_poll_retransmit_timed_out, + &stat_timer_status_prohibit_timed_out); + + if (rlc_status == RLC_OP_STATUS_OK) { + len+=sprintf(&buffer[len],"[RLC] DTCH Mode %s, NB_SDU_TO_TX = %u (bytes %u)\tNB_SDU_TO_TX_DISC %u (bytes %u)\n", + (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE", + stat_tx_pdcp_sdu, + stat_tx_pdcp_bytes, + stat_tx_pdcp_sdu_discarded, + stat_tx_pdcp_bytes_discarded); + len+=sprintf(&buffer[len],"[RLC] DTCH Mode %s, NB_TX_DATA = %u (bytes %u)\tNB_TX_CONTROL %u (bytes %u)\tNB_TX_RETX %u (bytes %u)\tNB_TX_RETX_BY_STATUS = %u (bytes %u)\n", + (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE", + stat_tx_data_pdu, + stat_tx_data_bytes, + stat_tx_control_pdu, + stat_tx_control_bytes, + stat_tx_retransmit_pdu, + stat_tx_retransmit_bytes, + stat_tx_retransmit_pdu_by_status, + stat_tx_retransmit_bytes_by_status); + len+=sprintf(&buffer[len],"[RLC] DTCH Mode %s, NB_RX_DATA = %u (bytes %u)\tNB_RX_CONTROL %u (bytes %u)\tNB_RX_DUPL %u (bytes %u)\tNB_RX_DROP = %u (bytes %u)\tNB_RX_OUT_OF_WINDOW = %u (bytes %u)\n", + (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE", + stat_rx_data_pdu, + stat_rx_data_bytes, + stat_rx_control_pdu, + stat_rx_control_bytes, + stat_rx_data_pdus_duplicate, + stat_rx_data_bytes_duplicate, + stat_rx_data_pdu_dropped, + stat_rx_data_bytes_dropped, + stat_rx_data_pdu_out_of_window, + stat_rx_data_bytes_out_of_window); + len+=sprintf(&buffer[len],"[RLC] DTCH Mode %s, RX_REODERING_TIMEOUT = %u\tRX_POLL_RET_TIMEOUT %u\tRX_PROHIBIT_TIME_OUT %u\n", + (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE", + stat_timer_reordering_timed_out, + stat_timer_poll_retransmit_timed_out, + stat_timer_status_prohibit_timed_out); + len+=sprintf(&buffer[len],"[RLC] DTCH Mode %s, NB_SDU_TO_RX = %u (bytes %u)\n", + (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE", + stat_rx_pdcp_sdu, + stat_rx_pdcp_bytes); + } + } } - } - return len + 1 /* SR: for trailing \0 */; + return len + 1 /* SR: for trailing \0 */; } #ifdef PROC int openair2_stats_read(char *buffer, char **my_buffer, off_t off, int length) { - int len = 0,fg,Overhead, Sign; - unsigned int i,j,k,kk; - unsigned int Mod_id = 0,CH_index; - unsigned int tx_pdcp_sdu; - unsigned int tx_pdcp_sdu_discarded; - unsigned int tx_retransmit_pdu_unblock; - unsigned int tx_retransmit_pdu_by_status; - unsigned int tx_retransmit_pdu; - unsigned int tx_data_pdu; - unsigned int tx_control_pdu; - unsigned int rx_sdu; - unsigned int rx_error_pdu; - unsigned int rx_data_pdu; - unsigned int rx_data_pdu_out_of_window; - unsigned int rx_control_pdu; - - // if (mac_xface->is_cluster_head == 0) { - for (k=0; k<NB_INST; k++) { - if (Mac_rlc_xface->Is_cluster_head[k] == 0) { + int len = 0,fg,Overhead, Sign; + unsigned int i,j,k,kk; + unsigned int Mod_id = 0,CH_index; + unsigned int tx_pdcp_sdu; + unsigned int tx_pdcp_sdu_discarded; + unsigned int tx_retransmit_pdu_unblock; + unsigned int tx_retransmit_pdu_by_status; + unsigned int tx_retransmit_pdu; + unsigned int tx_data_pdu; + unsigned int tx_control_pdu; + unsigned int rx_sdu; + unsigned int rx_error_pdu; + unsigned int rx_data_pdu; + unsigned int rx_data_pdu_out_of_window; + unsigned int rx_control_pdu; + + // if (mac_xface->is_cluster_head == 0) { + for (k=0; k<NB_INST; k++) { + if (Mac_rlc_xface->Is_cluster_head[k] == 0) { #ifndef PHY_EMUL_ONE_MACHINE - Mod_id=k-NB_CH_INST; - len+=sprintf(&buffer[len],"UE TTI: %d\n",Mac_rlc_xface->frame); - - for (CH_index = 0; CH_index<NB_CNX_UE; CH_index++) { - if (UE_mac_inst[Mod_id].Dcch_lchan[CH_index].Active==1) { - len+=sprintf(&buffer[len],"CH %d: Wideband SINR %d dB---\n", - CH_index,UE_mac_inst[Mod_id].Def_meas[CH_index].Wideband_sinr); - len+=sprintf(&buffer[len],"CH %d: Subband SINR (dB) :", - CH_index); - - for (fg=0; fg<NUMBER_OF_MEASUREMENT_SUBBANDS; fg++) { - len+=sprintf(&buffer[len],"%d ",UE_mac_inst[Mod_id].Def_meas[CH_index].Sinr_meas[0][fg]); - } - - len+=sprintf(&buffer[len],"\n"); - len+=sprintf(&buffer[len],"BCCH %d, NB_RX_MAC = %d (%d errors)\n", - UE_mac_inst[Mod_id].Bcch_lchan[CH_index].Lchan_info.Lchan_id.Index, - UE_mac_inst[Mod_id].Bcch_lchan[CH_index].Lchan_info.NB_RX, - UE_mac_inst[Mod_id].Bcch_lchan[CH_index].Lchan_info.NB_RX_ERRORS); - len+=sprintf(&buffer[len],"CCCH %d, NB_RX_MAC = %d (%d errors)\n", - UE_mac_inst[Mod_id].Ccch_lchan[CH_index].Lchan_info.Lchan_id.Index, - UE_mac_inst[Mod_id].Ccch_lchan[CH_index].Lchan_info.NB_RX, - UE_mac_inst[Mod_id].Ccch_lchan[CH_index].Lchan_info.NB_RX_ERRORS); - len+=sprintf(&buffer[len],"LCHAN %d (DCCH), NB_TX_MAC = %d (%d bits/TTI, %d kbits/sec), NB_RX_MAC = %d (%d errors)\n", - UE_mac_inst[Mod_id].Dcch_lchan[CH_index].Lchan_info.Lchan_id.Index, - UE_mac_inst[Mod_id].Dcch_lchan[CH_index].Lchan_info.NB_TX, - UE_mac_inst[Mod_id].Dcch_lchan[CH_index].Lchan_info.output_rate, - (10*UE_mac_inst[Mod_id].Dcch_lchan[CH_index].Lchan_info.output_rate)>>5, - UE_mac_inst[Mod_id].Dcch_lchan[CH_index].Lchan_info.NB_RX, - UE_mac_inst[Mod_id].Dcch_lchan[CH_index].Lchan_info.NB_RX_ERRORS); - - for(i=1; i<NB_RAB_MAX; i++) { - if (UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Active==1) { - Overhead=UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.output_rate - Pdcp_stats_tx_rate[k][CH_index][i]; - - if(Overhead<0) { - Overhead=-Overhead; - Sign=-1; - } else { - Sign=1; - } - - len+=sprintf(&buffer[len], - "[PDCP]LCHAN %d: NB_TX = %d ,Tx_rate =(%d bits/TTI ,%d Kbits/s), NB_RX = %d ,Rx_rate =(%d bits/TTI ,%d Kbits/s) , LAYER2 TX OVERHEAD: %d Kbits/s\n", - UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.Lchan_id.Index, - Pdcp_stats_tx[k][CH_index][i], - Pdcp_stats_tx_rate[k][CH_index][i], - (10*Pdcp_stats_tx_rate[k][CH_index][i])>>5, - Pdcp_stats_rx[k][CH_index][i], - Pdcp_stats_rx_rate[k][CH_index][i], - (10*Pdcp_stats_rx_rate[k][CH_index][i])>>5, - Sign*(10*Overhead)>>5); - int status = rlc_stat_req (k, - UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.Lchan_id.Index, - &tx_pdcp_sdu, - &tx_pdcp_sdu_discarded, - &tx_retransmit_pdu_unblock, - &tx_retransmit_pdu_by_status, - &tx_retransmit_pdu, - &tx_data_pdu, - &tx_control_pdu, - &rx_sdu, - &rx_error_pdu, - &rx_data_pdu, - &rx_data_pdu_out_of_window, - &rx_control_pdu) ; - - if (status == RLC_OP_STATUS_OK) { - len+=sprintf(&buffer[len],"RLC LCHAN %d, NB_SDU_TO_TX = %d\tNB_SDU_DISC %d\tNB_RX_SDU %d\n", - UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.Lchan_id.Index, + Mod_id=k-NB_CH_INST; + len+=sprintf(&buffer[len],"UE TTI: %d\n",Mac_rlc_xface->frame); + + for (CH_index = 0; CH_index<NB_CNX_UE; CH_index++) { + if (UE_mac_inst[Mod_id].Dcch_lchan[CH_index].Active==1) { + len+=sprintf(&buffer[len],"CH %u: Wideband SINR %d dB---\n", + CH_index,UE_mac_inst[Mod_id].Def_meas[CH_index].Wideband_sinr); + len+=sprintf(&buffer[len],"CH %u: Subband SINR (dB) :", + CH_index); + + for (fg=0; fg<NUMBER_OF_MEASUREMENT_SUBBANDS; fg++) { + len+=sprintf(&buffer[len],"%d ",UE_mac_inst[Mod_id].Def_meas[CH_index].Sinr_meas[0][fg]); + } + + len+=sprintf(&buffer[len],"\n"); + len+=sprintf(&buffer[len],"BCCH %d, NB_RX_MAC = %d (%d errors)\n", + UE_mac_inst[Mod_id].Bcch_lchan[CH_index].Lchan_info.Lchan_id.Index, + UE_mac_inst[Mod_id].Bcch_lchan[CH_index].Lchan_info.NB_RX, + UE_mac_inst[Mod_id].Bcch_lchan[CH_index].Lchan_info.NB_RX_ERRORS); + len+=sprintf(&buffer[len],"CCCH %d, NB_RX_MAC = %d (%d errors)\n", + UE_mac_inst[Mod_id].Ccch_lchan[CH_index].Lchan_info.Lchan_id.Index, + UE_mac_inst[Mod_id].Ccch_lchan[CH_index].Lchan_info.NB_RX, + UE_mac_inst[Mod_id].Ccch_lchan[CH_index].Lchan_info.NB_RX_ERRORS); + len+=sprintf(&buffer[len],"LCHAN %d (DCCH), NB_TX_MAC = %d (%d bits/TTI, %d kbits/sec), NB_RX_MAC = %d (%d errors)\n", + UE_mac_inst[Mod_id].Dcch_lchan[CH_index].Lchan_info.Lchan_id.Index, + UE_mac_inst[Mod_id].Dcch_lchan[CH_index].Lchan_info.NB_TX, + UE_mac_inst[Mod_id].Dcch_lchan[CH_index].Lchan_info.output_rate, + (10*UE_mac_inst[Mod_id].Dcch_lchan[CH_index].Lchan_info.output_rate)>>5, + UE_mac_inst[Mod_id].Dcch_lchan[CH_index].Lchan_info.NB_RX, + UE_mac_inst[Mod_id].Dcch_lchan[CH_index].Lchan_info.NB_RX_ERRORS); + + for(i=1; i<NB_RAB_MAX; i++) { + if (UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Active==1) { + Overhead=UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.output_rate - Pdcp_stats_tx_rate[k][CH_index][i]; + + if(Overhead<0) { + Overhead=-Overhead; + Sign=-1; + } else { + Sign=1; + } + + len+=sprintf(&buffer[len], + "[PDCP]LCHAN %d: NB_TX = %d ,Tx_rate =(%d bits/TTI ,%d Kbits/s), NB_RX = %d ,Rx_rate =(%d bits/TTI ,%d Kbits/s) , LAYER2 TX OVERHEAD: %d Kbits/s\n", + UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.Lchan_id.Index, + Pdcp_stats_tx[k][CH_index][i], + Pdcp_stats_tx_rate[k][CH_index][i], + (10*Pdcp_stats_tx_rate[k][CH_index][i])>>5, + Pdcp_stats_rx[k][CH_index][i], + Pdcp_stats_rx_rate[k][CH_index][i], + (10*Pdcp_stats_rx_rate[k][CH_index][i])>>5, + Sign*(10*Overhead)>>5); + int status = rlc_stat_req (k, + UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.Lchan_id.Index, + &tx_pdcp_sdu, + &tx_pdcp_sdu_discarded, + &tx_retransmit_pdu_unblock, + &tx_retransmit_pdu_by_status, + &tx_retransmit_pdu, + &tx_data_pdu, + &tx_control_pdu, + &rx_sdu, + &rx_error_pdu, + &rx_data_pdu, + &rx_data_pdu_out_of_window, + &rx_control_pdu) ; + + if (status == RLC_OP_STATUS_OK) { + len+=sprintf(&buffer[len],"RLC LCHAN %d, NB_SDU_TO_TX = %u\tNB_SDU_DISC %u\tNB_RX_SDU %u\n", + UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.Lchan_id.Index, + tx_pdcp_sdu, + tx_pdcp_sdu_discarded, + rx_sdu); + len+=sprintf(&buffer[len],"RLC LCHAN %d, NB_TB_TX_DATA = %u\tNB_TB_TX_CONTROL %u\tNB_TX_TB_RETRANS %u", + UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.Lchan_id.Index, + tx_data_pdu, + tx_control_pdu, + tx_retransmit_pdu); + len+=sprintf(&buffer[len],"\tRLC LCHAN %d, NB_TX_TB_RETRANS_BY_STATUS = %u\tNB_TX_TB_RETRANS_PADD %u\n", + UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.Lchan_id.Index, + tx_retransmit_pdu_by_status, + tx_retransmit_pdu_unblock); + len+=sprintf(&buffer[len],"RLC LCHAN %d, NB_RX_DATA = %u\tNB_RX_TB_OUT_WIN %u\tNB_RX_TB_CORRUPT %u\n", + UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.Lchan_id.Index, + rx_data_pdu, + rx_data_pdu_out_of_window, + rx_error_pdu); + } + + len+=sprintf(&buffer[len],"[MAC]: LCHAN %d, NB_TX_MAC = %d (%d bits/TTI, %d kbits/s), NB_RX_MAC = %d (%d errors)\n", + UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.Lchan_id.Index, + UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.NB_TX, + UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.output_rate, + (10*UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.output_rate)>>5, + UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.NB_RX, + UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.NB_RX_ERRORS); + len+=sprintf(&buffer[len]," TX per TB: "); + + for(kk=0; kk<MAX_NUMBER_TB_PER_LCHAN/2; kk++) { + len+=sprintf(&buffer[len],"%d . ",UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.NB_TX_TB[kk]); + } + + len+=sprintf(&buffer[len],"\n"); + len+=sprintf(&buffer[len]," RXerr per TB: "); + + for(kk=0; kk<MAX_NUMBER_TB_PER_LCHAN/2; kk++) + len+=sprintf(&buffer[len],"%d/%d . ",UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.NB_RX_ERRORS_TB[kk], + UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.NB_RX_TB[kk]); + + len+=sprintf(&buffer[len],"\n"); + } + } + } + } + +#endif //PHY_EMUL_ONE_MACHINE + } else if(Mac_rlc_xface->Is_cluster_head[k] ==1) { + Mod_id=k; + len+=sprintf(&buffer[len], + "-------------------------------------------------------------------CH %d: TTI: %d------------------------------------------------------------------\n", + NODE_ID[Mod_id],Mac_rlc_xface->frame); + + for(i=1; i<=NB_CNX_CH; i++) { + if (CH_mac_inst[Mod_id].Dcch_lchan[i].Active==1) { + len+=sprintf(&buffer[len],"\nMR index %u: DL SINR (feedback) %d dB, CQI: %s\n\n", + i,//CH_rrc_inst[Mod_id].Info.UE_list[i].L2_id[0], + CH_mac_inst[Mod_id].Def_meas[i].Wideband_sinr, + print_cqi(CH_mac_inst[Mod_id].Def_meas[i].cqi)); + len+=sprintf(&buffer[len], + "[MAC] LCHAN %d (DCCH), NB_TX_MAC= %d (%d bits/TTI, %d kbits/s), NB_RX_MAC= %d (errors %d, sacch errors %d, sach errors %d, sach_missing %d)\n\n", + CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.Lchan_id.Index, + CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.NB_TX, + CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.output_rate, + (10*CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.output_rate)>>5, + CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.NB_RX, + CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.NB_RX_ERRORS, + CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.NB_RX_SACCH_ERRORS, + CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.NB_RX_SACH_ERRORS, + CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.NB_RX_SACH_MISSING); + + for(j=0; j<NB_RAB_MAX; j++) { + if (CH_mac_inst[Mod_id].Dtch_lchan[j][i].Active==1) { + Overhead=CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.output_rate - Pdcp_stats_tx_rate[k][i][j]; + + if(Overhead<0) { + Overhead=-Overhead; + Sign=-1; + } else { + Sign=1; + } + + len+=sprintf(&buffer[len], + "[PDCP]LCHAN %d: NB_TX = %d ,Tx_rate =(%d bits/TTI ,%d Kbits/s), NB_RX = %d ,Rx_rate =(%d bits/TTI ,%d Kbits/s), LAYER2 TX OVERHEAD= %d Kbits/s\n", + CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Lchan_id.Index, + Pdcp_stats_tx[k][i][j], + Pdcp_stats_tx_rate[k][i][j], + (10*Pdcp_stats_tx_rate[k][i][j])>>5, + Pdcp_stats_rx[k][i][j], + Pdcp_stats_rx_rate[k][i][j], + (10*Pdcp_stats_rx_rate[k][i][j])>>5, + Sign*(10*Overhead)>>5); + int status = rlc_stat_req (k, + CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Lchan_id.Index, + &tx_pdcp_sdu, + &tx_pdcp_sdu_discarded, + &tx_retransmit_pdu_unblock, + &tx_retransmit_pdu_by_status, + &tx_retransmit_pdu, + &tx_data_pdu, + &tx_control_pdu, + &rx_sdu, + &rx_error_pdu, + &rx_data_pdu, + &rx_data_pdu_out_of_window, + &rx_control_pdu) ; + /* + if (status == RLC_OP_STATUS_OK) { + len+=sprintf(&buffer[len],"\t[RLC] LCHAN %d, NB_SDU_TO_TX = %d\tNB_SDU_DISC %d\tNB_RX_SDU %d\n", + CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Lchan_id.Index, tx_pdcp_sdu, tx_pdcp_sdu_discarded, rx_sdu); - len+=sprintf(&buffer[len],"RLC LCHAN %d, NB_TB_TX_DATA = %d\tNB_TB_TX_CONTROL %d\tNB_TX_TB_RETRANS %d", - UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.Lchan_id.Index, + len+=sprintf(&buffer[len],"\t[RLC] LCHAN %d, NB_TB_TX_DATA = %d\tNB_TB_TX_CONTROL %d\tNB_TX_TB_RETRANS %\n", + CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Lchan_id.Index, tx_data_pdu, tx_control_pdu, tx_retransmit_pdu); - len+=sprintf(&buffer[len],"\tRLC LCHAN %d, NB_TX_TB_RETRANS_BY_STATUS = %d\tNB_TX_TB_RETRANS_PADD %d\n", - UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.Lchan_id.Index, + len+=sprintf(&buffer[len],"\t[RLC] LCHAN %d, NB_TX_TB_RETRANS_BY_STATUS = %d\tNB_TX_TB_RETRANS_PADD %d\n", + CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Lchan_id.Index, tx_retransmit_pdu_by_status, tx_retransmit_pdu_unblock); - len+=sprintf(&buffer[len],"RLC LCHAN %d, NB_RX_DATA = %d\tNB_RX_TB_OUT_WIN %d\tNB_RX_TB_CORRUPT %d\n", - UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.Lchan_id.Index, + len+=sprintf(&buffer[len],"\t[RLC] LCHAN %d, NB_RX_DATA = %d\tNB_RX_TB_OUT_WIN %d\tNB_RX_TB_CORRUPT %d\n", + CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Lchan_id.Index, rx_data_pdu, rx_data_pdu_out_of_window, rx_error_pdu); - } - - len+=sprintf(&buffer[len],"[MAC]: LCHAN %d, NB_TX_MAC = %d (%d bits/TTI, %d kbits/s), NB_RX_MAC = %d (%d errors)\n", - UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.Lchan_id.Index, - UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.NB_TX, - UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.output_rate, - (10*UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.output_rate)>>5, - UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.NB_RX, - UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.NB_RX_ERRORS); - len+=sprintf(&buffer[len]," TX per TB: "); - - for(kk=0; kk<MAX_NUMBER_TB_PER_LCHAN/2; kk++) { - len+=sprintf(&buffer[len],"%d . ",UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.NB_TX_TB[kk]); - } - - len+=sprintf(&buffer[len],"\n"); - len+=sprintf(&buffer[len]," RXerr per TB: "); - - for(kk=0; kk<MAX_NUMBER_TB_PER_LCHAN/2; kk++) - len+=sprintf(&buffer[len],"%d/%d . ",UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.NB_RX_ERRORS_TB[kk], - UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.NB_RX_TB[kk]); - - len+=sprintf(&buffer[len],"\n"); - } - } - } - } - -#endif //PHY_EMUL_ONE_MACHINE - } else if(Mac_rlc_xface->Is_cluster_head[k] ==1) { - Mod_id=k; - len+=sprintf(&buffer[len], - "-------------------------------------------------------------------CH %d: TTI: %d------------------------------------------------------------------\n", - NODE_ID[Mod_id],Mac_rlc_xface->frame); - - for(i=1; i<=NB_CNX_CH; i++) { - if (CH_mac_inst[Mod_id].Dcch_lchan[i].Active==1) { - len+=sprintf(&buffer[len],"\nMR index %d: DL SINR (feedback) %d dB, CQI: %s\n\n", - i,//CH_rrc_inst[Mod_id].Info.UE_list[i].L2_id[0], - CH_mac_inst[Mod_id].Def_meas[i].Wideband_sinr, - print_cqi(CH_mac_inst[Mod_id].Def_meas[i].cqi)); - len+=sprintf(&buffer[len], - "[MAC] LCHAN %d (DCCH), NB_TX_MAC= %d (%d bits/TTI, %d kbits/s), NB_RX_MAC= %d (errors %d, sacch errors %d, sach errors %d, sach_missing %d)\n\n", - CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.Lchan_id.Index, - CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.NB_TX, - CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.output_rate, - (10*CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.output_rate)>>5, - CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.NB_RX, - CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.NB_RX_ERRORS, - CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.NB_RX_SACCH_ERRORS, - CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.NB_RX_SACH_ERRORS, - CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.NB_RX_SACH_MISSING); - - for(j=0; j<NB_RAB_MAX; j++) { - if (CH_mac_inst[Mod_id].Dtch_lchan[j][i].Active==1) { - Overhead=CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.output_rate - Pdcp_stats_tx_rate[k][i][j]; - - if(Overhead<0) { - Overhead=-Overhead; - Sign=-1; - } else { - Sign=1; - } - - len+=sprintf(&buffer[len], - "[PDCP]LCHAN %d: NB_TX = %d ,Tx_rate =(%d bits/TTI ,%d Kbits/s), NB_RX = %d ,Rx_rate =(%d bits/TTI ,%d Kbits/s), LAYER2 TX OVERHEAD= %d Kbits/s\n", - CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Lchan_id.Index, - Pdcp_stats_tx[k][i][j], - Pdcp_stats_tx_rate[k][i][j], - (10*Pdcp_stats_tx_rate[k][i][j])>>5, - Pdcp_stats_rx[k][i][j], - Pdcp_stats_rx_rate[k][i][j], - (10*Pdcp_stats_rx_rate[k][i][j])>>5, - Sign*(10*Overhead)>>5); - int status = rlc_stat_req (k, - CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Lchan_id.Index, - &tx_pdcp_sdu, - &tx_pdcp_sdu_discarded, - &tx_retransmit_pdu_unblock, - &tx_retransmit_pdu_by_status, - &tx_retransmit_pdu, - &tx_data_pdu, - &tx_control_pdu, - &rx_sdu, - &rx_error_pdu, - &rx_data_pdu, - &rx_data_pdu_out_of_window, - &rx_control_pdu) ; - /* - if (status == RLC_OP_STATUS_OK) { - len+=sprintf(&buffer[len],"\t[RLC] LCHAN %d, NB_SDU_TO_TX = %d\tNB_SDU_DISC %d\tNB_RX_SDU %d\n", - CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Lchan_id.Index, - tx_pdcp_sdu, - tx_pdcp_sdu_discarded, - rx_sdu); - len+=sprintf(&buffer[len],"\t[RLC] LCHAN %d, NB_TB_TX_DATA = %d\tNB_TB_TX_CONTROL %d\tNB_TX_TB_RETRANS %\n", - CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Lchan_id.Index, - tx_data_pdu, - tx_control_pdu, - tx_retransmit_pdu); - len+=sprintf(&buffer[len],"\t[RLC] LCHAN %d, NB_TX_TB_RETRANS_BY_STATUS = %d\tNB_TX_TB_RETRANS_PADD %d\n", - CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Lchan_id.Index, - tx_retransmit_pdu_by_status, - tx_retransmit_pdu_unblock); - len+=sprintf(&buffer[len],"\t[RLC] LCHAN %d, NB_RX_DATA = %d\tNB_RX_TB_OUT_WIN %d\tNB_RX_TB_CORRUPT %d\n", - CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Lchan_id.Index, - rx_data_pdu, - rx_data_pdu_out_of_window, - rx_error_pdu); - } - */ - len+=sprintf(&buffer[len], - "[MAC]LCHAN %d (CNX %d,RAB %d), NB_TX_MAC= %d (%d bits/TTI, %d kbit/s), NB_RX_MAC= %d (errors %d, sacch_errors %d, sach_errors %d, sach_missing %d)\n", - CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Lchan_id.Index, - i,j, - CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_TX, - CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.output_rate, - (10*CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.output_rate)>>5, - CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_RX, - CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_RX_ERRORS, - CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_RX_SACCH_ERRORS, - CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_RX_SACH_ERRORS, - CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_RX_SACH_MISSING); - len+=sprintf(&buffer[len],"[MAC][SCHEDULER] TX Arrival Rate %d, TX Service Rate %d, RX Arrival rate %d, RX Service rate %d, NB_BW_REQ_RX %d\n\n", - CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Arrival_rate, - CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Tx_rate, - CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Req_rate, - CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Rx_rate, - CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_BW_REQ_RX); - /* - len+=sprintf(&buffer[len]," TX per TB: "); - for(kk=0;kk<MAX_NUMBER_TB_PER_LCHAN/2;kk++) - len+=sprintf(&buffer[len],"%d.",CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_TX_TB[kk]); - len+=sprintf(&buffer[len],"\n"); - len+=sprintf(&buffer[len]," RXerr per TB: "); - for(kk=0;kk<MAX_NUMBER_TB_PER_LCHAN/2;kk++) - len+=sprintf(&buffer[len],"%d/%d . ",CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_RX_ERRORS_TB[kk], - CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_RX_TB[kk]); - len+=sprintf(&buffer[len],"\n"); - */ + } + */ + len+=sprintf(&buffer[len], + "[MAC]LCHAN %d (CNX %u,RAB %u), NB_TX_MAC= %d (%d bits/TTI, %d kbit/s), NB_RX_MAC= %d (errors %d, sacch_errors %d, sach_errors %d, sach_missing %d)\n", + CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Lchan_id.Index, + i,j, + CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_TX, + CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.output_rate, + (10*CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.output_rate)>>5, + CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_RX, + CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_RX_ERRORS, + CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_RX_SACCH_ERRORS, + CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_RX_SACH_ERRORS, + CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_RX_SACH_MISSING); + len+=sprintf(&buffer[len],"[MAC][SCHEDULER] TX Arrival Rate %d, TX Service Rate %d, RX Arrival rate %d, RX Service rate %d, NB_BW_REQ_RX %d\n\n", + CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Arrival_rate, + CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Tx_rate, + CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Req_rate, + CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Rx_rate, + CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_BW_REQ_RX); + /* + len+=sprintf(&buffer[len]," TX per TB: "); + for(kk=0;kk<MAX_NUMBER_TB_PER_LCHAN/2;kk++) + len+=sprintf(&buffer[len],"%d.",CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_TX_TB[kk]); + len+=sprintf(&buffer[len],"\n"); + len+=sprintf(&buffer[len]," RXerr per TB: "); + for(kk=0;kk<MAX_NUMBER_TB_PER_LCHAN/2;kk++) + len+=sprintf(&buffer[len],"%d/%d . ",CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_RX_ERRORS_TB[kk], + CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_RX_TB[kk]); + len+=sprintf(&buffer[len],"\n"); + */ + } + } + } } - } } - } } - } - return len; + return len; } #endif diff --git a/openair3/NAS/UE/API/USER/at_response.c b/openair3/NAS/UE/API/USER/at_response.c index a488aa78d9f7c949564c3553150e040b36981fa8..859db90d7e0d5393045771260e30b35f968e7484 100644 --- a/openair3/NAS/UE/API/USER/at_response.c +++ b/openair3/NAS/UE/API/USER/at_response.c @@ -88,41 +88,41 @@ static int _at_response_encode_cgev (char* buffer, const at_response_t* data); typedef int (*_at_response_encode_function_t) (char* buffer, const at_response_t*); static _at_response_encode_function_t _at_response_encode_function[AT_RESPONSE_ID_MAX] = { - NULL, - _at_response_encode_cgsn, /* CGSN */ - _at_response_encode_cgmi, /* CGMI */ - _at_response_encode_cgmm, /* CGMM */ - _at_response_encode_cgmr, /* CGMR */ - _at_response_encode_cimi, /* CIMI */ - _at_response_encode_cfun, /* CFUN */ - _at_response_encode_cpin, /* CPIN */ - _at_response_encode_csq, /* CSQ */ - _at_response_encode_cesq, /* CESQ */ - _at_response_encode_clac, /* CLAC */ - _at_response_encode_cmee, /* CMEE */ - _at_response_encode_cnum, /* CNUM */ - _at_response_encode_clck, /* CLCK */ - _at_response_encode_cops, /* COPS */ - _at_response_encode_creg, /* CREG */ - _at_response_encode_cgatt, /* CGATT */ - _at_response_encode_cgreg, /* CGREG */ - _at_response_encode_cereg, /* CEREG */ - _at_response_encode_cgdcont, /* CGDCONT */ - _at_response_encode_cgact, /* CGACT */ - _at_response_encode_cgpaddr, /* CGPADDR */ - _at_response_encode_cgev, /* CGEV: unsolicited result */ + NULL, + _at_response_encode_cgsn, /* CGSN */ + _at_response_encode_cgmi, /* CGMI */ + _at_response_encode_cgmm, /* CGMM */ + _at_response_encode_cgmr, /* CGMR */ + _at_response_encode_cimi, /* CIMI */ + _at_response_encode_cfun, /* CFUN */ + _at_response_encode_cpin, /* CPIN */ + _at_response_encode_csq, /* CSQ */ + _at_response_encode_cesq, /* CESQ */ + _at_response_encode_clac, /* CLAC */ + _at_response_encode_cmee, /* CMEE */ + _at_response_encode_cnum, /* CNUM */ + _at_response_encode_clck, /* CLCK */ + _at_response_encode_cops, /* COPS */ + _at_response_encode_creg, /* CREG */ + _at_response_encode_cgatt, /* CGATT */ + _at_response_encode_cgreg, /* CGREG */ + _at_response_encode_cereg, /* CEREG */ + _at_response_encode_cgdcont, /* CGDCONT */ + _at_response_encode_cgact, /* CGACT */ + _at_response_encode_cgpaddr, /* CGPADDR */ + _at_response_encode_cgev, /* CGEV: unsolicited result */ }; /* String representation of Packet Domain events (cf. network_pdn_state_t) */ static const char* _at_response_event_str[] = { - "UNKNOWN EVENT", - "ME PDN ACT", - "NW PDN DEACT", - "ME PDN DEACT", - "NW ACT", - "ME ACT", - "NW DEACT", - "ME DEACT", + "UNKNOWN EVENT", + "ME PDN ACT", + "NW PDN DEACT", + "ME PDN DEACT", + "NW ACT", + "ME ACT", + "NW DEACT", + "ME DEACT", }; /****************************************************************************/ @@ -147,24 +147,24 @@ static const char* _at_response_event_str[] = { ***************************************************************************/ int at_response_encode(char* buffer, const at_response_t* at_response) { - LOG_FUNC_IN; + LOG_FUNC_IN; - int bytes = RETURNerror; - _at_response_encode_function_t encode; + int bytes = RETURNerror; + _at_response_encode_function_t encode; - if (at_response->id < AT_RESPONSE_ID_MAX) { - /* Call encoding function applicable to the AT command response */ - encode = _at_response_encode_function[at_response->id]; + if (at_response->id < AT_RESPONSE_ID_MAX) { + /* Call encoding function applicable to the AT command response */ + encode = _at_response_encode_function[at_response->id]; - if (encode != NULL) { - bytes = (*encode)(buffer, at_response); - } else { - /* Generic encoding: OK, ERROR */ - bytes = 0; + if (encode != NULL) { + bytes = (*encode)(buffer, at_response); + } else { + /* Generic encoding: OK, ERROR */ + bytes = 0; + } } - } - LOG_FUNC_RETURN (bytes); + LOG_FUNC_RETURN (bytes); } /****************************************************************************/ @@ -188,21 +188,21 @@ int at_response_encode(char* buffer, const at_response_t* at_response) ***************************************************************************/ static int _at_response_encode_cgsn(char* buffer, const at_response_t* data) { - LOG_FUNC_IN; + LOG_FUNC_IN; - int offset = 0; + int offset = 0; - if (data->type == AT_COMMAND_ACT) { - const at_cgsn_resp_t * cgsn = &(data->response.cgsn); + if (data->type == AT_COMMAND_ACT) { + const at_cgsn_resp_t * cgsn = &(data->response.cgsn); - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } - offset += sprintf(buffer+offset, "+CGSN: %s\r\n", cgsn->sn); - } + offset += sprintf(buffer+offset, "+CGSN: %s\r\n", cgsn->sn); + } - LOG_FUNC_RETURN (offset); + LOG_FUNC_RETURN (offset); } /**************************************************************************** @@ -222,21 +222,21 @@ static int _at_response_encode_cgsn(char* buffer, const at_response_t* data) ***************************************************************************/ static int _at_response_encode_cgmi(char* buffer, const at_response_t* data) { - LOG_FUNC_IN; + LOG_FUNC_IN; - int offset = 0; + int offset = 0; - if (data->type == AT_COMMAND_ACT) { - const at_cgmi_resp_t * cgmi = &(data->response.cgmi); + if (data->type == AT_COMMAND_ACT) { + const at_cgmi_resp_t * cgmi = &(data->response.cgmi); - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } - offset += sprintf(buffer+offset, "+CGMI: %s\r\n", cgmi->manufacturer); - } + offset += sprintf(buffer+offset, "+CGMI: %s\r\n", cgmi->manufacturer); + } - LOG_FUNC_RETURN (offset); + LOG_FUNC_RETURN (offset); } /**************************************************************************** @@ -256,21 +256,21 @@ static int _at_response_encode_cgmi(char* buffer, const at_response_t* data) ***************************************************************************/ static int _at_response_encode_cgmm(char* buffer, const at_response_t* data) { - LOG_FUNC_IN; + LOG_FUNC_IN; - int offset = 0; + int offset = 0; - if (data->type == AT_COMMAND_ACT) { - const at_cgmm_resp_t * cgmm = &(data->response.cgmm); + if (data->type == AT_COMMAND_ACT) { + const at_cgmm_resp_t * cgmm = &(data->response.cgmm); - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } - offset += sprintf(buffer+offset, "+CGMM: %s\r\n", cgmm->model); - } + offset += sprintf(buffer+offset, "+CGMM: %s\r\n", cgmm->model); + } - LOG_FUNC_RETURN (offset); + LOG_FUNC_RETURN (offset); } /**************************************************************************** @@ -290,21 +290,21 @@ static int _at_response_encode_cgmm(char* buffer, const at_response_t* data) ***************************************************************************/ static int _at_response_encode_cgmr(char* buffer, const at_response_t* data) { - LOG_FUNC_IN; + LOG_FUNC_IN; - int offset = 0; + int offset = 0; - if (data->type == AT_COMMAND_ACT) { - const at_cgmr_resp_t * cgmr = &(data->response.cgmr); + if (data->type == AT_COMMAND_ACT) { + const at_cgmr_resp_t * cgmr = &(data->response.cgmr); - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } - offset += sprintf(buffer+offset, "+CGMR: %s\r\n", cgmr->revision); - } + offset += sprintf(buffer+offset, "+CGMR: %s\r\n", cgmr->revision); + } - LOG_FUNC_RETURN (offset); + LOG_FUNC_RETURN (offset); } /**************************************************************************** @@ -324,21 +324,21 @@ static int _at_response_encode_cgmr(char* buffer, const at_response_t* data) ***************************************************************************/ static int _at_response_encode_cimi(char* buffer, const at_response_t* data) { - LOG_FUNC_IN; + LOG_FUNC_IN; - int offset = 0; + int offset = 0; - if (data->type == AT_COMMAND_ACT) { - const at_cimi_resp_t * cimi = &(data->response.cimi); + if (data->type == AT_COMMAND_ACT) { + const at_cimi_resp_t * cimi = &(data->response.cimi); - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } - offset += sprintf(buffer+offset, "+CIMI: %s\r\n", cimi->IMSI); - } + offset += sprintf(buffer+offset, "+CIMI: %s\r\n", cimi->IMSI); + } - LOG_FUNC_RETURN (offset); + LOG_FUNC_RETURN (offset); } /**************************************************************************** @@ -358,27 +358,27 @@ static int _at_response_encode_cimi(char* buffer, const at_response_t* data) ***************************************************************************/ static int _at_response_encode_cfun(char* buffer, const at_response_t* data) { - LOG_FUNC_IN; + LOG_FUNC_IN; - const at_cfun_resp_t * cfun = &(data->response.cfun); - int offset = 0; + const at_cfun_resp_t * cfun = &(data->response.cfun); + int offset = 0; - if (data->type == AT_COMMAND_GET) { - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } + if (data->type == AT_COMMAND_GET) { + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } - offset += sprintf(buffer+offset, "+CFUN: %d\r\n", cfun->fun); - } else if (data->type == AT_COMMAND_TST) { - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } + offset += sprintf(buffer+offset, "+CFUN: %d\r\n", cfun->fun); + } else if (data->type == AT_COMMAND_TST) { + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } - offset += sprintf(buffer+offset, "+CFUN: (%d-%d),(%d,%d)\r\n", - AT_CFUN_MIN, AT_CFUN_MAX, AT_CFUN_NORST, AT_CFUN_RST); - } + offset += sprintf(buffer+offset, "+CFUN: (%d-%d),(%d,%d)\r\n", + AT_CFUN_MIN, AT_CFUN_MAX, AT_CFUN_NORST, AT_CFUN_RST); + } - LOG_FUNC_RETURN (offset); + LOG_FUNC_RETURN (offset); } /**************************************************************************** @@ -398,21 +398,21 @@ static int _at_response_encode_cfun(char* buffer, const at_response_t* data) ***************************************************************************/ static int _at_response_encode_cpin(char* buffer, const at_response_t* data) { - LOG_FUNC_IN; + LOG_FUNC_IN; - int offset = 0; + int offset = 0; - if (data->type == AT_COMMAND_GET) { - const at_cpin_resp_t * cpin = &(data->response.cpin); + if (data->type == AT_COMMAND_GET) { + const at_cpin_resp_t * cpin = &(data->response.cpin); - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } - offset += sprintf(buffer+offset, "+CPIN: %s\r\n", cpin->code); - } + offset += sprintf(buffer+offset, "+CPIN: %s\r\n", cpin->code); + } - LOG_FUNC_RETURN (offset); + LOG_FUNC_RETURN (offset); } /**************************************************************************** @@ -432,29 +432,29 @@ static int _at_response_encode_cpin(char* buffer, const at_response_t* data) ***************************************************************************/ static int _at_response_encode_csq(char* buffer, const at_response_t* data) { - LOG_FUNC_IN; - - const at_csq_resp_t * csq = &(data->response.csq); - int offset = 0; - - if (data->type == AT_COMMAND_ACT) { - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); + LOG_FUNC_IN; + + const at_csq_resp_t * csq = &(data->response.csq); + int offset = 0; + + if (data->type == AT_COMMAND_ACT) { + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } + + offset += sprintf(buffer+offset, "+CSQ: %d,%d\r\n", + csq->rssi, csq->ber); + } else if (data->type == AT_COMMAND_TST) { + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } + + offset += sprintf(buffer+offset, "+CSQ: (%d-%d),(%d-%d)\r\n", + AT_CSQ_RSSI_0, AT_CSQ_RSSI_31, + AT_CSQ_BER_0, AT_CSQ_BER_7); } - offset += sprintf(buffer+offset, "+CSQ: %d,%d\r\n", - csq->rssi, csq->ber); - } else if (data->type == AT_COMMAND_TST) { - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } - - offset += sprintf(buffer+offset, "+CSQ: (%d-%d),(%d-%d)\r\n", - AT_CSQ_RSSI_0, AT_CSQ_RSSI_31, - AT_CSQ_BER_0, AT_CSQ_BER_7); - } - - LOG_FUNC_RETURN (offset); + LOG_FUNC_RETURN (offset); } /**************************************************************************** @@ -474,35 +474,35 @@ static int _at_response_encode_csq(char* buffer, const at_response_t* data) ***************************************************************************/ static int _at_response_encode_cesq(char* buffer, const at_response_t* data) { - LOG_FUNC_IN; - - const at_cesq_resp_t * cesq = &(data->response.cesq); - int offset = 0; - - if (data->type == AT_COMMAND_ACT) { - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); + LOG_FUNC_IN; + + const at_cesq_resp_t * cesq = &(data->response.cesq); + int offset = 0; + + if (data->type == AT_COMMAND_ACT) { + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } + + offset += sprintf(buffer+offset, "+CESQ: %d,%d,%d,%d,%d,%d\r\n", + cesq->rssi, cesq->ber, cesq->rscp, + cesq->ecno, cesq->rsrq, cesq->rsrp); + } else if (data->type == AT_COMMAND_TST) { + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } + + offset += sprintf(buffer+offset, "+CESQ: (%d-%d),(%d-%d),(%d-%d)," + "(%d-%d),(%d-%d),(%d-%d)\r\n", + AT_CESQ_RSSI_0, AT_CESQ_RSSI_31, + AT_CESQ_BER_0, AT_CESQ_BER_7, + AT_CESQ_RSCP_0, AT_CESQ_RSCP_96, + AT_CESQ_ECNO_0, AT_CESQ_ECNO_49, + AT_CESQ_RSRQ_0, AT_CESQ_RSRQ_34, + AT_CESQ_RSRP_0, AT_CESQ_RSRP_97); } - offset += sprintf(buffer+offset, "+CESQ: %d,%d,%d,%d,%d,%d\r\n", - cesq->rssi, cesq->ber, cesq->rscp, - cesq->ecno, cesq->rsrq, cesq->rsrp); - } else if (data->type == AT_COMMAND_TST) { - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } - - offset += sprintf(buffer+offset, "+CESQ: (%d-%d),(%d-%d),(%d-%d)," - "(%d-%d),(%d-%d),(%d-%d)\r\n", - AT_CESQ_RSSI_0, AT_CESQ_RSSI_31, - AT_CESQ_BER_0, AT_CESQ_BER_7, - AT_CESQ_RSCP_0, AT_CESQ_RSCP_96, - AT_CESQ_ECNO_0, AT_CESQ_ECNO_49, - AT_CESQ_RSRQ_0, AT_CESQ_RSRQ_34, - AT_CESQ_RSRP_0, AT_CESQ_RSRP_97); - } - - LOG_FUNC_RETURN (offset); + LOG_FUNC_RETURN (offset); } /**************************************************************************** @@ -522,27 +522,27 @@ static int _at_response_encode_cesq(char* buffer, const at_response_t* data) ***************************************************************************/ static int _at_response_encode_clac(char* buffer, const at_response_t* data) { - LOG_FUNC_IN; + LOG_FUNC_IN; - const at_clac_resp_t * clac = &(data->response.clac); - int offset = 0; - int i; + const at_clac_resp_t * clac = &(data->response.clac); + int offset = 0; + int i; - if (data->type == AT_COMMAND_ACT) { - if (clac->n_acs > 0) { - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } + if (data->type == AT_COMMAND_ACT) { + if (clac->n_acs > 0) { + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } - offset += sprintf(buffer+offset, "%s", clac->ac[0]); + offset += sprintf(buffer+offset, "%s", clac->ac[0]); - for (i = 1; i < clac->n_acs; i++) { - offset += sprintf(buffer+offset, "\r\n%s", clac->ac[i]); - } + for (i = 1; i < clac->n_acs; i++) { + offset += sprintf(buffer+offset, "\r\n%s", clac->ac[i]); + } + } } - } - LOG_FUNC_RETURN (offset); + LOG_FUNC_RETURN (offset); } /**************************************************************************** @@ -562,22 +562,22 @@ static int _at_response_encode_clac(char* buffer, const at_response_t* data) ***************************************************************************/ static int _at_response_encode_cnum(char* buffer, const at_response_t* data) { - LOG_FUNC_IN; + LOG_FUNC_IN; - int offset = 0; + int offset = 0; - if (data->type == AT_COMMAND_ACT) { - const at_cnum_resp_t * cnum = &(data->response.cnum); + if (data->type == AT_COMMAND_ACT) { + const at_cnum_resp_t * cnum = &(data->response.cnum); - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } - offset += sprintf(buffer+offset, "+CNUM: ,%s,%u\r\n", - cnum->number, cnum->type); - } + offset += sprintf(buffer+offset, "+CNUM: ,%s,%u\r\n", + cnum->number, (unsigned int)cnum->type); + } - LOG_FUNC_RETURN (offset); + LOG_FUNC_RETURN (offset); } /**************************************************************************** @@ -597,26 +597,26 @@ static int _at_response_encode_cnum(char* buffer, const at_response_t* data) ***************************************************************************/ static int _at_response_encode_clck(char* buffer, const at_response_t* data) { - LOG_FUNC_IN; + LOG_FUNC_IN; - const at_clck_resp_t * clck = &(data->response.clck); - int offset = 0; + const at_clck_resp_t * clck = &(data->response.clck); + int offset = 0; - if (data->type == AT_COMMAND_SET) { - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } + if (data->type == AT_COMMAND_SET) { + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } - offset += sprintf(buffer+offset, "+CLCK: %d\r\n", clck->status); - } else if (data->type == AT_COMMAND_TST) { - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } + offset += sprintf(buffer+offset, "+CLCK: %d\r\n", clck->status); + } else if (data->type == AT_COMMAND_TST) { + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } - offset += sprintf(buffer+offset, "+CLCK: %s\r\n", AT_CLCK_SC); - } + offset += sprintf(buffer+offset, "+CLCK: %s\r\n", AT_CLCK_SC); + } - LOG_FUNC_RETURN (offset); + LOG_FUNC_RETURN (offset); } /**************************************************************************** @@ -636,63 +636,63 @@ static int _at_response_encode_clck(char* buffer, const at_response_t* data) ***************************************************************************/ static int _at_response_encode_cops(char* buffer, const at_response_t* data) { - LOG_FUNC_IN; - - int offset = 0; - - if (data->type == AT_COMMAND_GET) { - const at_cops_get_t * cops = &(data->response.cops.get); - - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } - - offset += sprintf(buffer+offset, "+COPS: %d", cops->mode); - - if (data->mask & AT_COPS_RESP_OPER_MASK) { - /* If <oper> is present <format> must be given */ - assert(data->mask & AT_COPS_RESP_FORMAT_MASK); - offset += sprintf(buffer+offset, ",%d", cops->format); - - if (cops->format == AT_COPS_LONG) { - offset += sprintf(buffer+offset, ",%s", - (char*)cops->plmn.id.alpha_long); - } else if (cops->format == AT_COPS_SHORT) { - offset += sprintf(buffer+offset, ",%s", - (char*)cops->plmn.id.alpha_short); - } else if (cops->format == AT_COPS_NUM) { - offset += sprintf(buffer+offset, ",%s", - (char*)cops->plmn.id.num); - } + LOG_FUNC_IN; + + int offset = 0; + + if (data->type == AT_COMMAND_GET) { + const at_cops_get_t * cops = &(data->response.cops.get); + + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } + + offset += sprintf(buffer+offset, "+COPS: %d", cops->mode); + + if (data->mask & AT_COPS_RESP_OPER_MASK) { + /* If <oper> is present <format> must be given */ + assert(data->mask & AT_COPS_RESP_FORMAT_MASK); + offset += sprintf(buffer+offset, ",%d", cops->format); + + if (cops->format == AT_COPS_LONG) { + offset += sprintf(buffer+offset, ",%s", + (char*)cops->plmn.id.alpha_long); + } else if (cops->format == AT_COPS_SHORT) { + offset += sprintf(buffer+offset, ",%s", + (char*)cops->plmn.id.alpha_short); + } else if (cops->format == AT_COPS_NUM) { + offset += sprintf(buffer+offset, ",%s", + (char*)cops->plmn.id.num); + } + } + + if (data->mask & AT_COPS_RESP_ACT_MASK) { + offset += sprintf(buffer+offset, ",%d", cops->AcT); + } + + offset += sprintf(buffer+offset, "\r\n"); + } else if (data->type == AT_COMMAND_TST) { + const at_cops_tst_t * cops = &(data->response.cops.tst); + + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } + + offset += sprintf(buffer+offset, "+COPS: "); + + /* Display the list of operators present in the network */ + strncpy(buffer+offset, cops->data, cops->size); + offset += cops->size; + + /* Display the list of supported network registration modes and + * supported representation formats of network operators */ + //offset += sprintf(buffer+offset, ",,(%d-%d),(%d,%d,%d)", + // AT_COPS_AUTO, AT_COPS_MANAUTO, + // AT_COPS_LONG, AT_COPS_SHORT, AT_COPS_NUM); + offset += sprintf(buffer+offset, "\r\n"); } - if (data->mask & AT_COPS_RESP_ACT_MASK) { - offset += sprintf(buffer+offset, ",%d", cops->AcT); - } - - offset += sprintf(buffer+offset, "\r\n"); - } else if (data->type == AT_COMMAND_TST) { - const at_cops_tst_t * cops = &(data->response.cops.tst); - - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } - - offset += sprintf(buffer+offset, "+COPS: "); - - /* Display the list of operators present in the network */ - strncpy(buffer+offset, cops->data, cops->size); - offset += cops->size; - - /* Display the list of supported network registration modes and - * supported representation formats of network operators */ - //offset += sprintf(buffer+offset, ",,(%d-%d),(%d,%d,%d)", - // AT_COPS_AUTO, AT_COPS_MANAUTO, - // AT_COPS_LONG, AT_COPS_SHORT, AT_COPS_NUM); - offset += sprintf(buffer+offset, "\r\n"); - } - - LOG_FUNC_RETURN (offset); + LOG_FUNC_RETURN (offset); } /**************************************************************************** @@ -712,28 +712,28 @@ static int _at_response_encode_cops(char* buffer, const at_response_t* data) ***************************************************************************/ static int _at_response_encode_cgatt(char* buffer, const at_response_t* data) { - LOG_FUNC_IN; + LOG_FUNC_IN; - int offset = 0; + int offset = 0; - if (data->type == AT_COMMAND_GET) { - const at_cgatt_resp_t * cgatt = &(data->response.cgatt); + if (data->type == AT_COMMAND_GET) { + const at_cgatt_resp_t * cgatt = &(data->response.cgatt); - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } - offset += sprintf(buffer+offset, "+CGATT: %d\r\n", cgatt->state); - } else if (data->type == AT_COMMAND_TST) { - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } + offset += sprintf(buffer+offset, "+CGATT: %d\r\n", cgatt->state); + } else if (data->type == AT_COMMAND_TST) { + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } - offset += sprintf(buffer+offset, "+CGATT: (%d,%d)\r\n", - AT_CGATT_STATE_MIN, AT_CGATT_STATE_MAX); - } + offset += sprintf(buffer+offset, "+CGATT: (%d,%d)\r\n", + AT_CGATT_STATE_MIN, AT_CGATT_STATE_MAX); + } - LOG_FUNC_RETURN (offset); + LOG_FUNC_RETURN (offset); } /**************************************************************************** @@ -753,43 +753,43 @@ static int _at_response_encode_cgatt(char* buffer, const at_response_t* data) ***************************************************************************/ static int _at_response_encode_creg(char* buffer, const at_response_t* data) { - LOG_FUNC_IN; + LOG_FUNC_IN; - int offset = 0; + int offset = 0; - if (data->type == AT_COMMAND_GET) { - const at_creg_resp_t * creg = &(data->response.creg); + if (data->type == AT_COMMAND_GET) { + const at_creg_resp_t * creg = &(data->response.creg); - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } - offset += sprintf(buffer+offset, "+CREG: %d,%d", - creg->n, creg->stat); + offset += sprintf(buffer+offset, "+CREG: %d,%d", + creg->n, creg->stat); - if (data->mask & AT_CREG_RESP_LAC_MASK) { - offset += sprintf(buffer+offset, ",%s", creg->lac); - } + if (data->mask & AT_CREG_RESP_LAC_MASK) { + offset += sprintf(buffer+offset, ",%s", creg->lac); + } - if (data->mask & AT_CREG_RESP_CI_MASK) { - offset += sprintf(buffer+offset, ",%s", creg->ci); - } + if (data->mask & AT_CREG_RESP_CI_MASK) { + offset += sprintf(buffer+offset, ",%s", creg->ci); + } - if (data->mask & AT_CREG_RESP_ACT_MASK) { - offset += sprintf(buffer+offset, ",%d", creg->AcT); - } + if (data->mask & AT_CREG_RESP_ACT_MASK) { + offset += sprintf(buffer+offset, ",%d", creg->AcT); + } - offset += sprintf(buffer+offset, "\r\n"); - } else if (data->type == AT_COMMAND_TST) { - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } + offset += sprintf(buffer+offset, "\r\n"); + } else if (data->type == AT_COMMAND_TST) { + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } - offset += sprintf(buffer+offset, "+CREG: (%d-%d)\r\n", - AT_CREG_N_MIN, AT_CREG_N_MAX); - } + offset += sprintf(buffer+offset, "+CREG: (%d-%d)\r\n", + AT_CREG_N_MIN, AT_CREG_N_MAX); + } - LOG_FUNC_RETURN (offset); + LOG_FUNC_RETURN (offset); } /**************************************************************************** @@ -809,47 +809,47 @@ static int _at_response_encode_creg(char* buffer, const at_response_t* data) ***************************************************************************/ static int _at_response_encode_cgreg(char* buffer, const at_response_t* data) { - LOG_FUNC_IN; + LOG_FUNC_IN; - int offset = 0; + int offset = 0; - if (data->type == AT_COMMAND_GET) { - const at_cgreg_resp_t * cgreg = &(data->response.cgreg); + if (data->type == AT_COMMAND_GET) { + const at_cgreg_resp_t * cgreg = &(data->response.cgreg); - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } - offset += sprintf(buffer+offset, "+CGREG: %d,%d", - cgreg->n, cgreg->stat); + offset += sprintf(buffer+offset, "+CGREG: %d,%d", + cgreg->n, cgreg->stat); - if (data->mask & AT_CGREG_RESP_LAC_MASK) { - offset += sprintf(buffer+offset, ",%s", cgreg->lac); - } + if (data->mask & AT_CGREG_RESP_LAC_MASK) { + offset += sprintf(buffer+offset, ",%s", cgreg->lac); + } - if (data->mask & AT_CGREG_RESP_CI_MASK) { - offset += sprintf(buffer+offset, ",%s", cgreg->ci); - } + if (data->mask & AT_CGREG_RESP_CI_MASK) { + offset += sprintf(buffer+offset, ",%s", cgreg->ci); + } - if (data->mask & AT_CGREG_RESP_ACT_MASK) { - offset += sprintf(buffer+offset, ",%d", cgreg->AcT); - } + if (data->mask & AT_CGREG_RESP_ACT_MASK) { + offset += sprintf(buffer+offset, ",%d", cgreg->AcT); + } - if (data->mask & AT_CGREG_RESP_RAC_MASK) { - offset += sprintf(buffer+offset, ",%s", cgreg->rac); - } + if (data->mask & AT_CGREG_RESP_RAC_MASK) { + offset += sprintf(buffer+offset, ",%s", cgreg->rac); + } - offset += sprintf(buffer+offset, "\r\n"); - } else if (data->type == AT_COMMAND_TST) { - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } + offset += sprintf(buffer+offset, "\r\n"); + } else if (data->type == AT_COMMAND_TST) { + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } - offset += sprintf(buffer+offset, "+CGREG: (%d-%d)\r\n", - AT_CGREG_N_MIN, AT_CGREG_N_MAX); - } + offset += sprintf(buffer+offset, "+CGREG: (%d-%d)\r\n", + AT_CGREG_N_MIN, AT_CGREG_N_MAX); + } - LOG_FUNC_RETURN (offset); + LOG_FUNC_RETURN (offset); } /**************************************************************************** @@ -869,43 +869,43 @@ static int _at_response_encode_cgreg(char* buffer, const at_response_t* data) ***************************************************************************/ static int _at_response_encode_cereg(char* buffer, const at_response_t* data) { - LOG_FUNC_IN; + LOG_FUNC_IN; - int offset = 0; + int offset = 0; - if (data->type == AT_COMMAND_GET) { - const at_cereg_resp_t * cereg = &(data->response.cereg); + if (data->type == AT_COMMAND_GET) { + const at_cereg_resp_t * cereg = &(data->response.cereg); - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } - offset += sprintf(buffer+offset, "+CEREG: %d,%d", - cereg->n, cereg->stat); + offset += sprintf(buffer+offset, "+CEREG: %d,%d", + cereg->n, cereg->stat); - if (data->mask & AT_CEREG_RESP_TAC_MASK) { - offset += sprintf(buffer+offset, ",%s", cereg->tac); - } + if (data->mask & AT_CEREG_RESP_TAC_MASK) { + offset += sprintf(buffer+offset, ",%s", cereg->tac); + } - if (data->mask & AT_CEREG_RESP_CI_MASK) { - offset += sprintf(buffer+offset, ",%s", cereg->ci); - } + if (data->mask & AT_CEREG_RESP_CI_MASK) { + offset += sprintf(buffer+offset, ",%s", cereg->ci); + } - if (data->mask & AT_CEREG_RESP_ACT_MASK) { - offset += sprintf(buffer+offset, ",%d", cereg->AcT); - } + if (data->mask & AT_CEREG_RESP_ACT_MASK) { + offset += sprintf(buffer+offset, ",%d", cereg->AcT); + } - offset += sprintf(buffer+offset, "\r\n"); - } else if (data->type == AT_COMMAND_TST) { - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } + offset += sprintf(buffer+offset, "\r\n"); + } else if (data->type == AT_COMMAND_TST) { + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } - offset += sprintf(buffer+offset, "+CEREG: (%d-%d)\r\n", - AT_CEREG_N_MIN, AT_CEREG_N_MAX); - } + offset += sprintf(buffer+offset, "+CEREG: (%d-%d)\r\n", + AT_CEREG_N_MIN, AT_CEREG_N_MAX); + } - LOG_FUNC_RETURN (offset); + LOG_FUNC_RETURN (offset); } /**************************************************************************** @@ -925,65 +925,65 @@ static int _at_response_encode_cereg(char* buffer, const at_response_t* data) ***************************************************************************/ static int _at_response_encode_cgdcont(char* buffer, const at_response_t* data) { - LOG_FUNC_IN; - - int offset = 0; - int i; - - if (data->type == AT_COMMAND_GET) { - const at_cgdcont_get_t * cgdcont = &(data->response.cgdcont.get); - - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); + LOG_FUNC_IN; + + int offset = 0; + int i; + + if (data->type == AT_COMMAND_GET) { + const at_cgdcont_get_t * cgdcont = &(data->response.cgdcont.get); + + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } + + /* Display the list of defined PDN contexts */ + for (i = 0; i < cgdcont->n_pdns; i++) { + offset += sprintf(buffer+offset, "+CGDCONT: %u", (unsigned int)cgdcont->cid[i]); + + if (cgdcont->PDP_type[i] == NET_PDN_TYPE_IPV4) { + offset += sprintf(buffer+offset, ",IP"); + } else if (cgdcont->PDP_type[i] == NET_PDN_TYPE_IPV6) { + offset += sprintf(buffer+offset, ",IPV6"); + } else if (cgdcont->PDP_type[i] == NET_PDN_TYPE_IPV4V6) { + offset += sprintf(buffer+offset, ",IPV4V6"); + } + + offset += sprintf(buffer+offset, ",%s", cgdcont->APN[i]); + /* No data/header compression */ + offset += sprintf(buffer+offset, ",%u,%u\r\n", + (unsigned int)(AT_CGDCONT_D_COMP_OFF), (unsigned int)(AT_CGDCONT_H_COMP_OFF)); + } + } else if (data->type == AT_COMMAND_TST) { + const at_cgdcont_tst_t * cgdcont = &(data->response.cgdcont.tst); + + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } + + /* IPv4 PDN type */ + offset += sprintf(buffer+offset, "+CGDCONT: "); + offset += sprintf(buffer+offset, "(1-%d),IP,,,(%d-%d),(%d-%d)", + cgdcont->n_cid, + AT_CGDCONT_D_COMP_MIN, AT_CGDCONT_D_COMP_MAX, + AT_CGDCONT_H_COMP_MIN, AT_CGDCONT_H_COMP_MAX); + /* IPv6 PDN type */ + offset += sprintf(buffer+offset, "\r\n+CGDCONT: "); + offset += sprintf(buffer+offset, "(1-%d),IPV6,,,(%d-%d),(%d-%d)", + cgdcont->n_cid, + AT_CGDCONT_D_COMP_MIN, AT_CGDCONT_D_COMP_MAX, + AT_CGDCONT_H_COMP_MIN, AT_CGDCONT_H_COMP_MAX); + /* IPv4v6 PDN type */ + offset += sprintf(buffer+offset, "\r\n+CGDCONT: "); + offset += sprintf(buffer+offset, "(1-%d),IPV4V6,,,(%d-%d),(%d-%d)", + cgdcont->n_cid, + AT_CGDCONT_D_COMP_MIN, AT_CGDCONT_D_COMP_MAX, + AT_CGDCONT_H_COMP_MIN, AT_CGDCONT_H_COMP_MAX); + + offset += sprintf(buffer+offset, "\r\n"); } - /* Display the list of defined PDN contexts */ - for (i = 0; i < cgdcont->n_pdns; i++) { - offset += sprintf(buffer+offset, "+CGDCONT: %u", cgdcont->cid[i]); - - if (cgdcont->PDP_type[i] == NET_PDN_TYPE_IPV4) { - offset += sprintf(buffer+offset, ",IP"); - } else if (cgdcont->PDP_type[i] == NET_PDN_TYPE_IPV6) { - offset += sprintf(buffer+offset, ",IPV6"); - } else if (cgdcont->PDP_type[i] == NET_PDN_TYPE_IPV4V6) { - offset += sprintf(buffer+offset, ",IPV4V6"); - } - - offset += sprintf(buffer+offset, ",%s", cgdcont->APN[i]); - /* No data/header compression */ - offset += sprintf(buffer+offset, ",%u,%u\r\n", - AT_CGDCONT_D_COMP_OFF, AT_CGDCONT_H_COMP_OFF); - } - } else if (data->type == AT_COMMAND_TST) { - const at_cgdcont_tst_t * cgdcont = &(data->response.cgdcont.tst); - - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } - - /* IPv4 PDN type */ - offset += sprintf(buffer+offset, "+CGDCONT: "); - offset += sprintf(buffer+offset, "(1-%u),IP,,,(%u-%u),(%u-%u)", - cgdcont->n_cid, - AT_CGDCONT_D_COMP_MIN, AT_CGDCONT_D_COMP_MAX, - AT_CGDCONT_H_COMP_MIN, AT_CGDCONT_H_COMP_MAX); - /* IPv6 PDN type */ - offset += sprintf(buffer+offset, "\r\n+CGDCONT: "); - offset += sprintf(buffer+offset, "(1-%u),IPV6,,,(%u-%u),(%u-%u)", - cgdcont->n_cid, - AT_CGDCONT_D_COMP_MIN, AT_CGDCONT_D_COMP_MAX, - AT_CGDCONT_H_COMP_MIN, AT_CGDCONT_H_COMP_MAX); - /* IPv4v6 PDN type */ - offset += sprintf(buffer+offset, "\r\n+CGDCONT: "); - offset += sprintf(buffer+offset, "(1-%u),IPV4V6,,,(%u-%u),(%u-%u)", - cgdcont->n_cid, - AT_CGDCONT_D_COMP_MIN, AT_CGDCONT_D_COMP_MAX, - AT_CGDCONT_H_COMP_MIN, AT_CGDCONT_H_COMP_MAX); - - offset += sprintf(buffer+offset, "\r\n"); - } - - LOG_FUNC_RETURN (offset); + LOG_FUNC_RETURN (offset); } /**************************************************************************** @@ -1003,33 +1003,33 @@ static int _at_response_encode_cgdcont(char* buffer, const at_response_t* data) ***************************************************************************/ static int _at_response_encode_cgact(char* buffer, const at_response_t* data) { - LOG_FUNC_IN; - - int offset = 0; - int i; - - if (data->type == AT_COMMAND_GET) { - const at_cgact_resp_t * cgact = &(data->response.cgact); - - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); + LOG_FUNC_IN; + + int offset = 0; + int i; + + if (data->type == AT_COMMAND_GET) { + const at_cgact_resp_t * cgact = &(data->response.cgact); + + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } + + /* Display the list of defined PDN status */ + for (i = 0; i < cgact->n_pdns; i++) { + offset += sprintf(buffer+offset, "+CGACT: %u,%u\r\n", + (unsigned int)cgact->cid[i], (unsigned int)cgact->state[i]); + } + } else if (data->type == AT_COMMAND_TST) { + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } + + offset += sprintf(buffer+offset, "+CGACT: (%d,%d)\r\n", + AT_CGACT_STATE_MIN, AT_CGACT_STATE_MAX); } - /* Display the list of defined PDN status */ - for (i = 0; i < cgact->n_pdns; i++) { - offset += sprintf(buffer+offset, "+CGACT: %u,%u\r\n", - cgact->cid[i], cgact->state[i]); - } - } else if (data->type == AT_COMMAND_TST) { - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } - - offset += sprintf(buffer+offset, "+CGACT: (%d,%d)\r\n", - AT_CGACT_STATE_MIN, AT_CGACT_STATE_MAX); - } - - LOG_FUNC_RETURN (offset); + LOG_FUNC_RETURN (offset); } /**************************************************************************** @@ -1049,69 +1049,72 @@ static int _at_response_encode_cgact(char* buffer, const at_response_t* data) ***************************************************************************/ static int _at_response_encode_cgpaddr(char* buffer, const at_response_t* data) { - LOG_FUNC_IN; - - int offset = 0; - const at_cgpaddr_resp_t * cgpaddr = &(data->response.cgpaddr); - int i; - - if (data->type == AT_COMMAND_SET) { - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } - - /* Display the list of IP addresses assigned to each defined PDN - * connections */ - for (i = 0; i < cgpaddr->n_pdns; i++) { - offset += sprintf(buffer+offset, "+CGPADDR: %u", cgpaddr->cid[i]); - - if (cgpaddr->PDP_addr_1[i] != NULL) { - /* IPv4 address */ - offset += sprintf(buffer+offset, ",%hhu.%hhu.%hhu.%hhu", - cgpaddr->PDP_addr_1[i][0], - cgpaddr->PDP_addr_1[i][1], - cgpaddr->PDP_addr_1[i][2], - cgpaddr->PDP_addr_1[i][3]); - } - - if (cgpaddr->PDP_addr_2[i] != NULL) { - /* IPv6 Link-local address prefixe */ - offset += sprintf(buffer+offset, - ",%hhu.%hhu.%hhu.%hhu.%hhu.%hhu.%hhu.%hhu", - 0xfe, 0x80, 0, 0, 0, 0, 0, 0); - /* IPv6 Link-local address */ - offset += sprintf(buffer+offset, - ".%hhu.%hhu.%hhu.%hhu.%hhu.%hhu.%hhu.%hhu", - cgpaddr->PDP_addr_2[i][0], - cgpaddr->PDP_addr_2[i][1], - cgpaddr->PDP_addr_2[i][2], - cgpaddr->PDP_addr_2[i][3], - cgpaddr->PDP_addr_2[i][4], - cgpaddr->PDP_addr_2[i][5], - cgpaddr->PDP_addr_2[i][6], - cgpaddr->PDP_addr_2[i][7]); - } - - offset += sprintf(buffer+offset, "\r\n"); + LOG_FUNC_IN; + + int offset = 0; + const at_cgpaddr_resp_t * cgpaddr = &(data->response.cgpaddr); + int i; + + if (data->type == AT_COMMAND_SET) { + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } + + /* Display the list of IP addresses assigned to each defined PDN + * connections */ + for (i = 0; i < cgpaddr->n_pdns; i++) { + offset += sprintf(buffer+offset, "+CGPADDR: %u", (unsigned int)cgpaddr->cid[i]); + + if (cgpaddr->PDP_addr_1[i] != NULL) { + /* IPv4 address */ + offset += sprintf(buffer+offset, ",%hhu.%hhu.%hhu.%hhu", + (unsigned int)cgpaddr->PDP_addr_1[i][0], + (unsigned int)cgpaddr->PDP_addr_1[i][1], + (unsigned int)cgpaddr->PDP_addr_1[i][2], + (unsigned int)cgpaddr->PDP_addr_1[i][3]); + } + + if (cgpaddr->PDP_addr_2[i] != NULL) { + /* IPv6 Link-local address prefixe */ + offset += sprintf(buffer+offset, + ",%hhu.%hhu.%hhu.%hhu.%hhu.%hhu.%hhu.%hhu", + (unsigned int)0xfe, (unsigned int)0x80, + (unsigned int)0, (unsigned int)0, + (unsigned int)0, (unsigned int)0, + (unsigned int)0, (unsigned int)0); + /* IPv6 Link-local address */ + offset += sprintf(buffer+offset, + ".%hhu.%hhu.%hhu.%hhu.%hhu.%hhu.%hhu.%hhu", + (unsigned int)cgpaddr->PDP_addr_2[i][0], + (unsigned int)cgpaddr->PDP_addr_2[i][1], + (unsigned int)cgpaddr->PDP_addr_2[i][2], + (unsigned int)cgpaddr->PDP_addr_2[i][3], + (unsigned int)cgpaddr->PDP_addr_2[i][4], + (unsigned int)cgpaddr->PDP_addr_2[i][5], + (unsigned int)cgpaddr->PDP_addr_2[i][6], + (unsigned int)cgpaddr->PDP_addr_2[i][7]); + } + + offset += sprintf(buffer+offset, "\r\n"); + } + } else if (data->type == AT_COMMAND_TST) { + /* Display the list of defined PDN contexts */ + if (cgpaddr->n_pdns > 0) { + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } + + offset += sprintf(buffer+offset, "+CGPADDR: %u", (unsigned int)cgpaddr->cid[0]); + + for (i = 1; i < cgpaddr->n_pdns; i++) { + offset += sprintf(buffer+offset, ",%u", (unsigned int)cgpaddr->cid[i]); + } + + offset += sprintf(buffer+offset, "\r\n"); + } } - } else if (data->type == AT_COMMAND_TST) { - /* Display the list of defined PDN contexts */ - if (cgpaddr->n_pdns > 0) { - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } - offset += sprintf(buffer+offset, "+CGPADDR: %u", cgpaddr->cid[0]); - - for (i = 1; i < cgpaddr->n_pdns; i++) { - offset += sprintf(buffer+offset, ",%u", cgpaddr->cid[i]); - } - - offset += sprintf(buffer+offset, "\r\n"); - } - } - - LOG_FUNC_RETURN (offset); + LOG_FUNC_RETURN (offset); } /**************************************************************************** @@ -1131,28 +1134,28 @@ static int _at_response_encode_cgpaddr(char* buffer, const at_response_t* data) ***************************************************************************/ static int _at_response_encode_cmee(char* buffer, const at_response_t* data) { - LOG_FUNC_IN; + LOG_FUNC_IN; - int offset = 0; + int offset = 0; - if (data->type == AT_COMMAND_GET) { - const at_cmee_resp_t * cmee = &(data->response.cmee); + if (data->type == AT_COMMAND_GET) { + const at_cmee_resp_t * cmee = &(data->response.cmee); - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } - offset += sprintf(buffer+offset, "+CMEE: %d\r\n", cmee->n); - } else if (data->type == AT_COMMAND_TST) { - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } + offset += sprintf(buffer+offset, "+CMEE: %d\r\n", cmee->n); + } else if (data->type == AT_COMMAND_TST) { + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } - offset += sprintf(buffer+offset, "+CMEE: (%d,%d)\r\n", - AT_CMEE_N_MIN, AT_CMEE_N_MAX); - } + offset += sprintf(buffer+offset, "+CMEE: (%d,%d)\r\n", + AT_CMEE_N_MIN, AT_CMEE_N_MAX); + } - LOG_FUNC_RETURN (offset); + LOG_FUNC_RETURN (offset); } /**************************************************************************** @@ -1172,16 +1175,16 @@ static int _at_response_encode_cmee(char* buffer, const at_response_t* data) ***************************************************************************/ static int _at_response_encode_cgev(char* buffer, const at_response_t* data) { - LOG_FUNC_IN; + LOG_FUNC_IN; - int offset = 0; + int offset = 0; - if (data->type == AT_COMMAND_GET) { - const at_cgev_resp_t * cgev = &(data->response.cgev); - offset += sprintf(buffer+offset, "+CGEV: %s %u\r\n", - _at_response_event_str[cgev->code], cgev->cid); - } + if (data->type == AT_COMMAND_GET) { + const at_cgev_resp_t * cgev = &(data->response.cgev); + offset += sprintf(buffer+offset, "+CGEV: %s %u\r\n", + _at_response_event_str[cgev->code], (unsigned int)cgev->cid); + } - LOG_FUNC_RETURN (offset); + LOG_FUNC_RETURN (offset); } diff --git a/openair3/NAS/UE/ESM/PdnConnectivity.c b/openair3/NAS/UE/ESM/PdnConnectivity.c index f0f4efa769f5180dc5b73f5c31ea04ada5e71a49..48730f2ca9d2f68e981f8268362d89b8af8bde1b 100644 --- a/openair3/NAS/UE/ESM/PdnConnectivity.c +++ b/openair3/NAS/UE/ESM/PdnConnectivity.c @@ -138,119 +138,119 @@ int esm_proc_pdn_connectivity(nas_user_t *user, int cid, int is_to_define, const OctetString *apn, int is_emergency, unsigned int *pti) { - LOG_FUNC_IN; + LOG_FUNC_IN; - int rc = RETURNerror; - int pid = cid - 1; - esm_data_t *esm_data = user-> esm_data; - esm_pt_data_t *esm_pt_data = user-> esm_pt_data; + int rc = RETURNerror; + int pid = cid - 1; + esm_data_t *esm_data = user-> esm_data; + esm_pt_data_t *esm_pt_data = user-> esm_pt_data; - if (!is_to_define) { - LOG_TRACE(INFO, "ESM-PROC - Undefine PDN connection (cid=%d)", cid); - /* Delete the PDN connection entry */ - int pti = _pdn_connectivity_delete(esm_data, pid); + if (!is_to_define) { + LOG_TRACE(INFO, "ESM-PROC - Undefine PDN connection (cid=%d)", cid); + /* Delete the PDN connection entry */ + int pti = _pdn_connectivity_delete(esm_data, pid); - if (pti != ESM_PT_UNASSIGNED) { - /* Release the procedure transaction data */ - rc = esm_pt_release(esm_pt_data, pti); - } + if (pti != ESM_PT_UNASSIGNED) { + /* Release the procedure transaction data */ + rc = esm_pt_release(esm_pt_data, pti); + } - LOG_FUNC_RETURN(rc); - } else if (pti != NULL) { - LOG_TRACE(INFO, "ESM-PROC - Assign new procedure transaction identity " - "(cid=%d)", cid); - /* Assign new procedure transaction identity */ - *pti = esm_pt_assign(esm_pt_data); - - if (*pti == ESM_PT_UNASSIGNED) { - LOG_TRACE(WARNING, "ESM-PROC - Failed to assign new procedure " - "transaction identity"); - LOG_FUNC_RETURN (RETURNerror); - } + LOG_FUNC_RETURN(rc); + } else if (pti != NULL) { + LOG_TRACE(INFO, "ESM-PROC - Assign new procedure transaction identity " + "(cid=%d)", cid); + /* Assign new procedure transaction identity */ + *pti = esm_pt_assign(esm_pt_data); + + if (*pti == ESM_PT_UNASSIGNED) { + LOG_TRACE(WARNING, "ESM-PROC - Failed to assign new procedure " + "transaction identity"); + LOG_FUNC_RETURN (RETURNerror); + } - /* Update the PDN connection data */ - rc = _pdn_connectivity_set_pti(esm_data, pid, *pti); + /* Update the PDN connection data */ + rc = _pdn_connectivity_set_pti(esm_data, pid, *pti); - if (rc != RETURNok) { - LOG_TRACE(WARNING, "ESM-PROC - Failed to update PDN connection"); - } + if (rc != RETURNok) { + LOG_TRACE(WARNING, "ESM-PROC - Failed to update PDN connection"); + } - LOG_FUNC_RETURN (rc); - } - - LOG_TRACE(INFO,"ESM-PROC - Define new %s PDN connection to APN %s (cid=%d)", - (pdn_type == ESM_PDN_TYPE_IPV4)? "IPv4" : - (pdn_type == ESM_PDN_TYPE_IPV6)? "IPv6" : "IPv4v6", - apn->value, cid); - - if (is_emergency && esm_data->emergency) { - /* The UE shall not request additional PDN connection for - * emergency bearer services */ - LOG_TRACE(WARNING, "ESM-PROC - PDN connection for emergency bearer " - "services is already active"); - LOG_FUNC_RETURN (RETURNerror); - } else if (pid < ESM_DATA_PDN_MAX) { - if ((pid == esm_data->pdn[pid].pid) && (esm_data->pdn[pid].is_active)) { - /* PDN connection with the specified identifier is active */ - LOG_TRACE(WARNING, "ESM-PROC - PDN connection is active"); - LOG_FUNC_RETURN (RETURNerror); + LOG_FUNC_RETURN (rc); } - } else { - LOG_TRACE(WARNING, "ESM-PROC - PDN connection identifier is not valid"); - LOG_FUNC_RETURN (RETURNerror); - } - - if (apn && apn->length > 0) { - /* The UE requested subsequent connectivity to additionnal PDNs */ - int pid = _pdn_connectivity_find_apn(esm_data, apn); - - if ( (pid >= 0) && esm_data->pdn[pid].is_active ) { - /* An active PDN connection to this APN already exists */ - if ( (esm_data->pdn[pid].data->type != ESM_PDN_TYPE_IPV4V6) && - (esm_data->pdn[pid].data->type != pdn_type) ) { - /* The UE is requesting PDN connection for other IP version - * than the one already activated */ - if (!esm_data->pdn[pid].data->addr_realloc) { - /* The network does not allow PDN connectivity using - * IPv4 and IPv6 address versions to the same APN */ - if (pdn_type != ESM_PDN_TYPE_IPV4V6) { - LOG_TRACE(WARNING, "ESM-PROC - %s PDN connectivity to " - "%s is not allowed by the network", - (pdn_type != ESM_PDN_TYPE_IPV4)? "IPv6" : - "IPv4", apn->value); - } else { - LOG_TRACE(WARNING, "ESM-PROC - %s PDN connection to %s " - "already exists", - (esm_data->pdn[pid].data->type != - ESM_PDN_TYPE_IPV4)? "IPv6" : "IPv4", - apn->value); - } - - LOG_FUNC_RETURN (RETURNerror); + + LOG_TRACE(INFO,"ESM-PROC - Define new %s PDN connection to APN %s (cid=%d)", + (pdn_type == ESM_PDN_TYPE_IPV4)? "IPv4" : + (pdn_type == ESM_PDN_TYPE_IPV6)? "IPv6" : "IPv4v6", + (apn!=NULL)?apn->value:0, cid); + + if (is_emergency && esm_data->emergency) { + /* The UE shall not request additional PDN connection for + * emergency bearer services */ + LOG_TRACE(WARNING, "ESM-PROC - PDN connection for emergency bearer " + "services is already active"); + LOG_FUNC_RETURN (RETURNerror); + } else if (pid < ESM_DATA_PDN_MAX) { + if ((pid == esm_data->pdn[pid].pid) && (esm_data->pdn[pid].is_active)) { + /* PDN connection with the specified identifier is active */ + LOG_TRACE(WARNING, "ESM-PROC - PDN connection is active"); + LOG_FUNC_RETURN (RETURNerror); } - } else { - /* The UE is requesting PDN connection to this APN using the - * same IP version than the one already activated */ - LOG_TRACE(WARNING, "ESM-PROC - %s PDN connection to %s " - "already exists", - (esm_data->pdn[pid].data->type != ESM_PDN_TYPE_IPV4)? - (esm_data->pdn[pid].data->type != ESM_PDN_TYPE_IPV6)? - "IPv4v6" : "IPv6" : "IPv4", apn->value); + } else { + LOG_TRACE(WARNING, "ESM-PROC - PDN connection identifier is not valid"); LOG_FUNC_RETURN (RETURNerror); - } } - } - - /* - * New PDN context has to be defined to allow connectivity to an APN: - * The UE may attempt to attach to the network using the default APN, - * or request PDN connectivity to emergency bearer services. The UE - * may also subsequently request connectivity to additional PDNs if - * not already established, or may have been allowed to request PDN - * connectivity for other IP version than the one already activated - */ - rc = _pdn_connectivity_create(esm_data, pid, apn, pdn_type, is_emergency); - LOG_FUNC_RETURN(rc); + + if (apn && apn->length > 0) { + /* The UE requested subsequent connectivity to additionnal PDNs */ + int pid = _pdn_connectivity_find_apn(esm_data, apn); + + if ( (pid >= 0) && esm_data->pdn[pid].is_active ) { + /* An active PDN connection to this APN already exists */ + if ( (esm_data->pdn[pid].data->type != ESM_PDN_TYPE_IPV4V6) && + (esm_data->pdn[pid].data->type != pdn_type) ) { + /* The UE is requesting PDN connection for other IP version + * than the one already activated */ + if (!esm_data->pdn[pid].data->addr_realloc) { + /* The network does not allow PDN connectivity using + * IPv4 and IPv6 address versions to the same APN */ + if (pdn_type != ESM_PDN_TYPE_IPV4V6) { + LOG_TRACE(WARNING, "ESM-PROC - %s PDN connectivity to " + "%s is not allowed by the network", + (pdn_type != ESM_PDN_TYPE_IPV4)? "IPv6" : + "IPv4", apn->value); + } else { + LOG_TRACE(WARNING, "ESM-PROC - %s PDN connection to %s " + "already exists", + (esm_data->pdn[pid].data->type != + ESM_PDN_TYPE_IPV4)? "IPv6" : "IPv4", + apn->value); + } + + LOG_FUNC_RETURN (RETURNerror); + } + } else { + /* The UE is requesting PDN connection to this APN using the + * same IP version than the one already activated */ + LOG_TRACE(WARNING, "ESM-PROC - %s PDN connection to %s " + "already exists", + (esm_data->pdn[pid].data->type != ESM_PDN_TYPE_IPV4)? + (esm_data->pdn[pid].data->type != ESM_PDN_TYPE_IPV6)? + "IPv4v6" : "IPv6" : "IPv4", apn->value); + LOG_FUNC_RETURN (RETURNerror); + } + } + } + + /* + * New PDN context has to be defined to allow connectivity to an APN: + * The UE may attempt to attach to the network using the default APN, + * or request PDN connectivity to emergency bearer services. The UE + * may also subsequently request connectivity to additional PDNs if + * not already established, or may have been allowed to request PDN + * connectivity for other IP version than the one already activated + */ + rc = _pdn_connectivity_create(esm_data, pid, apn, pdn_type, is_emergency); + LOG_FUNC_RETURN(rc); } /**************************************************************************** @@ -283,42 +283,42 @@ int esm_proc_pdn_connectivity(nas_user_t *user, int cid, int is_to_define, int esm_proc_pdn_connectivity_request(nas_user_t *user, int is_standalone, int pti, OctetString *msg, int sent_by_ue) { - LOG_FUNC_IN; - esm_pt_data_t *esm_pt_data = user->esm_pt_data; - int rc = RETURNok; - - LOG_TRACE(INFO, "ESM-PROC - Initiate PDN connectivity (pti=%d)", pti); - - if (is_standalone) { - emm_sap_t emm_sap; - emm_esm_data_t *emm_esm = &emm_sap.u.emm_esm.u.data; - /* - * Notity EMM that ESM PDU has to be forwarded to lower layers - */ - emm_sap.primitive = EMMESM_UNITDATA_REQ; - emm_sap.u.emm_esm.ueid = user->ueid; - emm_esm->msg.length = msg->length; - emm_esm->msg.value = msg->value; - rc = emm_sap_send(user, &emm_sap); - - if (rc != RETURNerror) { - /* Start T3482 retransmission timer */ - rc = esm_pt_start_timer(user, pti, msg, T3482_DEFAULT_VALUE, - _pdn_connectivity_t3482_handler); + LOG_FUNC_IN; + esm_pt_data_t *esm_pt_data = user->esm_pt_data; + int rc = RETURNok; + + LOG_TRACE(INFO, "ESM-PROC - Initiate PDN connectivity (pti=%d)", pti); + + if (is_standalone) { + emm_sap_t emm_sap; + emm_esm_data_t *emm_esm = &emm_sap.u.emm_esm.u.data; + /* + * Notity EMM that ESM PDU has to be forwarded to lower layers + */ + emm_sap.primitive = EMMESM_UNITDATA_REQ; + emm_sap.u.emm_esm.ueid = user->ueid; + emm_esm->msg.length = msg->length; + emm_esm->msg.value = msg->value; + rc = emm_sap_send(user, &emm_sap); + + if (rc != RETURNerror) { + /* Start T3482 retransmission timer */ + rc = esm_pt_start_timer(user, pti, msg, T3482_DEFAULT_VALUE, + _pdn_connectivity_t3482_handler); + } } - } - if (rc != RETURNerror) { - /* Set the procedure transaction state to PENDING */ - rc = esm_pt_set_status(esm_pt_data, pti, ESM_PT_PENDING); + if (rc != RETURNerror) { + /* Set the procedure transaction state to PENDING */ + rc = esm_pt_set_status(esm_pt_data, pti, ESM_PT_PENDING); - if (rc != RETURNok) { - /* The procedure transaction was already in PENDING state */ - LOG_TRACE(WARNING, "ESM-PROC - PTI %d was already PENDING", pti); + if (rc != RETURNok) { + /* The procedure transaction was already in PENDING state */ + LOG_TRACE(WARNING, "ESM-PROC - PTI %d was already PENDING", pti); + } } - } - LOG_FUNC_RETURN(rc); + LOG_FUNC_RETURN(rc); } /**************************************************************************** @@ -351,73 +351,73 @@ int esm_proc_pdn_connectivity_accept(nas_user_t *user, int pti, esm_proc_pdn_typ const OctetString *pdn_addr, const OctetString *apn, int *esm_cause) { - LOG_FUNC_IN; - esm_data_t *esm_data = user->esm_data; - esm_pt_data_t *esm_pt_data = user->esm_pt_data; - int rc; - int pid = RETURNerror; - char apn_first_char[4]; - - LOG_VAR(char, str[128]); - - if (isprint(apn->value[0])) { - apn_first_char[0] = '\0'; - } else { - sprintf (apn_first_char, "%02X", apn->value[0]); - } - - LOG_TRACE(INFO, "ESM-PROC - PDN connectivity accepted by the network " - "(pti=%d) APN = %s\"%s\", IP address = %s", pti, apn_first_char, isprint(apn->value[0]) ? &apn->value[0] : &apn->value[1], - (pdn_type == ESM_PDN_TYPE_IPV4)? esm_data_get_ipv4_addr(pdn_addr, str) : - (pdn_type == ESM_PDN_TYPE_IPV6)? esm_data_get_ipv6_addr(pdn_addr, str) : - esm_data_get_ipv4v6_addr(pdn_addr, str)); - - /* Stop T3482 timer if running */ - esm_pt_stop_timer(esm_pt_data, pti); - /* Set the procedure transaction state to INACTIVE */ - rc = esm_pt_set_status(esm_pt_data, pti, ESM_PT_INACTIVE); - - if (rc != RETURNok) { - /* The procedure transaction was already in INACTIVE state - * as the request may have already been accepted; consider - * this request message with same PTI as a network re- - * transmission */ - LOG_TRACE(WARNING, "ESM-PROC - PTI %d network retransmission", pti); - *esm_cause = ESM_CAUSE_PTI_ALREADY_IN_USE; - } else { - /* XXX - 3GPP TS 24.301, section 6.5.1.3 and 7.3.1 - * The UE should ensure that the procedure transaction identity - * (PTI) assigned to this procedure is not released immediately. - * While the PTI value is not released, the UE regards any received - * ACTIVATE DEFAULT EPS BEARER CONTEXT REQUEST message with the same - * PTI value as a network retransmission. - * The way to achieve this is implementation dependent. - */ + LOG_FUNC_IN; + esm_data_t *esm_data = user->esm_data; + esm_pt_data_t *esm_pt_data = user->esm_pt_data; + int rc; + int pid = RETURNerror; + char apn_first_char[4]; - /* Check whether a PDN connection exists to this APN */ - pid = _pdn_connectivity_find_pdn(esm_data, apn, pdn_type); + LOG_VAR(char, str[128]); - if (pid < 0) { - /* No any PDN connection has been defined to establish connectivity - * to this APN */ - LOG_TRACE(WARNING, "ESM-PROC - PDN connection entry for " - "APN \"%s\" (type=%d) not found", apn->value, pdn_type); - *esm_cause = ESM_CAUSE_UNKNOWN_ACCESS_POINT_NAME; - LOG_FUNC_RETURN(RETURNerror); + if (isprint(apn->value[0])) { + apn_first_char[0] = '\0'; + } else { + sprintf (apn_first_char, "%02X", apn->value[0]); } - /* Update the PDN connection */ - rc = _pdn_connectivity_update(esm_data, pid, apn, pdn_type, pdn_addr, *esm_cause); + LOG_TRACE(INFO, "ESM-PROC - PDN connectivity accepted by the network " + "(pti=%d) APN = %s\"%s\", IP address = %s", pti, apn_first_char, isprint(apn->value[0]) ? &apn->value[0] : &apn->value[1], + (pdn_type == ESM_PDN_TYPE_IPV4)? esm_data_get_ipv4_addr(pdn_addr, str) : + (pdn_type == ESM_PDN_TYPE_IPV6)? esm_data_get_ipv6_addr(pdn_addr, str) : + esm_data_get_ipv4v6_addr(pdn_addr, str)); + + /* Stop T3482 timer if running */ + esm_pt_stop_timer(esm_pt_data, pti); + /* Set the procedure transaction state to INACTIVE */ + rc = esm_pt_set_status(esm_pt_data, pti, ESM_PT_INACTIVE); if (rc != RETURNok) { - LOG_TRACE(WARNING, "ESM-PROC - Failed to update PDN connection " - "(pid=%d)", pid); - *esm_cause = ESM_CAUSE_REQUEST_REJECTED_UNSPECIFIED; - LOG_FUNC_RETURN(RETURNerror); + /* The procedure transaction was already in INACTIVE state + * as the request may have already been accepted; consider + * this request message with same PTI as a network re- + * transmission */ + LOG_TRACE(WARNING, "ESM-PROC - PTI %d network retransmission", pti); + *esm_cause = ESM_CAUSE_PTI_ALREADY_IN_USE; + } else { + /* XXX - 3GPP TS 24.301, section 6.5.1.3 and 7.3.1 + * The UE should ensure that the procedure transaction identity + * (PTI) assigned to this procedure is not released immediately. + * While the PTI value is not released, the UE regards any received + * ACTIVATE DEFAULT EPS BEARER CONTEXT REQUEST message with the same + * PTI value as a network retransmission. + * The way to achieve this is implementation dependent. + */ + + /* Check whether a PDN connection exists to this APN */ + pid = _pdn_connectivity_find_pdn(esm_data, apn, pdn_type); + + if (pid < 0) { + /* No any PDN connection has been defined to establish connectivity + * to this APN */ + LOG_TRACE(WARNING, "ESM-PROC - PDN connection entry for " + "APN \"%s\" (type=%d) not found", apn->value, pdn_type); + *esm_cause = ESM_CAUSE_UNKNOWN_ACCESS_POINT_NAME; + LOG_FUNC_RETURN(RETURNerror); + } + + /* Update the PDN connection */ + rc = _pdn_connectivity_update(esm_data, pid, apn, pdn_type, pdn_addr, *esm_cause); + + if (rc != RETURNok) { + LOG_TRACE(WARNING, "ESM-PROC - Failed to update PDN connection " + "(pid=%d)", pid); + *esm_cause = ESM_CAUSE_REQUEST_REJECTED_UNSPECIFIED; + LOG_FUNC_RETURN(RETURNerror); + } } - } - LOG_FUNC_RETURN (pid); + LOG_FUNC_RETURN (pid); } /**************************************************************************** @@ -444,33 +444,33 @@ int esm_proc_pdn_connectivity_accept(nas_user_t *user, int pti, esm_proc_pdn_typ ***************************************************************************/ int esm_proc_pdn_connectivity_reject(nas_user_t *user, int pti, int *esm_cause) { - LOG_FUNC_IN; - esm_pt_data_t *esm_pt_data = user->esm_pt_data; - int rc; - - LOG_TRACE(WARNING, "ESM-PROC - PDN connectivity rejected by " - "the network (pti=%d), ESM cause = %d", pti, *esm_cause); - - /* Stop T3482 timer if running */ - (void) esm_pt_stop_timer(esm_pt_data, pti); - /* Set the procedure transaction state to INACTIVE */ - rc = esm_pt_set_status(esm_pt_data, pti, ESM_PT_INACTIVE); - - if (rc != RETURNok) { - /* The procedure transaction was already in INACTIVE state */ - LOG_TRACE(WARNING, "ESM-PROC - PTI %d was already INACTIVE", pti); - *esm_cause = ESM_CAUSE_MESSAGE_TYPE_NOT_COMPATIBLE; - } else { - /* Release the procedure transaction identity */ - rc = esm_pt_release(user->esm_pt_data, pti); + LOG_FUNC_IN; + esm_pt_data_t *esm_pt_data = user->esm_pt_data; + int rc; + + LOG_TRACE(WARNING, "ESM-PROC - PDN connectivity rejected by " + "the network (pti=%d), ESM cause = %d", pti, *esm_cause); + + /* Stop T3482 timer if running */ + (void) esm_pt_stop_timer(esm_pt_data, pti); + /* Set the procedure transaction state to INACTIVE */ + rc = esm_pt_set_status(esm_pt_data, pti, ESM_PT_INACTIVE); if (rc != RETURNok) { - LOG_TRACE(WARNING, "ESM-PROC - Failed to release PTI %d", pti); - *esm_cause = ESM_CAUSE_REQUEST_REJECTED_UNSPECIFIED; + /* The procedure transaction was already in INACTIVE state */ + LOG_TRACE(WARNING, "ESM-PROC - PTI %d was already INACTIVE", pti); + *esm_cause = ESM_CAUSE_MESSAGE_TYPE_NOT_COMPATIBLE; + } else { + /* Release the procedure transaction identity */ + rc = esm_pt_release(user->esm_pt_data, pti); + + if (rc != RETURNok) { + LOG_TRACE(WARNING, "ESM-PROC - Failed to release PTI %d", pti); + *esm_cause = ESM_CAUSE_REQUEST_REJECTED_UNSPECIFIED; + } } - } - LOG_FUNC_RETURN(rc); + LOG_FUNC_RETURN(rc); } /**************************************************************************** @@ -495,22 +495,22 @@ int esm_proc_pdn_connectivity_reject(nas_user_t *user, int pti, int *esm_cause) ***************************************************************************/ int esm_proc_pdn_connectivity_complete(nas_user_t *user) { - LOG_FUNC_IN; - esm_pt_data_t *esm_pt_data = user->esm_pt_data; - int rc = RETURNerror; + LOG_FUNC_IN; + esm_pt_data_t *esm_pt_data = user->esm_pt_data; + int rc = RETURNerror; - LOG_TRACE(INFO, "ESM-PROC - PDN connectivity complete"); + LOG_TRACE(INFO, "ESM-PROC - PDN connectivity complete"); - /* Get the procedure transaction identity assigned to the PDN connection - * entry which is still pending in the inactive state */ - int pti = esm_pt_get_pending_pti(esm_pt_data, ESM_PT_INACTIVE); + /* Get the procedure transaction identity assigned to the PDN connection + * entry which is still pending in the inactive state */ + int pti = esm_pt_get_pending_pti(esm_pt_data, ESM_PT_INACTIVE); - if (pti != ESM_PT_UNASSIGNED) { - /* Release the procedure transaction identity */ - rc = esm_pt_release(esm_pt_data, pti); - } + if (pti != ESM_PT_UNASSIGNED) { + /* Release the procedure transaction identity */ + rc = esm_pt_release(esm_pt_data, pti); + } - LOG_FUNC_RETURN(rc); + LOG_FUNC_RETURN(rc); } /**************************************************************************** @@ -536,40 +536,40 @@ int esm_proc_pdn_connectivity_complete(nas_user_t *user) ***************************************************************************/ int esm_proc_pdn_connectivity_failure(nas_user_t *user, int is_pending) { - LOG_FUNC_IN; - esm_pt_data_t *esm_pt_data = user->esm_pt_data; - int rc; - int pti; - - LOG_TRACE(WARNING, "ESM-PROC - PDN connectivity failure in state %s", - (is_pending)? "PENDING" : "INACTIVE"); - - if (is_pending) { - /* Get the procedure transaction identity assigned to the pending PDN - * connection entry */ - pti = esm_pt_get_pending_pti(esm_pt_data, ESM_PT_PENDING); - - if (pti == ESM_PT_UNASSIGNED) { - LOG_TRACE(ERROR, "ESM-PROC - No procedure transaction is PENDING"); - return (RETURNerror); - } + LOG_FUNC_IN; + esm_pt_data_t *esm_pt_data = user->esm_pt_data; + int rc; + int pti; + + LOG_TRACE(WARNING, "ESM-PROC - PDN connectivity failure in state %s", + (is_pending)? "PENDING" : "INACTIVE"); + + if (is_pending) { + /* Get the procedure transaction identity assigned to the pending PDN + * connection entry */ + pti = esm_pt_get_pending_pti(esm_pt_data, ESM_PT_PENDING); + + if (pti == ESM_PT_UNASSIGNED) { + LOG_TRACE(ERROR, "ESM-PROC - No procedure transaction is PENDING"); + return (RETURNerror); + } - /* Set the procedure transaction state to INACTIVE */ - (void) esm_pt_set_status(esm_pt_data, pti, ESM_PT_INACTIVE); - } else { - /* Get the procedure transaction identity assigned to the PDN - * connection entry which is still pending in the inactive state */ - pti = esm_pt_get_pending_pti(esm_pt_data, ESM_PT_INACTIVE); - } + /* Set the procedure transaction state to INACTIVE */ + (void) esm_pt_set_status(esm_pt_data, pti, ESM_PT_INACTIVE); + } else { + /* Get the procedure transaction identity assigned to the PDN + * connection entry which is still pending in the inactive state */ + pti = esm_pt_get_pending_pti(esm_pt_data, ESM_PT_INACTIVE); + } - /* Release the procedure transaction identity */ - rc = esm_pt_release(esm_pt_data, pti); + /* Release the procedure transaction identity */ + rc = esm_pt_release(esm_pt_data, pti); - if (rc != RETURNok) { - LOG_TRACE(WARNING, "ESM-PROC - Failed to release PTI %d", pti); - } + if (rc != RETURNok) { + LOG_TRACE(WARNING, "ESM-PROC - Failed to release PTI %d", pti); + } - LOG_FUNC_RETURN(rc); + LOG_FUNC_RETURN(rc); } @@ -607,62 +607,62 @@ int esm_proc_pdn_connectivity_failure(nas_user_t *user, int is_pending) ** Others: None ** ** ** ***************************************************************************/ -// FIXME +// FIXME static void *_pdn_connectivity_t3482_handler(void *args) { - LOG_FUNC_IN; - - int rc; - - /* Get retransmission timer parameters data */ - esm_pt_timer_data_t *data = args; - nas_user_t *user = data->user; - esm_pt_data_t *esm_pt_data = user->esm_pt_data; - - /* Increment the retransmission counter */ - data->count += 1; - - LOG_TRACE(WARNING, "ESM-PROC - T3482 timer expired (pti=%d), " - "retransmission counter = %d", data->pti, data->count); - - if (data->count < ESM_PDN_CONNECTIVITY_COUNTER_MAX) { - emm_sap_t emm_sap; - emm_esm_data_t *emm_esm = &emm_sap.u.emm_esm.u.data; - /* - * Notify EMM that the PDN connectivity request message - * has to be sent again - */ - emm_sap.primitive = EMMESM_UNITDATA_REQ; - emm_sap.u.emm_esm.ueid = user->ueid; - emm_esm->msg.length = data->msg.length; - emm_esm->msg.value = data->msg.value; - rc = emm_sap_send(user, &emm_sap); - - if (rc != RETURNerror) { - /* Restart the timer T3482 */ - rc = esm_pt_start_timer(user, data->pti, &data->msg, T3482_DEFAULT_VALUE, - _pdn_connectivity_t3482_handler); - } - } else { - /* Set the procedure transaction state to INACTIVE */ - rc = esm_pt_set_status(esm_pt_data, data->pti, ESM_PT_INACTIVE); - - if (rc != RETURNok) { - /* The procedure transaction was already in INACTIVE state */ - LOG_TRACE(WARNING, "ESM-PROC - PTI %d was already INACTIVE", - data->pti); + LOG_FUNC_IN; + + int rc; + + /* Get retransmission timer parameters data */ + esm_pt_timer_data_t *data = args; + nas_user_t *user = data->user; + esm_pt_data_t *esm_pt_data = user->esm_pt_data; + + /* Increment the retransmission counter */ + data->count += 1; + + LOG_TRACE(WARNING, "ESM-PROC - T3482 timer expired (pti=%d), " + "retransmission counter = %d", data->pti, data->count); + + if (data->count < ESM_PDN_CONNECTIVITY_COUNTER_MAX) { + emm_sap_t emm_sap; + emm_esm_data_t *emm_esm = &emm_sap.u.emm_esm.u.data; + /* + * Notify EMM that the PDN connectivity request message + * has to be sent again + */ + emm_sap.primitive = EMMESM_UNITDATA_REQ; + emm_sap.u.emm_esm.ueid = user->ueid; + emm_esm->msg.length = data->msg.length; + emm_esm->msg.value = data->msg.value; + rc = emm_sap_send(user, &emm_sap); + + if (rc != RETURNerror) { + /* Restart the timer T3482 */ + rc = esm_pt_start_timer(user, data->pti, &data->msg, T3482_DEFAULT_VALUE, + _pdn_connectivity_t3482_handler); + } } else { - /* Release the transaction identity assigned to this procedure */ - rc = esm_pt_release(esm_pt_data, data->pti); - - if (rc != RETURNok) { - LOG_TRACE(WARNING, "ESM-PROC - Failed to release PTI %d", - data->pti); - } + /* Set the procedure transaction state to INACTIVE */ + rc = esm_pt_set_status(esm_pt_data, data->pti, ESM_PT_INACTIVE); + + if (rc != RETURNok) { + /* The procedure transaction was already in INACTIVE state */ + LOG_TRACE(WARNING, "ESM-PROC - PTI %d was already INACTIVE", + data->pti); + } else { + /* Release the transaction identity assigned to this procedure */ + rc = esm_pt_release(esm_pt_data, data->pti); + + if (rc != RETURNok) { + LOG_TRACE(WARNING, "ESM-PROC - Failed to release PTI %d", + data->pti); + } + } } - } - LOG_FUNC_RETURN(NULL); + LOG_FUNC_RETURN(NULL); } /* @@ -692,63 +692,63 @@ static int _pdn_connectivity_create(esm_data_t *esm_data, int pid, const OctetSt esm_proc_pdn_type_t pdn_type, int is_emergency) { - esm_pdn_t *pdn = NULL; + esm_pdn_t *pdn = NULL; - LOG_TRACE(INFO, "ESM-PROC - Create new PDN connection (pid=%d)", pid); + LOG_TRACE(INFO, "ESM-PROC - Create new PDN connection (pid=%d)", pid); - if (pid >= ESM_DATA_PDN_MAX) { - return (RETURNerror); - } else if (esm_data->pdn[pid].is_active) { - LOG_TRACE(ERROR, "ESM-PROC - PDN connection is active"); - return (RETURNerror); - } - - if (esm_data->pdn[pid].data != NULL) { - /* Update existing non-active PDN connection */ - pdn = esm_data->pdn[pid].data; - } else { - /* Create new PDN connection */ - pdn = (esm_pdn_t *)malloc(sizeof(esm_pdn_t)); - - if (pdn == NULL) { - LOG_TRACE(WARNING, "ESM-PROC - " - "Failed to create new PDN connection"); - return (RETURNerror); + if (pid >= ESM_DATA_PDN_MAX) { + return (RETURNerror); + } else if (esm_data->pdn[pid].is_active) { + LOG_TRACE(ERROR, "ESM-PROC - PDN connection is active"); + return (RETURNerror); } - memset(pdn, 0, sizeof(esm_pdn_t)); - /* Increment the number of PDN connections */ - esm_data->n_pdns += 1; - /* Set the PDN connection identifier */ - esm_data->pdn[pid].pid = pid; - /* Reset the PDN connection active indicator */ - esm_data->pdn[pid].is_active = FALSE; - /* Setup the PDN connection data */ - esm_data->pdn[pid].data = pdn; - } - - /* Update the PDN connection data */ - pdn->is_emergency = is_emergency; - - if ( apn && (apn->length > 0) ) { - if (pdn->apn.length > 0) { - free(pdn->apn.value); - pdn->apn.length = 0; + if (esm_data->pdn[pid].data != NULL) { + /* Update existing non-active PDN connection */ + pdn = esm_data->pdn[pid].data; + } else { + /* Create new PDN connection */ + pdn = (esm_pdn_t *)malloc(sizeof(esm_pdn_t)); + + if (pdn == NULL) { + LOG_TRACE(WARNING, "ESM-PROC - " + "Failed to create new PDN connection"); + return (RETURNerror); + } + + memset(pdn, 0, sizeof(esm_pdn_t)); + /* Increment the number of PDN connections */ + esm_data->n_pdns += 1; + /* Set the PDN connection identifier */ + esm_data->pdn[pid].pid = pid; + /* Reset the PDN connection active indicator */ + esm_data->pdn[pid].is_active = FALSE; + /* Setup the PDN connection data */ + esm_data->pdn[pid].data = pdn; } - pdn->apn.value = (uint8_t *)malloc(apn->length + 1); + /* Update the PDN connection data */ + pdn->is_emergency = is_emergency; + + if ( apn && (apn->length > 0) ) { + if (pdn->apn.length > 0) { + free(pdn->apn.value); + pdn->apn.length = 0; + } + + pdn->apn.value = (uint8_t *)malloc(apn->length + 1); - if (pdn->apn.value) { - pdn->apn.length = apn->length; - memcpy(pdn->apn.value, apn->value, apn->length); - pdn->apn.value[pdn->apn.length] = '\0'; + if (pdn->apn.value) { + pdn->apn.length = apn->length; + memcpy(pdn->apn.value, apn->value, apn->length); + pdn->apn.value[pdn->apn.length] = '\0'; + } } - } - pdn->type = pdn_type; - pdn->addr_realloc = FALSE; + pdn->type = pdn_type; + pdn->addr_realloc = FALSE; - return (RETURNok); + return (RETURNok); } /**************************************************************************** @@ -772,75 +772,75 @@ static int _pdn_connectivity_update(esm_data_t *esm_data, int pid, const OctetSt const OctetString *pdn_addr, int esm_cause) { - LOG_TRACE(INFO, "ESM-PROC - Update PDN connection (pid=%d)", pid); + LOG_TRACE(INFO, "ESM-PROC - Update PDN connection (pid=%d)", pid); - if (pid >= ESM_DATA_PDN_MAX) { - return (RETURNerror); - } else if (pid != esm_data->pdn[pid].pid) { - LOG_TRACE(ERROR, "ESM-PROC - PDN connection identifier is not valid"); - return (RETURNerror); - } else if (esm_data->pdn[pid].data == NULL) { - LOG_TRACE(ERROR, "ESM-PROC - PDN connection has not been allocated"); - return (RETURNerror); - } else if (esm_data->pdn[pid].is_active) { - LOG_TRACE(WARNING, "ESM-PROC - Active %s PDN connection to %s already " - "exists", (esm_data->pdn[pid].data->type != ESM_PDN_TYPE_IPV4)? - "IPv6" : "IPv4", esm_data->pdn[pid].data->apn.value); - return (RETURNerror); - } + if (pid >= ESM_DATA_PDN_MAX) { + return (RETURNerror); + } else if (pid != esm_data->pdn[pid].pid) { + LOG_TRACE(ERROR, "ESM-PROC - PDN connection identifier is not valid"); + return (RETURNerror); + } else if (esm_data->pdn[pid].data == NULL) { + LOG_TRACE(ERROR, "ESM-PROC - PDN connection has not been allocated"); + return (RETURNerror); + } else if (esm_data->pdn[pid].is_active) { + LOG_TRACE(WARNING, "ESM-PROC - Active %s PDN connection to %s already " + "exists", (esm_data->pdn[pid].data->type != ESM_PDN_TYPE_IPV4)? + "IPv6" : "IPv4", esm_data->pdn[pid].data->apn.value); + return (RETURNerror); + } - /* Get the PDN connection */ - esm_pdn_t *pdn = esm_data->pdn[pid].data; + /* Get the PDN connection */ + esm_pdn_t *pdn = esm_data->pdn[pid].data; - /* Setup the Access Point Name value */ - if ( apn && (apn->length > 0) ) { - if (pdn->apn.length > 0) { - free(pdn->apn.value); - pdn->apn.length = 0; - } + /* Setup the Access Point Name value */ + if ( apn && (apn->length > 0) ) { + if (pdn->apn.length > 0) { + free(pdn->apn.value); + pdn->apn.length = 0; + } - pdn->apn.value = (uint8_t *)malloc(apn->length + 1); + pdn->apn.value = (uint8_t *)malloc(apn->length + 1); - if (pdn->apn.value) { - pdn->apn.length = apn->length; - memcpy(pdn->apn.value, apn->value, apn->length); - pdn->apn.value[pdn->apn.length] = '\0'; + if (pdn->apn.value) { + pdn->apn.length = apn->length; + memcpy(pdn->apn.value, apn->value, apn->length); + pdn->apn.value[pdn->apn.length] = '\0'; + } } - } - /* Setup the IP address allocated by the network */ - if ( pdn_addr && (pdn_addr->length > 0) ) { - int length = ((pdn_addr->length < ESM_DATA_IP_ADDRESS_SIZE) ? - pdn_addr->length : ESM_DATA_IP_ADDRESS_SIZE); - memcpy(pdn->ip_addr, pdn_addr->value, length); - pdn->type = pdn_type; - } - - /* - * 3GPP TS 24.301, section 6.2.2 - * Update the address re-allocation indicator - */ - if (esm_cause == ESM_CAUSE_SINGLE_ADDRESS_BEARERS_ONLY_ALLOWED) { - /* The UE requested IPv4 or IPv6 address and the network allows - * single addressing per bearer: - * The UE should subsequently request another PDN connection for - * the other IP version using the UE requested PDN connectivity - * procedure to the same APN with a single address PDN type - * (IPv4 or IPv6) other than the one already activated */ - pdn->addr_realloc = TRUE; - } else if ( (esm_cause == ESM_CAUSE_PDN_TYPE_IPV4_ONLY_ALLOWED) || - (esm_cause == ESM_CAUSE_PDN_TYPE_IPV6_ONLY_ALLOWED) ) { - /* The UE requested IPv4 or IPv6 address and the network allows - * IPv4 or IPv6 PDN address only: - * The UE shall not subsequently initiate another UE requested - * PDN connectivity procedure to the same APN to obtain a PDN - * type different from the one allowed by the network */ - pdn->addr_realloc = FALSE; - } else if (pdn_type != ESM_PDN_TYPE_IPV4V6) { - pdn->addr_realloc = TRUE; - } + /* Setup the IP address allocated by the network */ + if ( pdn_addr && (pdn_addr->length > 0) ) { + int length = ((pdn_addr->length < ESM_DATA_IP_ADDRESS_SIZE) ? + pdn_addr->length : ESM_DATA_IP_ADDRESS_SIZE); + memcpy(pdn->ip_addr, pdn_addr->value, length); + pdn->type = pdn_type; + } + + /* + * 3GPP TS 24.301, section 6.2.2 + * Update the address re-allocation indicator + */ + if (esm_cause == ESM_CAUSE_SINGLE_ADDRESS_BEARERS_ONLY_ALLOWED) { + /* The UE requested IPv4 or IPv6 address and the network allows + * single addressing per bearer: + * The UE should subsequently request another PDN connection for + * the other IP version using the UE requested PDN connectivity + * procedure to the same APN with a single address PDN type + * (IPv4 or IPv6) other than the one already activated */ + pdn->addr_realloc = TRUE; + } else if ( (esm_cause == ESM_CAUSE_PDN_TYPE_IPV4_ONLY_ALLOWED) || + (esm_cause == ESM_CAUSE_PDN_TYPE_IPV6_ONLY_ALLOWED) ) { + /* The UE requested IPv4 or IPv6 address and the network allows + * IPv4 or IPv6 PDN address only: + * The UE shall not subsequently initiate another UE requested + * PDN connectivity procedure to the same APN to obtain a PDN + * type different from the one allowed by the network */ + pdn->addr_realloc = FALSE; + } else if (pdn_type != ESM_PDN_TYPE_IPV4V6) { + pdn->addr_realloc = TRUE; + } - return (RETURNok); + return (RETURNok); } /**************************************************************************** @@ -861,42 +861,42 @@ static int _pdn_connectivity_update(esm_data_t *esm_data, int pid, const OctetSt ***************************************************************************/ static int _pdn_connectivity_delete(esm_data_t *esm_data, int pid) { - int pti = ESM_PT_UNASSIGNED; - - if (pid < ESM_DATA_PDN_MAX) { - if (pid != esm_data->pdn[pid].pid) { - LOG_TRACE(ERROR, - "ESM-PROC - PDN connection identifier is not valid"); - } else if (esm_data->pdn[pid].data == NULL) { - LOG_TRACE(ERROR, - "ESM-PROC - PDN connection has not been allocated"); - } else if (esm_data->pdn[pid].is_active) { - LOG_TRACE(ERROR, "ESM-PROC - PDN connection is active"); - } else { - /* Get the identity of the procedure transaction that created - * the PDN connection */ - pti = esm_data->pdn[pid].data->pti; + int pti = ESM_PT_UNASSIGNED; + + if (pid < ESM_DATA_PDN_MAX) { + if (pid != esm_data->pdn[pid].pid) { + LOG_TRACE(ERROR, + "ESM-PROC - PDN connection identifier is not valid"); + } else if (esm_data->pdn[pid].data == NULL) { + LOG_TRACE(ERROR, + "ESM-PROC - PDN connection has not been allocated"); + } else if (esm_data->pdn[pid].is_active) { + LOG_TRACE(ERROR, "ESM-PROC - PDN connection is active"); + } else { + /* Get the identity of the procedure transaction that created + * the PDN connection */ + pti = esm_data->pdn[pid].data->pti; + } } - } - if (pti != ESM_PT_UNASSIGNED) { - /* Decrement the number of PDN connections */ - esm_data->n_pdns -= 1; - /* Set the PDN connection as available */ - esm_data->pdn[pid].pid = -1; + if (pti != ESM_PT_UNASSIGNED) { + /* Decrement the number of PDN connections */ + esm_data->n_pdns -= 1; + /* Set the PDN connection as available */ + esm_data->pdn[pid].pid = -1; + + /* Release allocated PDN connection data */ + if (esm_data->pdn[pid].data->apn.length > 0) { + free(esm_data->pdn[pid].data->apn.value); + } - /* Release allocated PDN connection data */ - if (esm_data->pdn[pid].data->apn.length > 0) { - free(esm_data->pdn[pid].data->apn.value); + free(esm_data->pdn[pid].data); + esm_data->pdn[pid].data = NULL; + LOG_TRACE(WARNING, "ESM-PROC - PDN connection %d released", pid); } - free(esm_data->pdn[pid].data); - esm_data->pdn[pid].data = NULL; - LOG_TRACE(WARNING, "ESM-PROC - PDN connection %d released", pid); - } - - /* Return the procedure transaction identity */ - return (pti); + /* Return the procedure transaction identity */ + return (pti); } /**************************************************************************** @@ -916,24 +916,24 @@ static int _pdn_connectivity_delete(esm_data_t *esm_data, int pid) ***************************************************************************/ static int _pdn_connectivity_set_pti(esm_data_t *esm_data, int pid, int pti) { - if (pid < ESM_DATA_PDN_MAX) { - if (pid != esm_data->pdn[pid].pid) { - LOG_TRACE(ERROR, - "ESM-PROC - PDN connection identifier is not valid"); - } else if (esm_data->pdn[pid].data == NULL) { - LOG_TRACE(ERROR, - "ESM-PROC - PDN connection has not been allocated"); - } else if (esm_data->pdn[pid].is_active) { - LOG_TRACE(ERROR, "ESM-PROC - PDN connection is active"); - } else { - /* Update the identity of the procedure transaction assigned to - * the PDN connection */ - esm_data->pdn[pid].data->pti = pti; - return (RETURNok); + if (pid < ESM_DATA_PDN_MAX) { + if (pid != esm_data->pdn[pid].pid) { + LOG_TRACE(ERROR, + "ESM-PROC - PDN connection identifier is not valid"); + } else if (esm_data->pdn[pid].data == NULL) { + LOG_TRACE(ERROR, + "ESM-PROC - PDN connection has not been allocated"); + } else if (esm_data->pdn[pid].is_active) { + LOG_TRACE(ERROR, "ESM-PROC - PDN connection is active"); + } else { + /* Update the identity of the procedure transaction assigned to + * the PDN connection */ + esm_data->pdn[pid].data->pti = pti; + return (RETURNok); + } } - } - return (RETURNerror); + return (RETURNerror); } /**************************************************************************** @@ -953,26 +953,26 @@ static int _pdn_connectivity_set_pti(esm_data_t *esm_data, int pid, int pti) ***************************************************************************/ static int _pdn_connectivity_find_apn(esm_data_t *esm_data, const OctetString *apn) { - int i; + int i; - for (i = 0; i < ESM_DATA_PDN_MAX; i++) { - if ( (esm_data->pdn[i].pid != -1) && esm_data->pdn[i].data ) { - if (esm_data->pdn[i].data->apn.length != apn->length) { - continue; - } + for (i = 0; i < ESM_DATA_PDN_MAX; i++) { + if ( (esm_data->pdn[i].pid != -1) && esm_data->pdn[i].data ) { + if (esm_data->pdn[i].data->apn.length != apn->length) { + continue; + } - if (memcmp(esm_data->pdn[i].data->apn.value, - apn->value, apn->length) != 0) { - continue; - } + if (memcmp(esm_data->pdn[i].data->apn.value, + apn->value, apn->length) != 0) { + continue; + } - /* PDN entry found */ - break; + /* PDN entry found */ + break; + } } - } - /* Return the identifier of the PDN connection */ - return (esm_data->pdn[i].pid); + /* Return the identifier of the PDN connection */ + return (esm_data->pdn[i].pid); } /**************************************************************************** @@ -994,35 +994,35 @@ static int _pdn_connectivity_find_apn(esm_data_t *esm_data, const OctetString *a static int _pdn_connectivity_find_pdn(esm_data_t *esm_data, const OctetString *apn, const esm_proc_pdn_type_t pdn_type) { - int i; - - for (i = 0; i < ESM_DATA_PDN_MAX; i++) { - if ( (esm_data->pdn[i].pid != -1) && esm_data->pdn[i].data ) { - /* PDN connection established during initial network attachment */ - if (esm_data->pdn[i].data->apn.length == 0) { - break; - } - - /* Subsequent PDN connection established for the specified APN */ - if (esm_data->pdn[i].data->apn.length != apn->length) { - continue; - } - - if (memcmp(esm_data->pdn[i].data->apn.value, - apn->value, apn->length) != 0) { - continue; - } - - if (esm_data->pdn[i].data->type == ESM_PDN_TYPE_IPV4V6) { - break; - } - - if (esm_data->pdn[i].data->type == pdn_type) { - break; - } + int i; + + for (i = 0; i < ESM_DATA_PDN_MAX; i++) { + if ( (esm_data->pdn[i].pid != -1) && esm_data->pdn[i].data ) { + /* PDN connection established during initial network attachment */ + if (esm_data->pdn[i].data->apn.length == 0) { + break; + } + + /* Subsequent PDN connection established for the specified APN */ + if (esm_data->pdn[i].data->apn.length != apn->length) { + continue; + } + + if (memcmp(esm_data->pdn[i].data->apn.value, + apn->value, apn->length) != 0) { + continue; + } + + if (esm_data->pdn[i].data->type == ESM_PDN_TYPE_IPV4V6) { + break; + } + + if (esm_data->pdn[i].data->type == pdn_type) { + break; + } + } } - } - /* Return the identifier of the PDN connection */ - return (esm_data->pdn[i].pid); + /* Return the identifier of the PDN connection */ + return (esm_data->pdn[i].pid); } diff --git a/openair3/S1AP/s1ap_common.h b/openair3/S1AP/s1ap_common.h index 94b3e43bc65b8789e330f25179381e0d2de4ba47..fc872564c57d51a34936523c86833b107ef20996 100644 --- a/openair3/S1AP/s1ap_common.h +++ b/openair3/S1AP/s1ap_common.h @@ -90,6 +90,7 @@ extern int asn1_xer_print; # define S1AP_DEBUG(x, args...) do { fprintf(stdout, "[S1AP][D]"x, ##args); } while(0) #endif + #define S1AP_FIND_PROTOCOLIE_BY_ID(IE_TYPE, ie, container, IE_ID, mandatory) \ do {\ IE_TYPE **ptr; \ @@ -102,15 +103,17 @@ extern int asn1_xer_print; break; \ } \ } \ - if (mandatory) DevAssert(ie != NULL); \ + if (ie == NULL ) { \ + S1AP_ERROR("S1AP_FIND_PROTOCOLIE_BY_ID: %s %d: ie is NULL\n",__FILE__,__LINE__);\ + if (mandatory) _Assert_Exit_ \ + } \ } while(0) - /** \brief Function callback prototype. **/ typedef int (*s1ap_message_decoded_callback)( - uint32_t assoc_id, - uint32_t stream, - S1AP_S1AP_PDU_t *pdu + uint32_t assoc_id, + uint32_t stream, + S1AP_S1AP_PDU_t *pdu ); /** \brief Handle criticality diff --git a/openair3/S1AP/s1ap_eNB_handlers.c b/openair3/S1AP/s1ap_eNB_handlers.c index 0f7afb68f76d03d2ae832a2ce49f848db6c64504..a047233ef2f8a931528fc9dd6d079b7bec29c0a9 100644 --- a/openair3/S1AP/s1ap_eNB_handlers.c +++ b/openair3/S1AP/s1ap_eNB_handlers.c @@ -66,13 +66,13 @@ int s1ap_eNB_handle_error_indication(uint32_t assoc_id, static int s1ap_eNB_handle_initial_context_request(uint32_t assoc_id, - uint32_t stream, - S1AP_S1AP_PDU_t *pdu); + uint32_t stream, + S1AP_S1AP_PDU_t *pdu); static int s1ap_eNB_handle_ue_context_release_command(uint32_t assoc_id, - uint32_t stream, - S1AP_S1AP_PDU_t *pdu); + uint32_t stream, + S1AP_S1AP_PDU_t *pdu); static int s1ap_eNB_handle_e_rab_setup_request(uint32_t assoc_id, @@ -86,295 +86,304 @@ int s1ap_eNB_handle_paging(uint32_t assoc_id, static int s1ap_eNB_handle_e_rab_modify_request(uint32_t assoc_id, - uint32_t stream, - S1AP_S1AP_PDU_t *pdu); + uint32_t stream, + S1AP_S1AP_PDU_t *pdu); static int s1ap_eNB_handle_e_rab_release_command(uint32_t assoc_id, - uint32_t stream, - S1AP_S1AP_PDU_t *pdu); + uint32_t stream, + S1AP_S1AP_PDU_t *pdu); /* Handlers matrix. Only eNB related procedure present here */ s1ap_message_decoded_callback messages_callback[][3] = { - { 0, 0, 0 }, /* HandoverPreparation */ - { 0, 0, 0 }, /* HandoverResourceAllocation */ - { 0, 0, 0 }, /* HandoverNotification */ - { 0, 0, 0 }, /* PathSwitchRequest */ - { 0, 0, 0 }, /* HandoverCancel */ - { s1ap_eNB_handle_e_rab_setup_request, 0, 0 }, /* E_RABSetup */ - { s1ap_eNB_handle_e_rab_modify_request, 0, 0 }, /* E_RABModify */ - { s1ap_eNB_handle_e_rab_release_command, 0, 0 }, /* E_RABRelease */ - { 0, 0, 0 }, /* E_RABReleaseIndication */ - { s1ap_eNB_handle_initial_context_request, 0, 0 }, /* InitialContextSetup */ - { s1ap_eNB_handle_paging, 0, 0 }, /* Paging */ - { s1ap_eNB_handle_nas_downlink, 0, 0 }, /* downlinkNASTransport */ - { 0, 0, 0 }, /* initialUEMessage */ - { 0, 0, 0 }, /* uplinkNASTransport */ - { 0, 0, 0 }, /* Reset */ - { s1ap_eNB_handle_error_indication, 0, 0 }, /* ErrorIndication */ - { 0, 0, 0 }, /* NASNonDeliveryIndication */ - { 0, s1ap_eNB_handle_s1_setup_response, s1ap_eNB_handle_s1_setup_failure }, /* S1Setup */ - { 0, 0, 0 }, /* UEContextReleaseRequest */ - { 0, 0, 0 }, /* DownlinkS1cdma2000tunneling */ - { 0, 0, 0 }, /* UplinkS1cdma2000tunneling */ - { 0, 0, 0 }, /* UEContextModification */ - { 0, 0, 0 }, /* UECapabilityInfoIndication */ - { s1ap_eNB_handle_ue_context_release_command, 0, 0 }, /* UEContextRelease */ - { 0, 0, 0 }, /* eNBStatusTransfer */ - { 0, 0, 0 }, /* MMEStatusTransfer */ - { s1ap_eNB_handle_deactivate_trace, 0, 0 }, /* DeactivateTrace */ - { s1ap_eNB_handle_trace_start, 0, 0 }, /* TraceStart */ - { 0, 0, 0 }, /* TraceFailureIndication */ - { 0, 0, 0 }, /* ENBConfigurationUpdate */ - { 0, 0, 0 }, /* MMEConfigurationUpdate */ - { 0, 0, 0 }, /* LocationReportingControl */ - { 0, 0, 0 }, /* LocationReportingFailureIndication */ - { 0, 0, 0 }, /* LocationReport */ - { 0, 0, 0 }, /* OverloadStart */ - { 0, 0, 0 }, /* OverloadStop */ - { 0, 0, 0 }, /* WriteReplaceWarning */ - { 0, 0, 0 }, /* eNBDirectInformationTransfer */ - { 0, 0, 0 }, /* MMEDirectInformationTransfer */ - { 0, 0, 0 }, /* PrivateMessage */ - { 0, 0, 0 }, /* eNBConfigurationTransfer */ - { 0, 0, 0 }, /* MMEConfigurationTransfer */ - { 0, 0, 0 }, /* CellTrafficTrace */ + { 0, 0, 0 }, /* HandoverPreparation */ + { 0, 0, 0 }, /* HandoverResourceAllocation */ + { 0, 0, 0 }, /* HandoverNotification */ + { 0, 0, 0 }, /* PathSwitchRequest */ + { 0, 0, 0 }, /* HandoverCancel */ + { s1ap_eNB_handle_e_rab_setup_request, 0, 0 }, /* E_RABSetup */ + { s1ap_eNB_handle_e_rab_modify_request, 0, 0 }, /* E_RABModify */ + { s1ap_eNB_handle_e_rab_release_command, 0, 0 }, /* E_RABRelease */ + { 0, 0, 0 }, /* E_RABReleaseIndication */ + { s1ap_eNB_handle_initial_context_request, 0, 0 }, /* InitialContextSetup */ + { s1ap_eNB_handle_paging, 0, 0 }, /* Paging */ + { s1ap_eNB_handle_nas_downlink, 0, 0 }, /* downlinkNASTransport */ + { 0, 0, 0 }, /* initialUEMessage */ + { 0, 0, 0 }, /* uplinkNASTransport */ + { 0, 0, 0 }, /* Reset */ + { s1ap_eNB_handle_error_indication, 0, 0 }, /* ErrorIndication */ + { 0, 0, 0 }, /* NASNonDeliveryIndication */ + { 0, s1ap_eNB_handle_s1_setup_response, s1ap_eNB_handle_s1_setup_failure }, /* S1Setup */ + { 0, 0, 0 }, /* UEContextReleaseRequest */ + { 0, 0, 0 }, /* DownlinkS1cdma2000tunneling */ + { 0, 0, 0 }, /* UplinkS1cdma2000tunneling */ + { 0, 0, 0 }, /* UEContextModification */ + { 0, 0, 0 }, /* UECapabilityInfoIndication */ + { s1ap_eNB_handle_ue_context_release_command, 0, 0 }, /* UEContextRelease */ + { 0, 0, 0 }, /* eNBStatusTransfer */ + { 0, 0, 0 }, /* MMEStatusTransfer */ + { s1ap_eNB_handle_deactivate_trace, 0, 0 }, /* DeactivateTrace */ + { s1ap_eNB_handle_trace_start, 0, 0 }, /* TraceStart */ + { 0, 0, 0 }, /* TraceFailureIndication */ + { 0, 0, 0 }, /* ENBConfigurationUpdate */ + { 0, 0, 0 }, /* MMEConfigurationUpdate */ + { 0, 0, 0 }, /* LocationReportingControl */ + { 0, 0, 0 }, /* LocationReportingFailureIndication */ + { 0, 0, 0 }, /* LocationReport */ + { 0, 0, 0 }, /* OverloadStart */ + { 0, 0, 0 }, /* OverloadStop */ + { 0, 0, 0 }, /* WriteReplaceWarning */ + { 0, 0, 0 }, /* eNBDirectInformationTransfer */ + { 0, 0, 0 }, /* MMEDirectInformationTransfer */ + { 0, 0, 0 }, /* PrivateMessage */ + { 0, 0, 0 }, /* eNBConfigurationTransfer */ + { 0, 0, 0 }, /* MMEConfigurationTransfer */ + { 0, 0, 0 }, /* CellTrafficTrace */ #if (S1AP_VERSION >= MAKE_VERSION(9, 0, 0)) - { 0, 0, 0 }, /* Kill */ - { 0, 0, 0 }, /* DownlinkUEAssociatedLPPaTransport */ - { 0, 0, 0 }, /* UplinkUEAssociatedLPPaTransport */ - { 0, 0, 0 }, /* DownlinkNonUEAssociatedLPPaTransport */ - { 0, 0, 0 }, /* UplinkNonUEAssociatedLPPaTransport */ + { 0, 0, 0 }, /* Kill */ + { 0, 0, 0 }, /* DownlinkUEAssociatedLPPaTransport */ + { 0, 0, 0 }, /* UplinkUEAssociatedLPPaTransport */ + { 0, 0, 0 }, /* DownlinkNonUEAssociatedLPPaTransport */ + { 0, 0, 0 }, /* UplinkNonUEAssociatedLPPaTransport */ #endif /* #if (S1AP_VERSION >= MAKE_VERSION(9, 0, 0)) */ }; char *s1ap_direction2String(int s1ap_dir) { - static char *s1ap_direction_String[] = { - "", /* Nothing */ - "Originating message", /* originating message */ - "Successfull outcome", /* successfull outcome */ - "UnSuccessfull outcome", /* successfull outcome */ - }; - return(s1ap_direction_String[s1ap_dir]); + static char *s1ap_direction_String[] = { + "", /* Nothing */ + "Originating message", /* originating message */ + "Successfull outcome", /* successfull outcome */ + "UnSuccessfull outcome", /* successfull outcome */ + }; + return(s1ap_direction_String[s1ap_dir]); } void s1ap_handle_s1_setup_message(s1ap_eNB_mme_data_t *mme_desc_p, int sctp_shutdown) { - if (sctp_shutdown) { - /* A previously connected MME has been shutdown */ - - /* TODO check if it was used by some eNB and send a message to inform these eNB if there is no more associated MME */ - if (mme_desc_p->state == S1AP_ENB_STATE_CONNECTED) { - mme_desc_p->state = S1AP_ENB_STATE_DISCONNECTED; - - if (mme_desc_p->s1ap_eNB_instance->s1ap_mme_associated_nb > 0) { - /* Decrease associated MME number */ - mme_desc_p->s1ap_eNB_instance->s1ap_mme_associated_nb --; - } - - /* If there are no more associated MME, inform eNB app */ - if (mme_desc_p->s1ap_eNB_instance->s1ap_mme_associated_nb == 0) { - MessageDef *message_p; - message_p = itti_alloc_new_message(TASK_S1AP, S1AP_DEREGISTERED_ENB_IND); - S1AP_DEREGISTERED_ENB_IND(message_p).nb_mme = 0; - itti_send_msg_to_task(TASK_ENB_APP, mme_desc_p->s1ap_eNB_instance->instance, message_p); - } - } - } else { - /* Check that at least one setup message is pending */ - DevCheck(mme_desc_p->s1ap_eNB_instance->s1ap_mme_pending_nb > 0, mme_desc_p->s1ap_eNB_instance->instance, - mme_desc_p->s1ap_eNB_instance->s1ap_mme_pending_nb, 0); - - if (mme_desc_p->s1ap_eNB_instance->s1ap_mme_pending_nb > 0) { - /* Decrease pending messages number */ - mme_desc_p->s1ap_eNB_instance->s1ap_mme_pending_nb --; - } + if (sctp_shutdown) { + /* A previously connected MME has been shutdown */ + + /* TODO check if it was used by some eNB and send a message to inform these eNB if there is no more associated MME */ + if (mme_desc_p->state == S1AP_ENB_STATE_CONNECTED) { + mme_desc_p->state = S1AP_ENB_STATE_DISCONNECTED; + + if (mme_desc_p->s1ap_eNB_instance->s1ap_mme_associated_nb > 0) { + /* Decrease associated MME number */ + mme_desc_p->s1ap_eNB_instance->s1ap_mme_associated_nb --; + } + + /* If there are no more associated MME, inform eNB app */ + if (mme_desc_p->s1ap_eNB_instance->s1ap_mme_associated_nb == 0) { + MessageDef *message_p; + message_p = itti_alloc_new_message(TASK_S1AP, S1AP_DEREGISTERED_ENB_IND); + S1AP_DEREGISTERED_ENB_IND(message_p).nb_mme = 0; + itti_send_msg_to_task(TASK_ENB_APP, mme_desc_p->s1ap_eNB_instance->instance, message_p); + } + } + } else { + /* Check that at least one setup message is pending */ + DevCheck(mme_desc_p->s1ap_eNB_instance->s1ap_mme_pending_nb > 0, mme_desc_p->s1ap_eNB_instance->instance, + mme_desc_p->s1ap_eNB_instance->s1ap_mme_pending_nb, 0); - /* If there are no more pending messages, inform eNB app */ - if (mme_desc_p->s1ap_eNB_instance->s1ap_mme_pending_nb == 0) { - MessageDef *message_p; - message_p = itti_alloc_new_message(TASK_S1AP, S1AP_REGISTER_ENB_CNF); - S1AP_REGISTER_ENB_CNF(message_p).nb_mme = mme_desc_p->s1ap_eNB_instance->s1ap_mme_associated_nb; - itti_send_msg_to_task(TASK_ENB_APP, mme_desc_p->s1ap_eNB_instance->instance, message_p); + if (mme_desc_p->s1ap_eNB_instance->s1ap_mme_pending_nb > 0) { + /* Decrease pending messages number */ + mme_desc_p->s1ap_eNB_instance->s1ap_mme_pending_nb --; + } + + /* If there are no more pending messages, inform eNB app */ + if (mme_desc_p->s1ap_eNB_instance->s1ap_mme_pending_nb == 0) { + MessageDef *message_p; + message_p = itti_alloc_new_message(TASK_S1AP, S1AP_REGISTER_ENB_CNF); + S1AP_REGISTER_ENB_CNF(message_p).nb_mme = mme_desc_p->s1ap_eNB_instance->s1ap_mme_associated_nb; + itti_send_msg_to_task(TASK_ENB_APP, mme_desc_p->s1ap_eNB_instance->instance, message_p); + } } - } } int s1ap_eNB_handle_message(uint32_t assoc_id, int32_t stream, const uint8_t *const data, const uint32_t data_length) { - S1AP_S1AP_PDU_t pdu; - int ret; - DevAssert(data != NULL); - memset(&pdu, 0, sizeof(pdu)); - - if (s1ap_eNB_decode_pdu(&pdu, data, data_length) < 0) { - S1AP_ERROR("Failed to decode PDU\n"); - return -1; - } - - /* Checking procedure Code and direction of message */ - if (pdu.choice.initiatingMessage.procedureCode > sizeof(messages_callback) / (3 * sizeof( - s1ap_message_decoded_callback)) - || (pdu.present > S1AP_S1AP_PDU_PR_unsuccessfulOutcome)) { - S1AP_ERROR("[SCTP %d] Either procedureCode %ld or direction %d exceed expected\n", - assoc_id, pdu.choice.initiatingMessage.procedureCode, pdu.present); - ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_S1AP_S1AP_PDU, &pdu); - return -1; - } - - /* No handler present. - * This can mean not implemented or no procedure for eNB (wrong direction). - */ - if (messages_callback[pdu.choice.initiatingMessage.procedureCode][pdu.present - 1] == NULL) { - S1AP_ERROR("[SCTP %d] No handler for procedureCode %ld in %s\n", - assoc_id, pdu.choice.initiatingMessage.procedureCode, - s1ap_direction2String(pdu.present - 1)); + S1AP_S1AP_PDU_t pdu; + int ret; + DevAssert(data != NULL); + memset(&pdu, 0, sizeof(pdu)); + + if (s1ap_eNB_decode_pdu(&pdu, data, data_length) < 0) { + S1AP_ERROR("Failed to decode PDU\n"); + return -1; + } + + /* Checking procedure Code and direction of message */ + if (pdu.choice.initiatingMessage.procedureCode > sizeof(messages_callback) / (3 * sizeof( + s1ap_message_decoded_callback)) + || (pdu.present > S1AP_S1AP_PDU_PR_unsuccessfulOutcome)) { + S1AP_ERROR("[SCTP %d] Either procedureCode %ld or direction %d exceed expected\n", + assoc_id, pdu.choice.initiatingMessage.procedureCode, pdu.present); + ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_S1AP_S1AP_PDU, &pdu); + return -1; + } + + /* No handler present. + * This can mean not implemented or no procedure for eNB (wrong direction). + */ + if (messages_callback[pdu.choice.initiatingMessage.procedureCode][pdu.present - 1] == NULL) { + S1AP_ERROR("[SCTP %d] No handler for procedureCode %ld in %s\n", + assoc_id, pdu.choice.initiatingMessage.procedureCode, + s1ap_direction2String(pdu.present - 1)); + ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_S1AP_S1AP_PDU, &pdu); + return -1; + } + + /* Calling the right handler */ + ret = (*messages_callback[pdu.choice.initiatingMessage.procedureCode][pdu.present - 1]) + (assoc_id, stream, &pdu); ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_S1AP_S1AP_PDU, &pdu); - return -1; - } - - /* Calling the right handler */ - ret = (*messages_callback[pdu.choice.initiatingMessage.procedureCode][pdu.present - 1]) - (assoc_id, stream, &pdu); - ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_S1AP_S1AP_PDU, &pdu); - return ret; + return ret; } static int s1ap_eNB_handle_s1_setup_failure(uint32_t assoc_id, uint32_t stream, S1AP_S1AP_PDU_t *pdu) { - S1AP_S1SetupFailure_t *container; - S1AP_S1SetupFailureIEs_t *ie; - s1ap_eNB_mme_data_t *mme_desc_p; - DevAssert(pdu != NULL); - container = &pdu->choice.unsuccessfulOutcome.value.choice.S1SetupFailure; - - /* S1 Setup Failure == Non UE-related procedure -> stream 0 */ - if (stream != 0) { - S1AP_WARN("[SCTP %d] Received s1 setup failure on stream != 0 (%d)\n", - assoc_id, stream); - } - - if ((mme_desc_p = s1ap_eNB_get_MME(NULL, assoc_id, 0)) == NULL) { - S1AP_ERROR("[SCTP %d] Received S1 setup response for non existing " - "MME context\n", assoc_id); - return -1; - } - - S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_S1SetupFailureIEs_t, ie, container, - S1AP_ProtocolIE_ID_id_Cause, true); - - if ((ie->value.choice.Cause.present == S1AP_Cause_PR_misc) && - (ie->value.choice.Cause.choice.misc == S1AP_CauseMisc_unspecified)) { - S1AP_WARN("Received s1 setup failure for MME... MME is not ready\n"); - } else { - S1AP_ERROR("Received s1 setup failure for MME... please check your parameters\n"); - } - - mme_desc_p->state = S1AP_ENB_STATE_WAITING; - s1ap_handle_s1_setup_message(mme_desc_p, 0); - return 0; + S1AP_S1SetupFailure_t *container; + S1AP_S1SetupFailureIEs_t *ie; + s1ap_eNB_mme_data_t *mme_desc_p; + DevAssert(pdu != NULL); + container = &pdu->choice.unsuccessfulOutcome.value.choice.S1SetupFailure; + + /* S1 Setup Failure == Non UE-related procedure -> stream 0 */ + if (stream != 0) { + S1AP_WARN("[SCTP %d] Received s1 setup failure on stream != 0 (%d)\n", + assoc_id, stream); + } + + if ((mme_desc_p = s1ap_eNB_get_MME(NULL, assoc_id, 0)) == NULL) { + S1AP_ERROR("[SCTP %d] Received S1 setup response for non existing " + "MME context\n", assoc_id); + return -1; + } + + S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_S1SetupFailureIEs_t, ie, container, + S1AP_ProtocolIE_ID_id_Cause,true); + if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ + if ((ie->value.choice.Cause.present == S1AP_Cause_PR_misc) && + (ie->value.choice.Cause.choice.misc == S1AP_CauseMisc_unspecified)) { + S1AP_WARN("Received s1 setup failure for MME... MME is not ready\n"); + } else { + S1AP_ERROR("Received s1 setup failure for MME... please check your parameters\n"); + } + } else { + return -1; + } + mme_desc_p->state = S1AP_ENB_STATE_WAITING; + s1ap_handle_s1_setup_message(mme_desc_p, 0); + return 0; } static int s1ap_eNB_handle_s1_setup_response(uint32_t assoc_id, uint32_t stream, S1AP_S1AP_PDU_t *pdu) { - S1AP_S1SetupResponse_t *container; - S1AP_S1SetupResponseIEs_t *ie; - s1ap_eNB_mme_data_t *mme_desc_p; - int i; - DevAssert(pdu != NULL); - container = &pdu->choice.successfulOutcome.value.choice.S1SetupResponse; - - /* S1 Setup Response == Non UE-related procedure -> stream 0 */ - if (stream != 0) { - S1AP_ERROR("[SCTP %d] Received s1 setup response on stream != 0 (%d)\n", - assoc_id, stream); - return -1; - } - - if ((mme_desc_p = s1ap_eNB_get_MME(NULL, assoc_id, 0)) == NULL) { - S1AP_ERROR("[SCTP %d] Received S1 setup response for non existing " - "MME context\n", assoc_id); - return -1; - } - - S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_S1SetupResponseIEs_t, ie, container, - S1AP_ProtocolIE_ID_id_ServedGUMMEIs, true); - /* The list of served gummei can contain at most 8 elements. - * LTE related gummei is the first element in the list, i.e with an id of 0. - */ - S1AP_DEBUG("servedGUMMEIs.list.count %d\n", ie->value.choice.ServedGUMMEIs.list.count); - DevAssert(ie->value.choice.ServedGUMMEIs.list.count > 0); - DevAssert(ie->value.choice.ServedGUMMEIs.list.count <= S1AP_maxnoofRATs); - - for (i = 0; i < ie->value.choice.ServedGUMMEIs.list.count; i++) { - S1AP_ServedGUMMEIsItem_t *gummei_item_p; - struct served_gummei_s *new_gummei_p; - int j; - gummei_item_p = ie->value.choice.ServedGUMMEIs.list.array[i]; - new_gummei_p = calloc(1, sizeof(struct served_gummei_s)); - STAILQ_INIT(&new_gummei_p->served_plmns); - STAILQ_INIT(&new_gummei_p->served_group_ids); - STAILQ_INIT(&new_gummei_p->mme_codes); - S1AP_DEBUG("servedPLMNs.list.count %d\n", gummei_item_p->servedPLMNs.list.count); - - for (j = 0; j < gummei_item_p->servedPLMNs.list.count; j++) { - S1AP_PLMNidentity_t *plmn_identity_p; - struct plmn_identity_s *new_plmn_identity_p; - plmn_identity_p = gummei_item_p->servedPLMNs.list.array[j]; - new_plmn_identity_p = calloc(1, sizeof(struct plmn_identity_s)); - TBCD_TO_MCC_MNC(plmn_identity_p, new_plmn_identity_p->mcc, - new_plmn_identity_p->mnc, new_plmn_identity_p->mnc_digit_length); - STAILQ_INSERT_TAIL(&new_gummei_p->served_plmns, new_plmn_identity_p, next); - new_gummei_p->nb_served_plmns++; + S1AP_S1SetupResponse_t *container; + S1AP_S1SetupResponseIEs_t *ie; + s1ap_eNB_mme_data_t *mme_desc_p; + int i; + DevAssert(pdu != NULL); + container = &pdu->choice.successfulOutcome.value.choice.S1SetupResponse; + + /* S1 Setup Response == Non UE-related procedure -> stream 0 */ + if (stream != 0) { + S1AP_ERROR("[SCTP %d] Received s1 setup response on stream != 0 (%d)\n", + assoc_id, stream); + return -1; } - for (j = 0; j < gummei_item_p->servedGroupIDs.list.count; j++) { - S1AP_MME_Group_ID_t *mme_group_id_p; - struct served_group_id_s *new_group_id_p; - mme_group_id_p = gummei_item_p->servedGroupIDs.list.array[j]; - new_group_id_p = calloc(1, sizeof(struct served_group_id_s)); - OCTET_STRING_TO_INT16(mme_group_id_p, new_group_id_p->mme_group_id); - STAILQ_INSERT_TAIL(&new_gummei_p->served_group_ids, new_group_id_p, next); - new_gummei_p->nb_group_id++; + if ((mme_desc_p = s1ap_eNB_get_MME(NULL, assoc_id, 0)) == NULL) { + S1AP_ERROR("[SCTP %d] Received S1 setup response for non existing " + "MME context\n", assoc_id); + return -1; } - for (j = 0; j < gummei_item_p->servedMMECs.list.count; j++) { - S1AP_MME_Code_t *mme_code_p; - struct mme_code_s *new_mme_code_p; - mme_code_p = gummei_item_p->servedMMECs.list.array[j]; - new_mme_code_p = calloc(1, sizeof(struct mme_code_s)); - OCTET_STRING_TO_INT8(mme_code_p, new_mme_code_p->mme_code); - STAILQ_INSERT_TAIL(&new_gummei_p->mme_codes, new_mme_code_p, next); - new_gummei_p->nb_mme_code++; + S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_S1SetupResponseIEs_t, ie, container, + S1AP_ProtocolIE_ID_id_ServedGUMMEIs, true); + /* The list of served gummei can contain at most 8 elements. + * LTE related gummei is the first element in the list, i.e with an id of 0. + */ + if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ + S1AP_DEBUG("servedGUMMEIs.list.count %d\n", ie->value.choice.ServedGUMMEIs.list.count); + DevAssert(ie->value.choice.ServedGUMMEIs.list.count > 0); + DevAssert(ie->value.choice.ServedGUMMEIs.list.count <= S1AP_maxnoofRATs); + + for (i = 0; i < ie->value.choice.ServedGUMMEIs.list.count; i++) { + S1AP_ServedGUMMEIsItem_t *gummei_item_p; + struct served_gummei_s *new_gummei_p; + int j; + gummei_item_p = ie->value.choice.ServedGUMMEIs.list.array[i]; + new_gummei_p = calloc(1, sizeof(struct served_gummei_s)); + STAILQ_INIT(&new_gummei_p->served_plmns); + STAILQ_INIT(&new_gummei_p->served_group_ids); + STAILQ_INIT(&new_gummei_p->mme_codes); + S1AP_DEBUG("servedPLMNs.list.count %d\n", gummei_item_p->servedPLMNs.list.count); + + for (j = 0; j < gummei_item_p->servedPLMNs.list.count; j++) { + S1AP_PLMNidentity_t *plmn_identity_p; + struct plmn_identity_s *new_plmn_identity_p; + plmn_identity_p = gummei_item_p->servedPLMNs.list.array[j]; + new_plmn_identity_p = calloc(1, sizeof(struct plmn_identity_s)); + TBCD_TO_MCC_MNC(plmn_identity_p, new_plmn_identity_p->mcc, + new_plmn_identity_p->mnc, new_plmn_identity_p->mnc_digit_length); + STAILQ_INSERT_TAIL(&new_gummei_p->served_plmns, new_plmn_identity_p, next); + new_gummei_p->nb_served_plmns++; + } + + for (j = 0; j < gummei_item_p->servedGroupIDs.list.count; j++) { + S1AP_MME_Group_ID_t *mme_group_id_p; + struct served_group_id_s *new_group_id_p; + mme_group_id_p = gummei_item_p->servedGroupIDs.list.array[j]; + new_group_id_p = calloc(1, sizeof(struct served_group_id_s)); + OCTET_STRING_TO_INT16(mme_group_id_p, new_group_id_p->mme_group_id); + STAILQ_INSERT_TAIL(&new_gummei_p->served_group_ids, new_group_id_p, next); + new_gummei_p->nb_group_id++; + } + + for (j = 0; j < gummei_item_p->servedMMECs.list.count; j++) { + S1AP_MME_Code_t *mme_code_p; + struct mme_code_s *new_mme_code_p; + mme_code_p = gummei_item_p->servedMMECs.list.array[j]; + new_mme_code_p = calloc(1, sizeof(struct mme_code_s)); + OCTET_STRING_TO_INT8(mme_code_p, new_mme_code_p->mme_code); + STAILQ_INSERT_TAIL(&new_gummei_p->mme_codes, new_mme_code_p, next); + new_gummei_p->nb_mme_code++; + } + + STAILQ_INSERT_TAIL(&mme_desc_p->served_gummei, new_gummei_p, next); + } + } else { + return -1; + } + /* Set the capacity of this MME */ + S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_S1SetupResponseIEs_t, ie, container, + S1AP_ProtocolIE_ID_id_RelativeMMECapacity, true); + if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ + mme_desc_p->relative_mme_capacity = ie->value.choice.RelativeMMECapacity; + } else { + return -1; + } + /* Optionaly set the mme name */ + S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_S1SetupResponseIEs_t, ie, container, + S1AP_ProtocolIE_ID_id_MMEname, false); + + if (ie) { + mme_desc_p->mme_name = calloc(ie->value.choice.MMEname.size + 1, sizeof(char)); + memcpy(mme_desc_p->mme_name, ie->value.choice.MMEname.buf, + ie->value.choice.MMEname.size); + /* Convert the mme name to a printable string */ + mme_desc_p->mme_name[ie->value.choice.MMEname.size] = '\0'; } - STAILQ_INSERT_TAIL(&mme_desc_p->served_gummei, new_gummei_p, next); - } - - /* Set the capacity of this MME */ - S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_S1SetupResponseIEs_t, ie, container, - S1AP_ProtocolIE_ID_id_RelativeMMECapacity, true); - mme_desc_p->relative_mme_capacity = ie->value.choice.RelativeMMECapacity; - /* Optionaly set the mme name */ - S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_S1SetupResponseIEs_t, ie, container, - S1AP_ProtocolIE_ID_id_MMEname, false); - - if (ie) { - mme_desc_p->mme_name = calloc(ie->value.choice.MMEname.size + 1, sizeof(char)); - memcpy(mme_desc_p->mme_name, ie->value.choice.MMEname.buf, - ie->value.choice.MMEname.size); - /* Convert the mme name to a printable string */ - mme_desc_p->mme_name[ie->value.choice.MMEname.size] = '\0'; - } - - /* The association is now ready as eNB and MME know parameters of each other. - * Mark the association as UP to enable UE contexts creation. - */ - mme_desc_p->state = S1AP_ENB_STATE_CONNECTED; - mme_desc_p->s1ap_eNB_instance->s1ap_mme_associated_nb ++; - s1ap_handle_s1_setup_message(mme_desc_p, 0); - return 0; + /* The association is now ready as eNB and MME know parameters of each other. + * Mark the association as UP to enable UE contexts creation. + */ + mme_desc_p->state = S1AP_ENB_STATE_CONNECTED; + mme_desc_p->s1ap_eNB_instance->s1ap_mme_associated_nb ++; + s1ap_handle_s1_setup_message(mme_desc_p, 0); + return 0; } @@ -382,992 +391,1059 @@ static int s1ap_eNB_handle_error_indication(uint32_t assoc_id, uint32_t stream, S1AP_S1AP_PDU_t *pdu) { - S1AP_ErrorIndication_t *container; - S1AP_ErrorIndicationIEs_t *ie; - s1ap_eNB_mme_data_t *mme_desc_p; - DevAssert(pdu != NULL); - container = &pdu->choice.initiatingMessage.value.choice.ErrorIndication; - - /* S1 Setup Failure == Non UE-related procedure -> stream 0 */ - if (stream != 0) { - S1AP_WARN("[SCTP %d] Received s1 Error indication on stream != 0 (%d)\n", - assoc_id, stream); - } - - if ((mme_desc_p = s1ap_eNB_get_MME(NULL, assoc_id, 0)) == NULL) { - S1AP_ERROR("[SCTP %d] Received S1 Error indication for non existing " - "MME context\n", assoc_id); - return -1; - } - - S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_ErrorIndicationIEs_t, ie, container, - S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID, false); - - /* optional */ - if (!ie) { - S1AP_WARN("Received S1 Error indication MME UE S1AP ID 0x%lx\n", ie->value.choice.MME_UE_S1AP_ID); - } - - S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_ErrorIndicationIEs_t, ie, container, - S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID, false); - - /* optional */ - if (!ie) { - S1AP_WARN("Received S1 Error indication eNB UE S1AP ID 0x%lx\n", ie->value.choice.ENB_UE_S1AP_ID); - } - - S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_ErrorIndicationIEs_t, ie, container, - S1AP_ProtocolIE_ID_id_Cause, false); - - /* optional */ - if (ie) { - switch(ie->value.choice.Cause.present) { - case S1AP_Cause_PR_NOTHING: - S1AP_WARN("Received S1 Error indication cause NOTHING\n"); - break; - - case S1AP_Cause_PR_radioNetwork: - switch (ie->value.choice.Cause.choice.radioNetwork) { - case S1AP_CauseRadioNetwork_unspecified: - S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_unspecified\n"); - break; + S1AP_ErrorIndication_t *container; + S1AP_ErrorIndicationIEs_t *ie; + s1ap_eNB_mme_data_t *mme_desc_p; + DevAssert(pdu != NULL); + container = &pdu->choice.initiatingMessage.value.choice.ErrorIndication; + + /* S1 Setup Failure == Non UE-related procedure -> stream 0 */ + if (stream != 0) { + S1AP_WARN("[SCTP %d] Received s1 Error indication on stream != 0 (%d)\n", + assoc_id, stream); + } - case S1AP_CauseRadioNetwork_tx2relocoverall_expiry: - S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_tx2relocoverall_expiry\n"); - break; + if ((mme_desc_p = s1ap_eNB_get_MME(NULL, assoc_id, 0)) == NULL) { + S1AP_ERROR("[SCTP %d] Received S1 Error indication for non existing " + "MME context\n", assoc_id); + return -1; + } + S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_ErrorIndicationIEs_t, ie, container, + S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID, false); - case S1AP_CauseRadioNetwork_successful_handover: - S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_successful_handover\n"); - break; + /* optional */ + if (ie != NULL) { + S1AP_WARN("Received S1 Error indication MME UE S1AP ID 0x%lx\n", ie->value.choice.MME_UE_S1AP_ID); + } - case S1AP_CauseRadioNetwork_release_due_to_eutran_generated_reason: - S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_release_due_to_eutran_generated_reason\n"); - break; + S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_ErrorIndicationIEs_t, ie, container, + S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID, false); - case S1AP_CauseRadioNetwork_handover_cancelled: - S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_handover_cancelled\n"); - break; + /* optional */ + if (ie != NULL) { + S1AP_WARN("Received S1 Error indication eNB UE S1AP ID 0x%lx\n", ie->value.choice.ENB_UE_S1AP_ID); + } - case S1AP_CauseRadioNetwork_partial_handover: - S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_partial_handover\n"); - break; + S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_ErrorIndicationIEs_t, ie, container, + S1AP_ProtocolIE_ID_id_Cause, false); - case S1AP_CauseRadioNetwork_ho_failure_in_target_EPC_eNB_or_target_system: - S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_ho_failure_in_target_EPC_eNB_or_target_system\n"); + /* optional */ + if (ie) { + switch(ie->value.choice.Cause.present) { + case S1AP_Cause_PR_NOTHING: + S1AP_WARN("Received S1 Error indication cause NOTHING\n"); break; - case S1AP_CauseRadioNetwork_ho_target_not_allowed: - S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_ho_target_not_allowed\n"); - break; + case S1AP_Cause_PR_radioNetwork: + switch (ie->value.choice.Cause.choice.radioNetwork) { + case S1AP_CauseRadioNetwork_unspecified: + S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_unspecified\n"); + break; - case S1AP_CauseRadioNetwork_tS1relocoverall_expiry: - S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_tS1relocoverall_expiry\n"); - break; + case S1AP_CauseRadioNetwork_tx2relocoverall_expiry: + S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_tx2relocoverall_expiry\n"); + break; - case S1AP_CauseRadioNetwork_tS1relocprep_expiry: - S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_tS1relocprep_expiry\n"); - break; + case S1AP_CauseRadioNetwork_successful_handover: + S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_successful_handover\n"); + break; - case S1AP_CauseRadioNetwork_cell_not_available: - S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_cell_not_available\n"); - break; + case S1AP_CauseRadioNetwork_release_due_to_eutran_generated_reason: + S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_release_due_to_eutran_generated_reason\n"); + break; - case S1AP_CauseRadioNetwork_unknown_targetID: - S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_unknown_targetID\n"); - break; + case S1AP_CauseRadioNetwork_handover_cancelled: + S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_handover_cancelled\n"); + break; - case S1AP_CauseRadioNetwork_no_radio_resources_available_in_target_cell: - S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_no_radio_resources_available_in_target_cell\n"); - break; + case S1AP_CauseRadioNetwork_partial_handover: + S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_partial_handover\n"); + break; - case S1AP_CauseRadioNetwork_unknown_mme_ue_s1ap_id: - S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_unknown_mme_ue_s1ap_id\n"); - break; + case S1AP_CauseRadioNetwork_ho_failure_in_target_EPC_eNB_or_target_system: + S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_ho_failure_in_target_EPC_eNB_or_target_system\n"); + break; - case S1AP_CauseRadioNetwork_unknown_enb_ue_s1ap_id: - S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_unknown_enb_ue_s1ap_id\n"); - break; + case S1AP_CauseRadioNetwork_ho_target_not_allowed: + S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_ho_target_not_allowed\n"); + break; - case S1AP_CauseRadioNetwork_unknown_pair_ue_s1ap_id: - S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_unknown_pair_ue_s1ap_id\n"); - break; + case S1AP_CauseRadioNetwork_tS1relocoverall_expiry: + S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_tS1relocoverall_expiry\n"); + break; - case S1AP_CauseRadioNetwork_handover_desirable_for_radio_reason: - S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_handover_desirable_for_radio_reason\n"); - break; + case S1AP_CauseRadioNetwork_tS1relocprep_expiry: + S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_tS1relocprep_expiry\n"); + break; - case S1AP_CauseRadioNetwork_time_critical_handover: - S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_time_critical_handover\n"); - break; + case S1AP_CauseRadioNetwork_cell_not_available: + S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_cell_not_available\n"); + break; - case S1AP_CauseRadioNetwork_resource_optimisation_handover: - S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_resource_optimisation_handover\n"); - break; + case S1AP_CauseRadioNetwork_unknown_targetID: + S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_unknown_targetID\n"); + break; - case S1AP_CauseRadioNetwork_reduce_load_in_serving_cell: - S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_reduce_load_in_serving_cell\n"); - break; + case S1AP_CauseRadioNetwork_no_radio_resources_available_in_target_cell: + S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_no_radio_resources_available_in_target_cell\n"); + break; - case S1AP_CauseRadioNetwork_user_inactivity: - S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_user_inactivity\n"); - break; + case S1AP_CauseRadioNetwork_unknown_mme_ue_s1ap_id: + S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_unknown_mme_ue_s1ap_id\n"); + break; - case S1AP_CauseRadioNetwork_radio_connection_with_ue_lost: - S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_radio_connection_with_ue_lost\n"); - break; + case S1AP_CauseRadioNetwork_unknown_enb_ue_s1ap_id: + S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_unknown_enb_ue_s1ap_id\n"); + break; - case S1AP_CauseRadioNetwork_load_balancing_tau_required: - S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_load_balancing_tau_required\n"); - break; + case S1AP_CauseRadioNetwork_unknown_pair_ue_s1ap_id: + S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_unknown_pair_ue_s1ap_id\n"); + break; - case S1AP_CauseRadioNetwork_cs_fallback_triggered: - S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_cs_fallback_triggered\n"); - break; + case S1AP_CauseRadioNetwork_handover_desirable_for_radio_reason: + S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_handover_desirable_for_radio_reason\n"); + break; - case S1AP_CauseRadioNetwork_ue_not_available_for_ps_service: - S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_ue_not_available_for_ps_service\n"); - break; + case S1AP_CauseRadioNetwork_time_critical_handover: + S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_time_critical_handover\n"); + break; - case S1AP_CauseRadioNetwork_radio_resources_not_available: - S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_radio_resources_not_available\n"); - break; + case S1AP_CauseRadioNetwork_resource_optimisation_handover: + S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_resource_optimisation_handover\n"); + break; - case S1AP_CauseRadioNetwork_failure_in_radio_interface_procedure: - S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_failure_in_radio_interface_procedure\n"); - break; + case S1AP_CauseRadioNetwork_reduce_load_in_serving_cell: + S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_reduce_load_in_serving_cell\n"); + break; - case S1AP_CauseRadioNetwork_invalid_qos_combination: - S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_invals1ap_id_qos_combination\n"); - break; + case S1AP_CauseRadioNetwork_user_inactivity: + S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_user_inactivity\n"); + break; - case S1AP_CauseRadioNetwork_interrat_redirection: - S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_interrat_redirection\n"); - break; + case S1AP_CauseRadioNetwork_radio_connection_with_ue_lost: + S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_radio_connection_with_ue_lost\n"); + break; - case S1AP_CauseRadioNetwork_interaction_with_other_procedure: - S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_interaction_with_other_procedure\n"); - break; + case S1AP_CauseRadioNetwork_load_balancing_tau_required: + S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_load_balancing_tau_required\n"); + break; - case S1AP_CauseRadioNetwork_unknown_E_RAB_ID: - S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_unknown_E_RAB_ID\n"); - break; + case S1AP_CauseRadioNetwork_cs_fallback_triggered: + S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_cs_fallback_triggered\n"); + break; - case S1AP_CauseRadioNetwork_multiple_E_RAB_ID_instances: - S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_multiple_E_RAB_ID_instances\n"); - break; + case S1AP_CauseRadioNetwork_ue_not_available_for_ps_service: + S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_ue_not_available_for_ps_service\n"); + break; + + case S1AP_CauseRadioNetwork_radio_resources_not_available: + S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_radio_resources_not_available\n"); + break; - case S1AP_CauseRadioNetwork_encryption_and_or_integrity_protection_algorithms_not_supported: - S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_encryption_and_or_integrity_protection_algorithms_not_supported\n"); - break; + case S1AP_CauseRadioNetwork_failure_in_radio_interface_procedure: + S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_failure_in_radio_interface_procedure\n"); + break; - case S1AP_CauseRadioNetwork_s1_intra_system_handover_triggered: - S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_s1_intra_system_handover_triggered\n"); - break; + case S1AP_CauseRadioNetwork_invalid_qos_combination: + S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_invals1ap_id_qos_combination\n"); + break; - case S1AP_CauseRadioNetwork_s1_inter_system_handover_triggered: - S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_s1_inter_system_handover_triggered\n"); - break; + case S1AP_CauseRadioNetwork_interrat_redirection: + S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_interrat_redirection\n"); + break; - case S1AP_CauseRadioNetwork_x2_handover_triggered: - S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_x2_handover_triggered\n"); - break; + case S1AP_CauseRadioNetwork_interaction_with_other_procedure: + S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_interaction_with_other_procedure\n"); + break; - case S1AP_CauseRadioNetwork_redirection_towards_1xRTT: - S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_redirection_towards_1xRTT\n"); - break; + case S1AP_CauseRadioNetwork_unknown_E_RAB_ID: + S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_unknown_E_RAB_ID\n"); + break; - case S1AP_CauseRadioNetwork_not_supported_QCI_value: - S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_not_supported_QCI_value\n"); - break; + case S1AP_CauseRadioNetwork_multiple_E_RAB_ID_instances: + S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_multiple_E_RAB_ID_instances\n"); + break; + + case S1AP_CauseRadioNetwork_encryption_and_or_integrity_protection_algorithms_not_supported: + S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_encryption_and_or_integrity_protection_algorithms_not_supported\n"); + break; + + case S1AP_CauseRadioNetwork_s1_intra_system_handover_triggered: + S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_s1_intra_system_handover_triggered\n"); + break; + + case S1AP_CauseRadioNetwork_s1_inter_system_handover_triggered: + S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_s1_inter_system_handover_triggered\n"); + break; + + case S1AP_CauseRadioNetwork_x2_handover_triggered: + S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_x2_handover_triggered\n"); + break; + + case S1AP_CauseRadioNetwork_redirection_towards_1xRTT: + S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_redirection_towards_1xRTT\n"); + break; + + case S1AP_CauseRadioNetwork_not_supported_QCI_value: + S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_not_supported_QCI_value\n"); + break; #if (S1AP_VERSION >= MAKE_VERSION(9, 0, 0)) - case S1AP_CauseRadioNetwork_invalid_CSG_Id: - S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_invals1ap_id_CSG_Id\n"); - break; + case S1AP_CauseRadioNetwork_invalid_CSG_Id: + S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_invals1ap_id_CSG_Id\n"); + break; #endif /* #if (S1AP_VERSION >= MAKE_VERSION(9, 0, 0)) */ - default: - S1AP_WARN("Received S1 Error indication cause radio network case not handled\n"); - } - - break; + default: + S1AP_WARN("Received S1 Error indication cause radio network case not handled\n"); + } - case S1AP_Cause_PR_transport: - switch (ie->value.choice.Cause.choice.transport) { - case S1AP_CauseTransport_transport_resource_unavailable: - S1AP_WARN("Received S1 Error indication S1AP_CauseTransport_transport_resource_unavailable\n"); break; - case S1AP_CauseTransport_unspecified: - S1AP_WARN("Received S1 Error indication S1AP_CauseTransport_unspecified\n"); - break; + case S1AP_Cause_PR_transport: + switch (ie->value.choice.Cause.choice.transport) { + case S1AP_CauseTransport_transport_resource_unavailable: + S1AP_WARN("Received S1 Error indication S1AP_CauseTransport_transport_resource_unavailable\n"); + break; - default: - S1AP_WARN("Received S1 Error indication cause transport case not handled\n"); - } + case S1AP_CauseTransport_unspecified: + S1AP_WARN("Received S1 Error indication S1AP_CauseTransport_unspecified\n"); + break; - break; + default: + S1AP_WARN("Received S1 Error indication cause transport case not handled\n"); + } - case S1AP_Cause_PR_nas: - switch (ie->value.choice.Cause.choice.nas) { - case S1AP_CauseNas_normal_release: - S1AP_WARN("Received S1 Error indication S1AP_CauseNas_normal_release\n"); break; - case S1AP_CauseNas_authentication_failure: - S1AP_WARN("Received S1 Error indication S1AP_CauseNas_authentication_failure\n"); - break; + case S1AP_Cause_PR_nas: + switch (ie->value.choice.Cause.choice.nas) { + case S1AP_CauseNas_normal_release: + S1AP_WARN("Received S1 Error indication S1AP_CauseNas_normal_release\n"); + break; - case S1AP_CauseNas_detach: - S1AP_WARN("Received S1 Error indication S1AP_CauseNas_detach\n"); - break; + case S1AP_CauseNas_authentication_failure: + S1AP_WARN("Received S1 Error indication S1AP_CauseNas_authentication_failure\n"); + break; - case S1AP_CauseNas_unspecified: - S1AP_WARN("Received S1 Error indication S1AP_CauseNas_unspecified\n"); - break; + case S1AP_CauseNas_detach: + S1AP_WARN("Received S1 Error indication S1AP_CauseNas_detach\n"); + break; + + case S1AP_CauseNas_unspecified: + S1AP_WARN("Received S1 Error indication S1AP_CauseNas_unspecified\n"); + break; #if (S1AP_VERSION >= MAKE_VERSION(9, 0, 0)) - case S1AP_CauseNas_csg_subscription_expiry: - S1AP_WARN("Received S1 Error indication S1AP_CauseNas_csg_subscription_expiry\n"); - break; + case S1AP_CauseNas_csg_subscription_expiry: + S1AP_WARN("Received S1 Error indication S1AP_CauseNas_csg_subscription_expiry\n"); + break; #endif /* #if (S1AP_VERSION >= MAKE_VERSION(9, 0, 0)) */ - default: - S1AP_WARN("Received S1 Error indication cause nas case not handled\n"); - } - - break; + default: + S1AP_WARN("Received S1 Error indication cause nas case not handled\n"); + } - case S1AP_Cause_PR_protocol: - switch (ie->value.choice.Cause.choice.protocol) { - case S1AP_CauseProtocol_transfer_syntax_error: - S1AP_WARN("Received S1 Error indication S1AP_CauseProtocol_transfer_syntax_error\n"); break; - case S1AP_CauseProtocol_abstract_syntax_error_reject: - S1AP_WARN("Received S1 Error indication S1AP_CauseProtocol_abstract_syntax_error_reject\n"); - break; + case S1AP_Cause_PR_protocol: + switch (ie->value.choice.Cause.choice.protocol) { + case S1AP_CauseProtocol_transfer_syntax_error: + S1AP_WARN("Received S1 Error indication S1AP_CauseProtocol_transfer_syntax_error\n"); + break; - case S1AP_CauseProtocol_abstract_syntax_error_ignore_and_notify: - S1AP_WARN("Received S1 Error indication S1AP_CauseProtocol_abstract_syntax_error_ignore_and_notify\n"); - break; + case S1AP_CauseProtocol_abstract_syntax_error_reject: + S1AP_WARN("Received S1 Error indication S1AP_CauseProtocol_abstract_syntax_error_reject\n"); + break; - case S1AP_CauseProtocol_message_not_compatible_with_receiver_state: - S1AP_WARN("Received S1 Error indication S1AP_CauseProtocol_message_not_compatible_with_receiver_state\n"); - break; + case S1AP_CauseProtocol_abstract_syntax_error_ignore_and_notify: + S1AP_WARN("Received S1 Error indication S1AP_CauseProtocol_abstract_syntax_error_ignore_and_notify\n"); + break; - case S1AP_CauseProtocol_semantic_error: - S1AP_WARN("Received S1 Error indication S1AP_CauseProtocol_semantic_error\n"); - break; + case S1AP_CauseProtocol_message_not_compatible_with_receiver_state: + S1AP_WARN("Received S1 Error indication S1AP_CauseProtocol_message_not_compatible_with_receiver_state\n"); + break; - case S1AP_CauseProtocol_abstract_syntax_error_falsely_constructed_message: - S1AP_WARN("Received S1 Error indication S1AP_CauseProtocol_abstract_syntax_error_falsely_constructed_message\n"); - break; + case S1AP_CauseProtocol_semantic_error: + S1AP_WARN("Received S1 Error indication S1AP_CauseProtocol_semantic_error\n"); + break; - case S1AP_CauseProtocol_unspecified: - S1AP_WARN("Received S1 Error indication S1AP_CauseProtocol_unspecified\n"); - break; + case S1AP_CauseProtocol_abstract_syntax_error_falsely_constructed_message: + S1AP_WARN("Received S1 Error indication S1AP_CauseProtocol_abstract_syntax_error_falsely_constructed_message\n"); + break; - default: - S1AP_WARN("Received S1 Error indication cause protocol case not handled\n"); - } + case S1AP_CauseProtocol_unspecified: + S1AP_WARN("Received S1 Error indication S1AP_CauseProtocol_unspecified\n"); + break; - break; + default: + S1AP_WARN("Received S1 Error indication cause protocol case not handled\n"); + } - case S1AP_Cause_PR_misc: - switch (ie->value.choice.Cause.choice.protocol) { - case S1AP_CauseMisc_control_processing_overload: - S1AP_WARN("Received S1 Error indication S1AP_CauseMisc_control_processing_overload\n"); break; - case S1AP_CauseMisc_not_enough_user_plane_processing_resources: - S1AP_WARN("Received S1 Error indication S1AP_CauseMisc_not_enough_user_plane_processing_resources\n"); - break; + case S1AP_Cause_PR_misc: + switch (ie->value.choice.Cause.choice.protocol) { + case S1AP_CauseMisc_control_processing_overload: + S1AP_WARN("Received S1 Error indication S1AP_CauseMisc_control_processing_overload\n"); + break; - case S1AP_CauseMisc_hardware_failure: - S1AP_WARN("Received S1 Error indication S1AP_CauseMisc_hardware_failure\n"); - break; + case S1AP_CauseMisc_not_enough_user_plane_processing_resources: + S1AP_WARN("Received S1 Error indication S1AP_CauseMisc_not_enough_user_plane_processing_resources\n"); + break; - case S1AP_CauseMisc_om_intervention: - S1AP_WARN("Received S1 Error indication S1AP_CauseMisc_om_intervention\n"); - break; + case S1AP_CauseMisc_hardware_failure: + S1AP_WARN("Received S1 Error indication S1AP_CauseMisc_hardware_failure\n"); + break; - case S1AP_CauseMisc_unspecified: - S1AP_WARN("Received S1 Error indication S1AP_CauseMisc_unspecified\n"); - break; + case S1AP_CauseMisc_om_intervention: + S1AP_WARN("Received S1 Error indication S1AP_CauseMisc_om_intervention\n"); + break; - case S1AP_CauseMisc_unknown_PLMN: - S1AP_WARN("Received S1 Error indication S1AP_CauseMisc_unknown_PLMN\n"); - break; + case S1AP_CauseMisc_unspecified: + S1AP_WARN("Received S1 Error indication S1AP_CauseMisc_unspecified\n"); + break; - default: - S1AP_WARN("Received S1 Error indication cause misc case not handled\n"); - } + case S1AP_CauseMisc_unknown_PLMN: + S1AP_WARN("Received S1 Error indication S1AP_CauseMisc_unknown_PLMN\n"); + break; - break; + default: + S1AP_WARN("Received S1 Error indication cause misc case not handled\n"); + } + + break; + } } - } - S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_ErrorIndicationIEs_t, ie, container, - S1AP_ProtocolIE_ID_id_CriticalityDiagnostics, false); + S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_ErrorIndicationIEs_t, ie, container, + S1AP_ProtocolIE_ID_id_CriticalityDiagnostics, false); - if (ie) { - // TODO continue - } + if (ie) { + // TODO continue + } - // TODO continue - return 0; + // TODO continue + return 0; } static int s1ap_eNB_handle_initial_context_request(uint32_t assoc_id, - uint32_t stream, - S1AP_S1AP_PDU_t *pdu) { - int i; - s1ap_eNB_mme_data_t *mme_desc_p = NULL; - s1ap_eNB_ue_context_t *ue_desc_p = NULL; - MessageDef *message_p = NULL; - S1AP_InitialContextSetupRequest_t *container; - S1AP_InitialContextSetupRequestIEs_t *ie; - S1AP_ENB_UE_S1AP_ID_t enb_ue_s1ap_id; - S1AP_MME_UE_S1AP_ID_t mme_ue_s1ap_id; - DevAssert(pdu != NULL); - container = &pdu->choice.initiatingMessage.value.choice.InitialContextSetupRequest; - - if ((mme_desc_p = s1ap_eNB_get_MME(NULL, assoc_id, 0)) == NULL) { - S1AP_ERROR("[SCTP %d] Received initial context setup request for non " - "existing MME context\n", assoc_id); - return -1; - } - - /* id-MME-UE-S1AP-ID */ - S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_InitialContextSetupRequestIEs_t, ie, container, - S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID, true); - mme_ue_s1ap_id = ie->value.choice.MME_UE_S1AP_ID; - /* id-eNB-UE-S1AP-ID */ - S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_InitialContextSetupRequestIEs_t, ie, container, - S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID, true); - enb_ue_s1ap_id = ie->value.choice.ENB_UE_S1AP_ID; - - if ((ue_desc_p = s1ap_eNB_get_ue_context(mme_desc_p->s1ap_eNB_instance, - enb_ue_s1ap_id)) == NULL) { - S1AP_ERROR("[SCTP %d] Received initial context setup request for non " - "existing UE context 0x%06lx\n", assoc_id, - enb_ue_s1ap_id); - return -1; - } - - /* Initial context request = UE-related procedure -> stream != 0 */ - if (stream == 0) { - S1AP_ERROR("[SCTP %d] Received UE-related procedure on stream (%d)\n", - assoc_id, stream); - return -1; - } - - ue_desc_p->rx_stream = stream; - ue_desc_p->mme_ue_s1ap_id = mme_ue_s1ap_id; - message_p = itti_alloc_new_message(TASK_S1AP, S1AP_INITIAL_CONTEXT_SETUP_REQ); - S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).ue_initial_id = ue_desc_p->ue_initial_id; - ue_desc_p->ue_initial_id = 0; - S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).eNB_ue_s1ap_id = ue_desc_p->eNB_ue_s1ap_id; - /* id-uEaggregateMaximumBitrate */ - S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_InitialContextSetupRequestIEs_t, ie, container, - S1AP_ProtocolIE_ID_id_uEaggregateMaximumBitrate, true); - asn_INTEGER2ulong(&(ie->value.choice.UEAggregateMaximumBitrate.uEaggregateMaximumBitRateUL), - &(S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).ue_ambr.br_ul)); - asn_INTEGER2ulong(&(ie->value.choice.UEAggregateMaximumBitrate.uEaggregateMaximumBitRateDL), - &(S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).ue_ambr.br_dl)); - /* id-E-RABToBeSetupListCtxtSUReq */ - S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_InitialContextSetupRequestIEs_t, ie, container, - S1AP_ProtocolIE_ID_id_E_RABToBeSetupListCtxtSUReq, true); - S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).nb_of_e_rabs = - ie->value.choice.E_RABToBeSetupListCtxtSUReq.list.count; - - for (i = 0; i < ie->value.choice.E_RABToBeSetupListCtxtSUReq.list.count; i++) { - S1AP_E_RABToBeSetupItemCtxtSUReq_t *item_p; - item_p = &(((S1AP_E_RABToBeSetupItemCtxtSUReqIEs_t *)ie->value.choice.E_RABToBeSetupListCtxtSUReq.list.array[i])->value.choice.E_RABToBeSetupItemCtxtSUReq); - S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].e_rab_id = item_p->e_RAB_ID; - - if (item_p->nAS_PDU != NULL) { - /* Only copy NAS pdu if present */ - S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].nas_pdu.length = item_p->nAS_PDU->size; - S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].nas_pdu.buffer = - malloc(sizeof(uint8_t) * item_p->nAS_PDU->size); - memcpy(S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].nas_pdu.buffer, - item_p->nAS_PDU->buf, item_p->nAS_PDU->size); - S1AP_DEBUG("Received NAS message with the E_RAB setup procedure\n"); + uint32_t stream, + S1AP_S1AP_PDU_t *pdu) { + int i; + s1ap_eNB_mme_data_t *mme_desc_p = NULL; + s1ap_eNB_ue_context_t *ue_desc_p = NULL; + MessageDef *message_p = NULL; + S1AP_InitialContextSetupRequest_t *container; + S1AP_InitialContextSetupRequestIEs_t *ie; + S1AP_ENB_UE_S1AP_ID_t enb_ue_s1ap_id; + S1AP_MME_UE_S1AP_ID_t mme_ue_s1ap_id; + DevAssert(pdu != NULL); + container = &pdu->choice.initiatingMessage.value.choice.InitialContextSetupRequest; + + if ((mme_desc_p = s1ap_eNB_get_MME(NULL, assoc_id, 0)) == NULL) { + S1AP_ERROR("[SCTP %d] Received initial context setup request for non " + "existing MME context\n", assoc_id); + return -1; + } + + /* id-MME-UE-S1AP-ID */ + S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_InitialContextSetupRequestIEs_t, ie, container, + S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID, true); + if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ + mme_ue_s1ap_id = ie->value.choice.MME_UE_S1AP_ID; } else { - S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].nas_pdu.length = 0; - S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].nas_pdu.buffer = NULL; + return -1; + } + /* id-eNB-UE-S1AP-ID */ + S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_InitialContextSetupRequestIEs_t, ie, container, + S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID, true); + if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ + enb_ue_s1ap_id = ie->value.choice.ENB_UE_S1AP_ID; + if ((ue_desc_p = s1ap_eNB_get_ue_context(mme_desc_p->s1ap_eNB_instance, + enb_ue_s1ap_id)) == NULL) { + S1AP_ERROR("[SCTP %d] Received initial context setup request for non " + "existing UE context 0x%06lx\n", assoc_id, + enb_ue_s1ap_id); + return -1; + } + } else { + return -1; + } + + /* Initial context request = UE-related procedure -> stream != 0 */ + if (stream == 0) { + S1AP_ERROR("[SCTP %d] Received UE-related procedure on stream (%d)\n", + assoc_id, stream); + return -1; } - /* Set the transport layer address */ - memcpy(S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].sgw_addr.buffer, - item_p->transportLayerAddress.buf, item_p->transportLayerAddress.size); - S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].sgw_addr.length = - item_p->transportLayerAddress.size * 8 - item_p->transportLayerAddress.bits_unused; - /* GTP tunnel endpoint ID */ - OCTET_STRING_TO_INT32(&item_p->gTP_TEID, S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].gtp_teid); - /* Set the QOS informations */ - S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].qos.qci = item_p->e_RABlevelQoSParameters.qCI; - S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].qos.allocation_retention_priority.priority_level = - item_p->e_RABlevelQoSParameters.allocationRetentionPriority.priorityLevel; - S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].qos.allocation_retention_priority.pre_emp_capability = - item_p->e_RABlevelQoSParameters.allocationRetentionPriority.pre_emptionCapability; - S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].qos.allocation_retention_priority.pre_emp_vulnerability = - item_p->e_RABlevelQoSParameters.allocationRetentionPriority.pre_emptionVulnerability; - } - - /* id-UESecurityCapabilities */ - S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_InitialContextSetupRequestIEs_t, ie, container, - S1AP_ProtocolIE_ID_id_UESecurityCapabilities, true); - S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).security_capabilities.encryption_algorithms = - BIT_STRING_to_uint16(&ie->value.choice.UESecurityCapabilities.encryptionAlgorithms); - S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).security_capabilities.integrity_algorithms = - BIT_STRING_to_uint16(&ie->value.choice.UESecurityCapabilities.integrityProtectionAlgorithms); - /* id-SecurityKey : Copy the security key */ - S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_InitialContextSetupRequestIEs_t, ie, container, - S1AP_ProtocolIE_ID_id_SecurityKey, true); - memcpy(&S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).security_key, - ie->value.choice.SecurityKey.buf, ie->value.choice.SecurityKey.size); - itti_send_msg_to_task(TASK_RRC_ENB, ue_desc_p->eNB_instance->instance, message_p); - return 0; + ue_desc_p->rx_stream = stream; + ue_desc_p->mme_ue_s1ap_id = mme_ue_s1ap_id; + message_p = itti_alloc_new_message(TASK_S1AP, S1AP_INITIAL_CONTEXT_SETUP_REQ); + S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).ue_initial_id = ue_desc_p->ue_initial_id; + ue_desc_p->ue_initial_id = 0; + S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).eNB_ue_s1ap_id = ue_desc_p->eNB_ue_s1ap_id; + /* id-uEaggregateMaximumBitrate */ + S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_InitialContextSetupRequestIEs_t, ie, container, + S1AP_ProtocolIE_ID_id_uEaggregateMaximumBitrate, true); + if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ + asn_INTEGER2ulong(&(ie->value.choice.UEAggregateMaximumBitrate.uEaggregateMaximumBitRateUL), + &(S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).ue_ambr.br_ul)); + asn_INTEGER2ulong(&(ie->value.choice.UEAggregateMaximumBitrate.uEaggregateMaximumBitRateDL), + &(S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).ue_ambr.br_dl)); + /* id-E-RABToBeSetupListCtxtSUReq */ + } else { + return -1; + } + S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_InitialContextSetupRequestIEs_t, ie, container, + S1AP_ProtocolIE_ID_id_E_RABToBeSetupListCtxtSUReq, true); + if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ + S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).nb_of_e_rabs = + ie->value.choice.E_RABToBeSetupListCtxtSUReq.list.count; + + for (i = 0; i < ie->value.choice.E_RABToBeSetupListCtxtSUReq.list.count; i++) { + S1AP_E_RABToBeSetupItemCtxtSUReq_t *item_p; + item_p = &(((S1AP_E_RABToBeSetupItemCtxtSUReqIEs_t *)ie->value.choice.E_RABToBeSetupListCtxtSUReq.list.array[i])->value.choice.E_RABToBeSetupItemCtxtSUReq); + S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].e_rab_id = item_p->e_RAB_ID; + + if (item_p->nAS_PDU != NULL) { + /* Only copy NAS pdu if present */ + S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].nas_pdu.length = item_p->nAS_PDU->size; + S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].nas_pdu.buffer = + malloc(sizeof(uint8_t) * item_p->nAS_PDU->size); + memcpy(S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].nas_pdu.buffer, + item_p->nAS_PDU->buf, item_p->nAS_PDU->size); + S1AP_DEBUG("Received NAS message with the E_RAB setup procedure\n"); + } else { + S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].nas_pdu.length = 0; + S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].nas_pdu.buffer = NULL; + } + + /* Set the transport layer address */ + memcpy(S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].sgw_addr.buffer, + item_p->transportLayerAddress.buf, item_p->transportLayerAddress.size); + S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].sgw_addr.length = + item_p->transportLayerAddress.size * 8 - item_p->transportLayerAddress.bits_unused; + /* GTP tunnel endpoint ID */ + OCTET_STRING_TO_INT32(&item_p->gTP_TEID, S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].gtp_teid); + /* Set the QOS informations */ + S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].qos.qci = item_p->e_RABlevelQoSParameters.qCI; + S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].qos.allocation_retention_priority.priority_level = + item_p->e_RABlevelQoSParameters.allocationRetentionPriority.priorityLevel; + S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].qos.allocation_retention_priority.pre_emp_capability = + item_p->e_RABlevelQoSParameters.allocationRetentionPriority.pre_emptionCapability; + S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].qos.allocation_retention_priority.pre_emp_vulnerability = + item_p->e_RABlevelQoSParameters.allocationRetentionPriority.pre_emptionVulnerability; + } /* for i... */ + } else {/* ie != NULL */ + return -1; + } + /* id-UESecurityCapabilities */ + S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_InitialContextSetupRequestIEs_t, ie, container, + S1AP_ProtocolIE_ID_id_UESecurityCapabilities, true); + if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ + S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).security_capabilities.encryption_algorithms = + BIT_STRING_to_uint16(&ie->value.choice.UESecurityCapabilities.encryptionAlgorithms); + S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).security_capabilities.integrity_algorithms = + BIT_STRING_to_uint16(&ie->value.choice.UESecurityCapabilities.integrityProtectionAlgorithms); + /* id-SecurityKey : Copy the security key */ + } else {/* ie != NULL */ + return -1; + } + S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_InitialContextSetupRequestIEs_t, ie, container, + S1AP_ProtocolIE_ID_id_SecurityKey, true); + if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ + memcpy(&S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).security_key, + ie->value.choice.SecurityKey.buf, ie->value.choice.SecurityKey.size); + itti_send_msg_to_task(TASK_RRC_ENB, ue_desc_p->eNB_instance->instance, message_p); + } else {/* ie != NULL */ + return -1; + } + return 0; } static int s1ap_eNB_handle_ue_context_release_command(uint32_t assoc_id, - uint32_t stream, - S1AP_S1AP_PDU_t *pdu) { - s1ap_eNB_mme_data_t *mme_desc_p = NULL; - s1ap_eNB_ue_context_t *ue_desc_p = NULL; - MessageDef *message_p = NULL; - S1AP_MME_UE_S1AP_ID_t mme_ue_s1ap_id; - S1AP_ENB_UE_S1AP_ID_t enb_ue_s1ap_id; - S1AP_UEContextReleaseCommand_t *container; - S1AP_UEContextReleaseCommand_IEs_t *ie; - DevAssert(pdu != NULL); - container = &pdu->choice.initiatingMessage.value.choice.UEContextReleaseCommand; - - if ((mme_desc_p = s1ap_eNB_get_MME(NULL, assoc_id, 0)) == NULL) { - S1AP_ERROR("[SCTP %d] Received UE context release command for non " - "existing MME context\n", assoc_id); - return -1; - } - - S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_UEContextReleaseCommand_IEs_t, ie, container, - S1AP_ProtocolIE_ID_id_UE_S1AP_IDs, true); - - switch (ie->value.choice.UE_S1AP_IDs.present) { - case S1AP_UE_S1AP_IDs_PR_uE_S1AP_ID_pair: - enb_ue_s1ap_id = ie->value.choice.UE_S1AP_IDs.choice.uE_S1AP_ID_pair.eNB_UE_S1AP_ID; - mme_ue_s1ap_id = ie->value.choice.UE_S1AP_IDs.choice.uE_S1AP_ID_pair.mME_UE_S1AP_ID; - MSC_LOG_RX_MESSAGE( - MSC_S1AP_ENB, - MSC_S1AP_MME, - NULL,0, - "0 UEContextRelease/%s eNB_ue_s1ap_id "S1AP_UE_ID_FMT" mme_ue_s1ap_id "S1AP_UE_ID_FMT" len %u", - s1ap_direction2String(pdu->present - 1), - enb_ue_s1ap_id, - mme_ue_s1ap_id); - - if ((ue_desc_p = s1ap_eNB_get_ue_context(mme_desc_p->s1ap_eNB_instance, - enb_ue_s1ap_id)) == NULL) { + uint32_t stream, + S1AP_S1AP_PDU_t *pdu) { + s1ap_eNB_mme_data_t *mme_desc_p = NULL; + s1ap_eNB_ue_context_t *ue_desc_p = NULL; + MessageDef *message_p = NULL; + S1AP_MME_UE_S1AP_ID_t mme_ue_s1ap_id; + S1AP_ENB_UE_S1AP_ID_t enb_ue_s1ap_id; + S1AP_UEContextReleaseCommand_t *container; + S1AP_UEContextReleaseCommand_IEs_t *ie; + DevAssert(pdu != NULL); + container = &pdu->choice.initiatingMessage.value.choice.UEContextReleaseCommand; + + if ((mme_desc_p = s1ap_eNB_get_MME(NULL, assoc_id, 0)) == NULL) { S1AP_ERROR("[SCTP %d] Received UE context release command for non " - "existing UE context 0x%06lx\n", - assoc_id, - enb_ue_s1ap_id); + "existing MME context\n", assoc_id); return -1; - } else { - MSC_LOG_TX_MESSAGE( - MSC_S1AP_ENB, - MSC_RRC_ENB, - NULL,0, - "0 S1AP_UE_CONTEXT_RELEASE_COMMAND/%d eNB_ue_s1ap_id "S1AP_UE_ID_FMT" ", - enb_ue_s1ap_id); - message_p = itti_alloc_new_message(TASK_S1AP, S1AP_UE_CONTEXT_RELEASE_COMMAND); - - if (ue_desc_p->mme_ue_s1ap_id == 0) { // case of Detach Request and switch off from RRC_IDLE mode - ue_desc_p->mme_ue_s1ap_id = mme_ue_s1ap_id; - } - - S1AP_UE_CONTEXT_RELEASE_COMMAND(message_p).eNB_ue_s1ap_id = enb_ue_s1ap_id; - itti_send_msg_to_task(TASK_RRC_ENB, ue_desc_p->eNB_instance->instance, message_p); - return 0; - } + } - break; + S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_UEContextReleaseCommand_IEs_t, ie, container, + S1AP_ProtocolIE_ID_id_UE_S1AP_IDs, true); + if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ + switch (ie->value.choice.UE_S1AP_IDs.present) { + case S1AP_UE_S1AP_IDs_PR_uE_S1AP_ID_pair: + enb_ue_s1ap_id = ie->value.choice.UE_S1AP_IDs.choice.uE_S1AP_ID_pair.eNB_UE_S1AP_ID; + mme_ue_s1ap_id = ie->value.choice.UE_S1AP_IDs.choice.uE_S1AP_ID_pair.mME_UE_S1AP_ID; + MSC_LOG_RX_MESSAGE( + MSC_S1AP_ENB, + MSC_S1AP_MME, + NULL,0, + "0 UEContextRelease/%s eNB_ue_s1ap_id "S1AP_UE_ID_FMT" mme_ue_s1ap_id "S1AP_UE_ID_FMT" len %u", + s1ap_direction2String(pdu->present - 1), + enb_ue_s1ap_id, + mme_ue_s1ap_id); + + if ((ue_desc_p = s1ap_eNB_get_ue_context(mme_desc_p->s1ap_eNB_instance, + enb_ue_s1ap_id)) == NULL) { + S1AP_ERROR("[SCTP %d] Received UE context release command for non " + "existing UE context 0x%06lx\n", + assoc_id, + enb_ue_s1ap_id); + return -1; + } else { + MSC_LOG_TX_MESSAGE( + MSC_S1AP_ENB, + MSC_RRC_ENB, + NULL,0, + "0 S1AP_UE_CONTEXT_RELEASE_COMMAND/%d eNB_ue_s1ap_id "S1AP_UE_ID_FMT" ", + enb_ue_s1ap_id); + message_p = itti_alloc_new_message(TASK_S1AP, S1AP_UE_CONTEXT_RELEASE_COMMAND); + + if (ue_desc_p->mme_ue_s1ap_id == 0) { // case of Detach Request and switch off from RRC_IDLE mode + ue_desc_p->mme_ue_s1ap_id = mme_ue_s1ap_id; + } + + S1AP_UE_CONTEXT_RELEASE_COMMAND(message_p).eNB_ue_s1ap_id = enb_ue_s1ap_id; + itti_send_msg_to_task(TASK_RRC_ENB, ue_desc_p->eNB_instance->instance, message_p); + return 0; + } - //#warning "TODO mapping mme_ue_s1ap_id enb_ue_s1ap_id?" + break; - case S1AP_UE_S1AP_IDs_PR_mME_UE_S1AP_ID: - mme_ue_s1ap_id = ie->value.choice.UE_S1AP_IDs.choice.uE_S1AP_ID_pair.mME_UE_S1AP_ID; - S1AP_ERROR("TO DO mapping mme_ue_s1ap_id enb_ue_s1ap_id"); - (void)mme_ue_s1ap_id; /* TODO: remove - it's to remove gcc warning about unused var */ + //#warning "TODO mapping mme_ue_s1ap_id enb_ue_s1ap_id?" - case S1AP_UE_S1AP_IDs_PR_NOTHING: - default: - S1AP_ERROR("S1AP_UE_CONTEXT_RELEASE_COMMAND not processed, missing info elements"); - return -1; - } + case S1AP_UE_S1AP_IDs_PR_mME_UE_S1AP_ID: + mme_ue_s1ap_id = ie->value.choice.UE_S1AP_IDs.choice.uE_S1AP_ID_pair.mME_UE_S1AP_ID; + S1AP_ERROR("TO DO mapping mme_ue_s1ap_id enb_ue_s1ap_id"); + (void)mme_ue_s1ap_id; /* TODO: remove - it's to remove gcc warning about unused var */ - S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_UEContextReleaseCommand_IEs_t, ie, container, - S1AP_ProtocolIE_ID_id_Cause, true); - /* TBD */ + case S1AP_UE_S1AP_IDs_PR_NOTHING: + default: + S1AP_ERROR("S1AP_UE_CONTEXT_RELEASE_COMMAND not processed, missing info elements"); + return -1; + } + } else { + return -1; + } + S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_UEContextReleaseCommand_IEs_t, ie, container, + S1AP_ProtocolIE_ID_id_Cause, true); + /* TBD */ } static int s1ap_eNB_handle_e_rab_setup_request(uint32_t assoc_id, uint32_t stream, S1AP_S1AP_PDU_t *pdu) { - int i; - S1AP_MME_UE_S1AP_ID_t mme_ue_s1ap_id; - S1AP_ENB_UE_S1AP_ID_t enb_ue_s1ap_id; - s1ap_eNB_mme_data_t *mme_desc_p = NULL; - s1ap_eNB_ue_context_t *ue_desc_p = NULL; - MessageDef *message_p = NULL; - S1AP_E_RABSetupRequest_t *container; - S1AP_E_RABSetupRequestIEs_t *ie; - DevAssert(pdu != NULL); - container = &pdu->choice.initiatingMessage.value.choice.E_RABSetupRequest; - - if ((mme_desc_p = s1ap_eNB_get_MME(NULL, assoc_id, 0)) == NULL) { - S1AP_ERROR("[SCTP %d] Received initial context setup request for non " - "existing MME context\n", assoc_id); - return -1; - } - - /* id-MME-UE-S1AP-ID */ - S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_E_RABSetupRequestIEs_t, ie, container, - S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID, true); - mme_ue_s1ap_id = ie->value.choice.MME_UE_S1AP_ID; - /* id-eNB-UE-S1AP-ID */ - S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_E_RABSetupRequestIEs_t, ie, container, - S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID, true); - enb_ue_s1ap_id = ie->value.choice.ENB_UE_S1AP_ID; - - if ((ue_desc_p = s1ap_eNB_get_ue_context(mme_desc_p->s1ap_eNB_instance, - enb_ue_s1ap_id)) == NULL) { - S1AP_ERROR("[SCTP %d] Received initial context setup request for non " - "existing UE context 0x%06lx\n", assoc_id, - enb_ue_s1ap_id); - return -1; - } - - /* Initial context request = UE-related procedure -> stream != 0 */ - if (stream == 0) { - S1AP_ERROR("[SCTP %d] Received UE-related procedure on stream (%d)\n", - assoc_id, stream); - return -1; - } - - ue_desc_p->rx_stream = stream; - - if ( ue_desc_p->mme_ue_s1ap_id != mme_ue_s1ap_id) { - S1AP_WARN("UE context mme_ue_s1ap_id is different form that of the message (%d != %ld)", - ue_desc_p->mme_ue_s1ap_id, mme_ue_s1ap_id); - } - - message_p = itti_alloc_new_message(TASK_S1AP, S1AP_E_RAB_SETUP_REQ); - S1AP_E_RAB_SETUP_REQ(message_p).ue_initial_id = ue_desc_p->ue_initial_id; - S1AP_E_RAB_SETUP_REQ(message_p).mme_ue_s1ap_id = mme_ue_s1ap_id; - S1AP_E_RAB_SETUP_REQ(message_p).eNB_ue_s1ap_id = enb_ue_s1ap_id; - S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_E_RABSetupRequestIEs_t, ie, container, - S1AP_ProtocolIE_ID_id_E_RABToBeSetupListBearerSUReq, true); - S1AP_E_RAB_SETUP_REQ(message_p).nb_e_rabs_tosetup = - ie->value.choice.E_RABToBeSetupListBearerSUReq.list.count; - - for (i = 0; i < ie->value.choice.E_RABToBeSetupListBearerSUReq.list.count; i++) { - S1AP_E_RABToBeSetupItemBearerSUReq_t *item_p; - item_p = &(((S1AP_E_RABToBeSetupItemBearerSUReqIEs_t *)ie->value.choice.E_RABToBeSetupListBearerSUReq.list.array[i])->value.choice.E_RABToBeSetupItemBearerSUReq); - S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].e_rab_id = item_p->e_RAB_ID; - - // check for the NAS PDU - if (item_p->nAS_PDU.size > 0 ) { - S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].nas_pdu.length = item_p->nAS_PDU.size; - S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].nas_pdu.buffer = malloc(sizeof(uint8_t) * item_p->nAS_PDU.size); - memcpy(S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].nas_pdu.buffer, - item_p->nAS_PDU.buf, item_p->nAS_PDU.size); - // S1AP_INFO("received a NAS PDU with size %d (%02x.%02x)\n",S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].nas_pdu.length, item_p->nAS_PDU.buf[0], item_p->nAS_PDU.buf[1]); + int i; + S1AP_MME_UE_S1AP_ID_t mme_ue_s1ap_id; + S1AP_ENB_UE_S1AP_ID_t enb_ue_s1ap_id; + s1ap_eNB_mme_data_t *mme_desc_p = NULL; + s1ap_eNB_ue_context_t *ue_desc_p = NULL; + MessageDef *message_p = NULL; + S1AP_E_RABSetupRequest_t *container; + S1AP_E_RABSetupRequestIEs_t *ie; + DevAssert(pdu != NULL); + container = &pdu->choice.initiatingMessage.value.choice.E_RABSetupRequest; + + if ((mme_desc_p = s1ap_eNB_get_MME(NULL, assoc_id, 0)) == NULL) { + S1AP_ERROR("[SCTP %d] Received initial context setup request for non " + "existing MME context\n", assoc_id); + return -1; + } + + /* id-MME-UE-S1AP-ID */ + S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_E_RABSetupRequestIEs_t, ie, container, + S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID, true); + if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ + mme_ue_s1ap_id = ie->value.choice.MME_UE_S1AP_ID; } else { - S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].nas_pdu.length = 0; - S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].nas_pdu.buffer = NULL; - S1AP_WARN("NAS PDU is not provided, generate a E_RAB_SETUP Failure (TBD) back to MME \n"); - // return -1; + return -1; + } + /* id-eNB-UE-S1AP-ID */ + S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_E_RABSetupRequestIEs_t, ie, container, + S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID, true); + if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ + enb_ue_s1ap_id = ie->value.choice.ENB_UE_S1AP_ID; + } else { + return -1; + } + if ((ue_desc_p = s1ap_eNB_get_ue_context(mme_desc_p->s1ap_eNB_instance, + enb_ue_s1ap_id)) == NULL) { + S1AP_ERROR("[SCTP %d] Received initial context setup request for non " + "existing UE context 0x%06lx\n", assoc_id, + enb_ue_s1ap_id); + return -1; + } + + /* Initial context request = UE-related procedure -> stream != 0 */ + if (stream == 0) { + S1AP_ERROR("[SCTP %d] Received UE-related procedure on stream (%d)\n", + assoc_id, stream); + return -1; + } + + ue_desc_p->rx_stream = stream; + + if ( ue_desc_p->mme_ue_s1ap_id != mme_ue_s1ap_id) { + S1AP_WARN("UE context mme_ue_s1ap_id is different form that of the message (%d != %ld)", + ue_desc_p->mme_ue_s1ap_id, mme_ue_s1ap_id); } - /* Set the transport layer address */ - memcpy(S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].sgw_addr.buffer, - item_p->transportLayerAddress.buf, item_p->transportLayerAddress.size); - S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].sgw_addr.length = - item_p->transportLayerAddress.size * 8 - item_p->transportLayerAddress.bits_unused; - /* S1AP_INFO("sgw addr %s len: %d (size %d, index %d)\n", - S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].sgw_addr.buffer, - S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].sgw_addr.length, - item_p->transportLayerAddress.size, i); - */ - /* GTP tunnel endpoint ID */ - OCTET_STRING_TO_INT32(&item_p->gTP_TEID, S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].gtp_teid); - /* Set the QOS informations */ - S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].qos.qci = item_p->e_RABlevelQoSParameters.qCI; - S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].qos.allocation_retention_priority.priority_level = - item_p->e_RABlevelQoSParameters.allocationRetentionPriority.priorityLevel; - S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].qos.allocation_retention_priority.pre_emp_capability = - item_p->e_RABlevelQoSParameters.allocationRetentionPriority.pre_emptionCapability; - S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].qos.allocation_retention_priority.pre_emp_vulnerability = - item_p->e_RABlevelQoSParameters.allocationRetentionPriority.pre_emptionVulnerability; - } - - itti_send_msg_to_task(TASK_RRC_ENB, ue_desc_p->eNB_instance->instance, message_p); - return 0; + message_p = itti_alloc_new_message(TASK_S1AP, S1AP_E_RAB_SETUP_REQ); + S1AP_E_RAB_SETUP_REQ(message_p).ue_initial_id = ue_desc_p->ue_initial_id; + S1AP_E_RAB_SETUP_REQ(message_p).mme_ue_s1ap_id = mme_ue_s1ap_id; + S1AP_E_RAB_SETUP_REQ(message_p).eNB_ue_s1ap_id = enb_ue_s1ap_id; + S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_E_RABSetupRequestIEs_t, ie, container, + S1AP_ProtocolIE_ID_id_E_RABToBeSetupListBearerSUReq, true); + if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ + S1AP_E_RAB_SETUP_REQ(message_p).nb_e_rabs_tosetup = + ie->value.choice.E_RABToBeSetupListBearerSUReq.list.count; + + for (i = 0; i < ie->value.choice.E_RABToBeSetupListBearerSUReq.list.count; i++) { + S1AP_E_RABToBeSetupItemBearerSUReq_t *item_p; + item_p = &(((S1AP_E_RABToBeSetupItemBearerSUReqIEs_t *)ie->value.choice.E_RABToBeSetupListBearerSUReq.list.array[i])->value.choice.E_RABToBeSetupItemBearerSUReq); + S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].e_rab_id = item_p->e_RAB_ID; + + // check for the NAS PDU + if (item_p->nAS_PDU.size > 0 ) { + S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].nas_pdu.length = item_p->nAS_PDU.size; + S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].nas_pdu.buffer = malloc(sizeof(uint8_t) * item_p->nAS_PDU.size); + memcpy(S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].nas_pdu.buffer, + item_p->nAS_PDU.buf, item_p->nAS_PDU.size); + // S1AP_INFO("received a NAS PDU with size %d (%02x.%02x)\n",S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].nas_pdu.length, item_p->nAS_PDU.buf[0], item_p->nAS_PDU.buf[1]); + } else { + S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].nas_pdu.length = 0; + S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].nas_pdu.buffer = NULL; + S1AP_WARN("NAS PDU is not provided, generate a E_RAB_SETUP Failure (TBD) back to MME \n"); + } + + /* Set the transport layer address */ + memcpy(S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].sgw_addr.buffer, + item_p->transportLayerAddress.buf, item_p->transportLayerAddress.size); + S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].sgw_addr.length = + item_p->transportLayerAddress.size * 8 - item_p->transportLayerAddress.bits_unused; + /* S1AP_INFO("sgw addr %s len: %d (size %d, index %d)\n", + S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].sgw_addr.buffer, + S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].sgw_addr.length, + item_p->transportLayerAddress.size, i); + */ + /* GTP tunnel endpoint ID */ + OCTET_STRING_TO_INT32(&item_p->gTP_TEID, S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].gtp_teid); + /* Set the QOS informations */ + S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].qos.qci = item_p->e_RABlevelQoSParameters.qCI; + S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].qos.allocation_retention_priority.priority_level = + item_p->e_RABlevelQoSParameters.allocationRetentionPriority.priorityLevel; + S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].qos.allocation_retention_priority.pre_emp_capability = + item_p->e_RABlevelQoSParameters.allocationRetentionPriority.pre_emptionCapability; + S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].qos.allocation_retention_priority.pre_emp_vulnerability = + item_p->e_RABlevelQoSParameters.allocationRetentionPriority.pre_emptionVulnerability; + } /* for i... */ + itti_send_msg_to_task(TASK_RRC_ENB, ue_desc_p->eNB_instance->instance, message_p); + } else { + return -1; + } + return 0; } static int s1ap_eNB_handle_paging(uint32_t assoc_id, uint32_t stream, S1AP_S1AP_PDU_t *pdu) { - s1ap_eNB_mme_data_t *mme_desc_p = NULL; - s1ap_eNB_instance_t *s1ap_eNB_instance = NULL; - MessageDef *message_p = NULL; - S1AP_Paging_t *container; - S1AP_PagingIEs_t *ie; - DevAssert(pdu != NULL); - container = &pdu->choice.initiatingMessage.value.choice.Paging; - // received Paging Message from MME - S1AP_DEBUG("[SCTP %d] Received Paging Message From MME\n",assoc_id); - - /* Paging procedure -> stream != 0 */ - if (stream == 0) { - LOG_W(S1AP,"[SCTP %d] Received Paging procedure on stream (%d)\n", - assoc_id, stream); - return -1; - } - - if ((mme_desc_p = s1ap_eNB_get_MME(NULL, assoc_id, 0)) == NULL) { - S1AP_ERROR("[SCTP %d] Received Paging for non " - "existing MME context\n", assoc_id); - return -1; - } - - s1ap_eNB_instance = mme_desc_p->s1ap_eNB_instance; - - if (s1ap_eNB_instance == NULL) { - S1AP_ERROR("[SCTP %d] Received Paging for non existing MME context : s1ap_eNB_instance is NULL\n", - assoc_id); - return -1; - } - - message_p = itti_alloc_new_message(TASK_S1AP, S1AP_PAGING_IND); - /* convert S1AP_PagingIEs_t to s1ap_paging_ind_t */ - /* id-UEIdentityIndexValue : convert UE Identity Index value */ - S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_PagingIEs_t, ie, container, - S1AP_ProtocolIE_ID_id_UEIdentityIndexValue, true); - S1AP_PAGING_IND(message_p).ue_index_value = BIT_STRING_to_uint32(&ie->value.choice.UEIdentityIndexValue); - S1AP_DEBUG("[SCTP %d] Received Paging ue_index_value (%d)\n", - assoc_id,(uint32_t)S1AP_PAGING_IND(message_p).ue_index_value); - S1AP_PAGING_IND(message_p).ue_paging_identity.choice.s_tmsi.mme_code = 0; - S1AP_PAGING_IND(message_p).ue_paging_identity.choice.s_tmsi.m_tmsi = 0; - /* id-UEPagingID */ - S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_PagingIEs_t, ie, container, - S1AP_ProtocolIE_ID_id_UEPagingID, true); - - /* convert UE Paging Identity */ - if (ie->value.choice.UEPagingID.present == S1AP_UEPagingID_PR_s_TMSI) { - S1AP_PAGING_IND(message_p).ue_paging_identity.presenceMask = UE_PAGING_IDENTITY_s_tmsi; - OCTET_STRING_TO_INT8(&ie->value.choice.UEPagingID.choice.s_TMSI.mMEC, S1AP_PAGING_IND(message_p).ue_paging_identity.choice.s_tmsi.mme_code); - OCTET_STRING_TO_INT32(&ie->value.choice.UEPagingID.choice.s_TMSI.m_TMSI, S1AP_PAGING_IND(message_p).ue_paging_identity.choice.s_tmsi.m_tmsi); - } else if (ie->value.choice.UEPagingID.present == S1AP_UEPagingID_PR_iMSI) { - S1AP_PAGING_IND(message_p).ue_paging_identity.presenceMask = UE_PAGING_IDENTITY_imsi; - S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.length = 0; - - for (int i = 0; i < ie->value.choice.UEPagingID.choice.iMSI.size; i++) { - S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.buffer[2*i] = (uint8_t)(ie->value.choice.UEPagingID.choice.iMSI.buf[i] & 0x0F ); - S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.length++; - S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.buffer[2*i+1] = (uint8_t)((ie->value.choice.UEPagingID.choice.iMSI.buf[i]>>4) & 0x0F); - LOG_D(S1AP,"paging : i %d %d imsi %d %d \n",2*i,2*i+1,S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.buffer[2*i], S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.buffer[2*i+1]); - - if (S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.buffer[2*i+1] == 0x0F) { - if(i != ie->value.choice.UEPagingID.choice.iMSI.size - 1) { - /* invalid paging_p->uePagingID.choise.iMSI.buffer */ - S1AP_ERROR("[SCTP %d] Received Paging : uePagingID.choise.iMSI error(i %d 0x0F)\n", assoc_id,i); - return -1; - } - } else { - S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.length++; - } + s1ap_eNB_mme_data_t *mme_desc_p = NULL; + s1ap_eNB_instance_t *s1ap_eNB_instance = NULL; + MessageDef *message_p = NULL; + S1AP_Paging_t *container; + S1AP_PagingIEs_t *ie; + DevAssert(pdu != NULL); + container = &pdu->choice.initiatingMessage.value.choice.Paging; + // received Paging Message from MME + S1AP_DEBUG("[SCTP %d] Received Paging Message From MME\n",assoc_id); + + /* Paging procedure -> stream != 0 */ + if (stream == 0) { + LOG_W(S1AP,"[SCTP %d] Received Paging procedure on stream (%d)\n", + assoc_id, stream); + return -1; } - if (S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.length >= S1AP_IMSI_LENGTH) { - /* invalid paging_p->uePagingID.choise.iMSI.size */ - S1AP_ERROR("[SCTP %d] Received Paging : uePagingID.choise.iMSI.size(%d) is over IMSI length(%d)\n", assoc_id, S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.length, S1AP_IMSI_LENGTH); - return -1; + if ((mme_desc_p = s1ap_eNB_get_MME(NULL, assoc_id, 0)) == NULL) { + S1AP_ERROR("[SCTP %d] Received Paging for non " + "existing MME context\n", assoc_id); + return -1; + } + + s1ap_eNB_instance = mme_desc_p->s1ap_eNB_instance; + + if (s1ap_eNB_instance == NULL) { + S1AP_ERROR("[SCTP %d] Received Paging for non existing MME context : s1ap_eNB_instance is NULL\n", + assoc_id); + return -1; } - } else { - /* invalid paging_p->uePagingID.present */ - S1AP_ERROR("[SCTP %d] Received Paging : uePagingID.present(%d) is unknown\n", assoc_id, ie->value.choice.UEPagingID.present); - return -1; - } - - S1AP_PAGING_IND(message_p).paging_drx = PAGING_DRX_256; - /* id-pagingDRX */ - S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_PagingIEs_t, ie, container, - S1AP_ProtocolIE_ID_id_pagingDRX, false); - - /* optional */ - if (ie) { - S1AP_PAGING_IND(message_p).paging_drx = ie->value.choice.PagingDRX; - } else { + + message_p = itti_alloc_new_message(TASK_S1AP, S1AP_PAGING_IND); + /* convert S1AP_PagingIEs_t to s1ap_paging_ind_t */ + /* id-UEIdentityIndexValue : convert UE Identity Index value */ + S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_PagingIEs_t, ie, container, + S1AP_ProtocolIE_ID_id_UEIdentityIndexValue, true); + if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ + S1AP_PAGING_IND(message_p).ue_index_value = BIT_STRING_to_uint32(&ie->value.choice.UEIdentityIndexValue); + S1AP_DEBUG("[SCTP %d] Received Paging ue_index_value (%d)\n", + assoc_id,(uint32_t)S1AP_PAGING_IND(message_p).ue_index_value); + S1AP_PAGING_IND(message_p).ue_paging_identity.choice.s_tmsi.mme_code = 0; + S1AP_PAGING_IND(message_p).ue_paging_identity.choice.s_tmsi.m_tmsi = 0; + } else { + return -1; + } + /* id-UEPagingID */ + S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_PagingIEs_t, ie, container, + S1AP_ProtocolIE_ID_id_UEPagingID, true); + if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ + /* convert UE Paging Identity */ + if (ie->value.choice.UEPagingID.present == S1AP_UEPagingID_PR_s_TMSI) { + S1AP_PAGING_IND(message_p).ue_paging_identity.presenceMask = UE_PAGING_IDENTITY_s_tmsi; + OCTET_STRING_TO_INT8(&ie->value.choice.UEPagingID.choice.s_TMSI.mMEC, S1AP_PAGING_IND(message_p).ue_paging_identity.choice.s_tmsi.mme_code); + OCTET_STRING_TO_INT32(&ie->value.choice.UEPagingID.choice.s_TMSI.m_TMSI, S1AP_PAGING_IND(message_p).ue_paging_identity.choice.s_tmsi.m_tmsi); + } else if (ie->value.choice.UEPagingID.present == S1AP_UEPagingID_PR_iMSI) { + S1AP_PAGING_IND(message_p).ue_paging_identity.presenceMask = UE_PAGING_IDENTITY_imsi; + S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.length = 0; + + for (int i = 0; i < ie->value.choice.UEPagingID.choice.iMSI.size; i++) { + S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.buffer[2*i] = (uint8_t)(ie->value.choice.UEPagingID.choice.iMSI.buf[i] & 0x0F ); + S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.length++; + S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.buffer[2*i+1] = (uint8_t)((ie->value.choice.UEPagingID.choice.iMSI.buf[i]>>4) & 0x0F); + LOG_D(S1AP,"paging : i %d %d imsi %d %d \n",2*i,2*i+1,S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.buffer[2*i], S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.buffer[2*i+1]); + + if (S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.buffer[2*i+1] == 0x0F) { + if(i != ie->value.choice.UEPagingID.choice.iMSI.size - 1) { + /* invalid paging_p->uePagingID.choise.iMSI.buffer */ + S1AP_ERROR("[SCTP %d] Received Paging : uePagingID.choise.iMSI error(i %d 0x0F)\n", assoc_id,i); + return -1; + } + } else { + S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.length++; + } + } /* for i... */ + + if (S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.length >= S1AP_IMSI_LENGTH) { + /* invalid paging_p->uePagingID.choise.iMSI.size */ + S1AP_ERROR("[SCTP %d] Received Paging : uePagingID.choise.iMSI.size(%d) is over IMSI length(%d)\n", assoc_id, S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.length, S1AP_IMSI_LENGTH); + return -1; + } + } else { /* of if (ie->value.choice.UEPagingID.present == S1AP_UEPagingID_PR_iMSI) */ + /* invalid paging_p->uePagingID.present */ + S1AP_ERROR("[SCTP %d] Received Paging : uePagingID.present(%d) is unknown\n", assoc_id, ie->value.choice.UEPagingID.present); + return -1; + } + } else { /* of ie != NULL */ + return -1; + } + S1AP_PAGING_IND(message_p).paging_drx = PAGING_DRX_256; - } - - /* */ - S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_PagingIEs_t, ie, container, - S1AP_ProtocolIE_ID_id_CNDomain, true); - - /* id-CNDomain : convert cnDomain */ - if (ie->value.choice.CNDomain == S1AP_CNDomain_ps) { - S1AP_PAGING_IND(message_p).cn_domain = CN_DOMAIN_PS; - } else if (ie->value.choice.CNDomain == S1AP_CNDomain_cs) { - S1AP_PAGING_IND(message_p).cn_domain = CN_DOMAIN_CS; - } else { - /* invalid paging_p->cnDomain */ - S1AP_ERROR("[SCTP %d] Received Paging : cnDomain(%ld) is unknown\n", assoc_id, ie->value.choice.CNDomain); - return -1; - } - - memset (&S1AP_PAGING_IND(message_p).plmn_identity[0], 0, sizeof(plmn_identity_t)*256); - memset (&S1AP_PAGING_IND(message_p).tac[0], 0, sizeof(int16_t)*256); - S1AP_PAGING_IND(message_p).tai_size = 0; - /* id-TAIList */ - S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_PagingIEs_t, ie, container, - S1AP_ProtocolIE_ID_id_TAIList, true); - S1AP_INFO("[SCTP %d] Received Paging taiList: count %d\n", assoc_id, ie->value.choice.TAIList.list.count); - - for (int i = 0; i < ie->value.choice.TAIList.list.count; i++) { - S1AP_TAIItem_t *item_p; - item_p = &(((S1AP_TAIItemIEs_t *)ie->value.choice.TAIList.list.array[i])->value.choice.TAIItem); - TBCD_TO_MCC_MNC(&(item_p->tAI.pLMNidentity), S1AP_PAGING_IND(message_p).plmn_identity[i].mcc, - S1AP_PAGING_IND(message_p).plmn_identity[i].mnc, - S1AP_PAGING_IND(message_p).plmn_identity[i].mnc_digit_length); - OCTET_STRING_TO_INT16(&(item_p->tAI.tAC), S1AP_PAGING_IND(message_p).tac[i]); - S1AP_PAGING_IND(message_p).tai_size++; - S1AP_DEBUG("[SCTP %d] Received Paging: MCC %d, MNC %d, TAC %d\n", assoc_id, - S1AP_PAGING_IND(message_p).plmn_identity[i].mcc, - S1AP_PAGING_IND(message_p).plmn_identity[i].mnc, - S1AP_PAGING_IND(message_p).tac[i]); - } - - //paging parameter values - S1AP_DEBUG("[SCTP %d] Received Paging parameters: ue_index_value %d cn_domain %d paging_drx %d paging_priority %d\n",assoc_id, - S1AP_PAGING_IND(message_p).ue_index_value, S1AP_PAGING_IND(message_p).cn_domain, - S1AP_PAGING_IND(message_p).paging_drx, S1AP_PAGING_IND(message_p).paging_priority); - S1AP_DEBUG("[SCTP %d] Received Paging parameters(ue): presenceMask %d s_tmsi.m_tmsi %d s_tmsi.mme_code %d IMSI length %d (0-5) %d%d%d%d%d%d\n",assoc_id, - S1AP_PAGING_IND(message_p).ue_paging_identity.presenceMask, S1AP_PAGING_IND(message_p).ue_paging_identity.choice.s_tmsi.m_tmsi, - S1AP_PAGING_IND(message_p).ue_paging_identity.choice.s_tmsi.mme_code, S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.length, - S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.buffer[0], S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.buffer[1], - S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.buffer[2], S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.buffer[3], - S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.buffer[4], S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.buffer[5]); - /* send message to RRC */ - itti_send_msg_to_task(TASK_RRC_ENB, s1ap_eNB_instance->instance, message_p); - return 0; + /* id-pagingDRX */ + S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_PagingIEs_t, ie, container, + S1AP_ProtocolIE_ID_id_pagingDRX, false); + + /* optional */ + if (ie) { + S1AP_PAGING_IND(message_p).paging_drx = ie->value.choice.PagingDRX; + } else { + S1AP_PAGING_IND(message_p).paging_drx = PAGING_DRX_256; + } + + /* */ + S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_PagingIEs_t, ie, container, + S1AP_ProtocolIE_ID_id_CNDomain, true); + if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ + /* id-CNDomain : convert cnDomain */ + if (ie->value.choice.CNDomain == S1AP_CNDomain_ps) { + S1AP_PAGING_IND(message_p).cn_domain = CN_DOMAIN_PS; + } else if (ie->value.choice.CNDomain == S1AP_CNDomain_cs) { + S1AP_PAGING_IND(message_p).cn_domain = CN_DOMAIN_CS; + } else { + /* invalid paging_p->cnDomain */ + S1AP_ERROR("[SCTP %d] Received Paging : cnDomain(%ld) is unknown\n", assoc_id, ie->value.choice.CNDomain); + return -1; + } + } else { + return -1; + } + memset (&S1AP_PAGING_IND(message_p).plmn_identity[0], 0, sizeof(plmn_identity_t)*256); + memset (&S1AP_PAGING_IND(message_p).tac[0], 0, sizeof(int16_t)*256); + S1AP_PAGING_IND(message_p).tai_size = 0; + /* id-TAIList */ + S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_PagingIEs_t, ie, container, + S1AP_ProtocolIE_ID_id_TAIList, true); + if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ + S1AP_INFO("[SCTP %d] Received Paging taiList: count %d\n", assoc_id, ie->value.choice.TAIList.list.count); + for (int i = 0; i < ie->value.choice.TAIList.list.count; i++) { + S1AP_TAIItem_t *item_p; + item_p = &(((S1AP_TAIItemIEs_t *)ie->value.choice.TAIList.list.array[i])->value.choice.TAIItem); + TBCD_TO_MCC_MNC(&(item_p->tAI.pLMNidentity), S1AP_PAGING_IND(message_p).plmn_identity[i].mcc, + S1AP_PAGING_IND(message_p).plmn_identity[i].mnc, + S1AP_PAGING_IND(message_p).plmn_identity[i].mnc_digit_length); + OCTET_STRING_TO_INT16(&(item_p->tAI.tAC), S1AP_PAGING_IND(message_p).tac[i]); + S1AP_PAGING_IND(message_p).tai_size++; + S1AP_DEBUG("[SCTP %d] Received Paging: MCC %d, MNC %d, TAC %d\n", assoc_id, + S1AP_PAGING_IND(message_p).plmn_identity[i].mcc, + S1AP_PAGING_IND(message_p).plmn_identity[i].mnc, + S1AP_PAGING_IND(message_p).tac[i]); + } + } else { + return -1; + } + + //paging parameter values + S1AP_DEBUG("[SCTP %d] Received Paging parameters: ue_index_value %d cn_domain %d paging_drx %d paging_priority %d\n",assoc_id, + S1AP_PAGING_IND(message_p).ue_index_value, S1AP_PAGING_IND(message_p).cn_domain, + S1AP_PAGING_IND(message_p).paging_drx, S1AP_PAGING_IND(message_p).paging_priority); + S1AP_DEBUG("[SCTP %d] Received Paging parameters(ue): presenceMask %d s_tmsi.m_tmsi %d s_tmsi.mme_code %d IMSI length %d (0-5) %d%d%d%d%d%d\n",assoc_id, + S1AP_PAGING_IND(message_p).ue_paging_identity.presenceMask, S1AP_PAGING_IND(message_p).ue_paging_identity.choice.s_tmsi.m_tmsi, + S1AP_PAGING_IND(message_p).ue_paging_identity.choice.s_tmsi.mme_code, S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.length, + S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.buffer[0], S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.buffer[1], + S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.buffer[2], S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.buffer[3], + S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.buffer[4], S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.buffer[5]); + /* send message to RRC */ + itti_send_msg_to_task(TASK_RRC_ENB, s1ap_eNB_instance->instance, message_p); + return 0; } static int s1ap_eNB_handle_e_rab_modify_request(uint32_t assoc_id, - uint32_t stream, - S1AP_S1AP_PDU_t *pdu) { - int i, nb_of_e_rabs_failed; - s1ap_eNB_mme_data_t *mme_desc_p = NULL; - s1ap_eNB_ue_context_t *ue_desc_p = NULL; - MessageDef *message_p = NULL; - S1AP_E_RABModifyRequest_t *container; - S1AP_E_RABModifyRequestIEs_t *ie; - S1AP_ENB_UE_S1AP_ID_t enb_ue_s1ap_id; - S1AP_MME_UE_S1AP_ID_t mme_ue_s1ap_id; - DevAssert(pdu != NULL); - container = &pdu->choice.initiatingMessage.value.choice.E_RABModifyRequest; - - if ((mme_desc_p = s1ap_eNB_get_MME(NULL, assoc_id, 0)) == NULL) { - S1AP_ERROR("[SCTP %d] Received E-RAB modify request for non " - "existing MME context\n", assoc_id); - return -1; - } - - /* id-MME-UE-S1AP-ID */ - S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_E_RABModifyRequestIEs_t, ie, container, - S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID, true); - mme_ue_s1ap_id = ie->value.choice.MME_UE_S1AP_ID; - /* id-eNB-UE-S1AP-ID */ - S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_E_RABModifyRequestIEs_t, ie, container, - S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID, true); - enb_ue_s1ap_id = ie->value.choice.ENB_UE_S1AP_ID; - - if ((ue_desc_p = s1ap_eNB_get_ue_context(mme_desc_p->s1ap_eNB_instance, - enb_ue_s1ap_id)) == NULL) { - S1AP_ERROR("[SCTP %d] Received E-RAB modify request for non " - "existing UE context 0x%06lx\n", assoc_id, - enb_ue_s1ap_id); - return -1; - } - - /* E-RAB modify request = UE-related procedure -> stream != 0 */ - if (stream == 0) { - S1AP_ERROR("[SCTP %d] Received UE-related procedure on stream (%d)\n", - assoc_id, stream); - return -1; - } - - ue_desc_p->rx_stream = stream; - - if (ue_desc_p->mme_ue_s1ap_id != mme_ue_s1ap_id) { - S1AP_WARN("UE context mme_ue_s1ap_id is different form that of the message (%d != %ld)", - ue_desc_p->mme_ue_s1ap_id, mme_ue_s1ap_id); - message_p = itti_alloc_new_message (TASK_RRC_ENB, S1AP_E_RAB_MODIFY_RESP); - S1AP_E_RAB_MODIFY_RESP (message_p).eNB_ue_s1ap_id = enb_ue_s1ap_id; + uint32_t stream, + S1AP_S1AP_PDU_t *pdu) { + int i, nb_of_e_rabs_failed; + s1ap_eNB_mme_data_t *mme_desc_p = NULL; + s1ap_eNB_ue_context_t *ue_desc_p = NULL; + MessageDef *message_p = NULL; + S1AP_E_RABModifyRequest_t *container; + S1AP_E_RABModifyRequestIEs_t *ie; + S1AP_ENB_UE_S1AP_ID_t enb_ue_s1ap_id; + S1AP_MME_UE_S1AP_ID_t mme_ue_s1ap_id; + DevAssert(pdu != NULL); + container = &pdu->choice.initiatingMessage.value.choice.E_RABModifyRequest; + + if ((mme_desc_p = s1ap_eNB_get_MME(NULL, assoc_id, 0)) == NULL) { + S1AP_ERROR("[SCTP %d] Received E-RAB modify request for non " + "existing MME context\n", assoc_id); + return -1; + } + + /* id-MME-UE-S1AP-ID */ S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_E_RABModifyRequestIEs_t, ie, container, - S1AP_ProtocolIE_ID_id_E_RABToBeModifiedListBearerModReq, true); + S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID, true); + if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ + mme_ue_s1ap_id = ie->value.choice.MME_UE_S1AP_ID; + } else { + return -1; + } + /* id-eNB-UE-S1AP-ID */ + S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_E_RABModifyRequestIEs_t, ie, container, + S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID, true); + if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ + enb_ue_s1ap_id = ie->value.choice.ENB_UE_S1AP_ID; + } else { + return -1; + } + if ((ue_desc_p = s1ap_eNB_get_ue_context(mme_desc_p->s1ap_eNB_instance, + enb_ue_s1ap_id)) == NULL) { + S1AP_ERROR("[SCTP %d] Received E-RAB modify request for non " + "existing UE context 0x%06lx\n", assoc_id, + enb_ue_s1ap_id); + return -1; + } - for(nb_of_e_rabs_failed = 0; nb_of_e_rabs_failed < ie->value.choice.E_RABToBeModifiedListBearerModReq.list.count; nb_of_e_rabs_failed++) { - S1AP_E_RABToBeModifiedItemBearerModReq_t *item_p; - item_p = &(((S1AP_E_RABToBeModifiedItemBearerModReqIEs_t *) - ie->value.choice.E_RABToBeModifiedListBearerModReq.list.array[nb_of_e_rabs_failed])->value.choice.E_RABToBeModifiedItemBearerModReq); - S1AP_E_RAB_MODIFY_RESP(message_p).e_rabs_failed[nb_of_e_rabs_failed].e_rab_id = item_p->e_RAB_ID; - S1AP_E_RAB_MODIFY_RESP(message_p).e_rabs_failed[nb_of_e_rabs_failed].cause = S1AP_Cause_PR_radioNetwork; - S1AP_E_RAB_MODIFY_RESP(message_p).e_rabs_failed[nb_of_e_rabs_failed].cause_value = S1AP_CauseRadioNetwork_unknown_mme_ue_s1ap_id; + /* E-RAB modify request = UE-related procedure -> stream != 0 */ + if (stream == 0) { + S1AP_ERROR("[SCTP %d] Received UE-related procedure on stream (%d)\n", + assoc_id, stream); + return -1; } - S1AP_E_RAB_MODIFY_RESP(message_p).nb_of_e_rabs_failed = nb_of_e_rabs_failed; - s1ap_eNB_e_rab_modify_resp(mme_desc_p->s1ap_eNB_instance->instance, - &S1AP_E_RAB_MODIFY_RESP(message_p)); - message_p = NULL; - return -1; - } - - message_p = itti_alloc_new_message(TASK_S1AP, S1AP_E_RAB_MODIFY_REQ); - S1AP_E_RAB_MODIFY_REQ(message_p).ue_initial_id = ue_desc_p->ue_initial_id; - S1AP_E_RAB_MODIFY_REQ(message_p).mme_ue_s1ap_id = mme_ue_s1ap_id; - S1AP_E_RAB_MODIFY_REQ(message_p).eNB_ue_s1ap_id = enb_ue_s1ap_id; - /* id-E-RABToBeModifiedListBearerModReq */ - S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_E_RABModifyRequestIEs_t, ie, container, - S1AP_ProtocolIE_ID_id_E_RABToBeModifiedListBearerModReq, true); - S1AP_E_RAB_MODIFY_REQ(message_p).nb_e_rabs_tomodify = - ie->value.choice.E_RABToBeModifiedListBearerModReq.list.count; - - for (i = 0; i < ie->value.choice.E_RABToBeModifiedListBearerModReq.list.count; i++) { - S1AP_E_RABToBeModifiedItemBearerModReq_t *item_p; - item_p = &(((S1AP_E_RABToBeModifiedItemBearerModReqIEs_t *)ie->value.choice.E_RABToBeModifiedListBearerModReq.list.array[i])->value.choice.E_RABToBeModifiedItemBearerModReq); - S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].e_rab_id = item_p->e_RAB_ID; - - // check for the NAS PDU - if (item_p->nAS_PDU.size > 0 ) { - S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].nas_pdu.length = item_p->nAS_PDU.size; - S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].nas_pdu.buffer = malloc(sizeof(uint8_t) * item_p->nAS_PDU.size); - memcpy(S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].nas_pdu.buffer, - item_p->nAS_PDU.buf, item_p->nAS_PDU.size); - } else { - S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].nas_pdu.length = 0; - S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].nas_pdu.buffer = NULL; - continue; + ue_desc_p->rx_stream = stream; + + if (ue_desc_p->mme_ue_s1ap_id != mme_ue_s1ap_id) { + S1AP_WARN("UE context mme_ue_s1ap_id is different form that of the message (%d != %ld)", + ue_desc_p->mme_ue_s1ap_id, mme_ue_s1ap_id); + message_p = itti_alloc_new_message (TASK_RRC_ENB, S1AP_E_RAB_MODIFY_RESP); + S1AP_E_RAB_MODIFY_RESP (message_p).eNB_ue_s1ap_id = enb_ue_s1ap_id; + S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_E_RABModifyRequestIEs_t, ie, container, + S1AP_ProtocolIE_ID_id_E_RABToBeModifiedListBearerModReq, true); + if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ + for(nb_of_e_rabs_failed = 0; nb_of_e_rabs_failed < ie->value.choice.E_RABToBeModifiedListBearerModReq.list.count; nb_of_e_rabs_failed++) { + S1AP_E_RABToBeModifiedItemBearerModReq_t *item_p; + item_p = &(((S1AP_E_RABToBeModifiedItemBearerModReqIEs_t *) + ie->value.choice.E_RABToBeModifiedListBearerModReq.list.array[nb_of_e_rabs_failed])->value.choice.E_RABToBeModifiedItemBearerModReq); + S1AP_E_RAB_MODIFY_RESP(message_p).e_rabs_failed[nb_of_e_rabs_failed].e_rab_id = item_p->e_RAB_ID; + S1AP_E_RAB_MODIFY_RESP(message_p).e_rabs_failed[nb_of_e_rabs_failed].cause = S1AP_Cause_PR_radioNetwork; + S1AP_E_RAB_MODIFY_RESP(message_p).e_rabs_failed[nb_of_e_rabs_failed].cause_value = S1AP_CauseRadioNetwork_unknown_mme_ue_s1ap_id; + } + } else { + return -1; + } + S1AP_E_RAB_MODIFY_RESP(message_p).nb_of_e_rabs_failed = nb_of_e_rabs_failed; + s1ap_eNB_e_rab_modify_resp(mme_desc_p->s1ap_eNB_instance->instance, + &S1AP_E_RAB_MODIFY_RESP(message_p)); + message_p = NULL; + return -1; } - /* Set the QOS informations */ - S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].qos.qci = item_p->e_RABLevelQoSParameters.qCI; - S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].qos.allocation_retention_priority.priority_level = - item_p->e_RABLevelQoSParameters.allocationRetentionPriority.priorityLevel; - S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].qos.allocation_retention_priority.pre_emp_capability = - item_p->e_RABLevelQoSParameters.allocationRetentionPriority.pre_emptionCapability; - S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].qos.allocation_retention_priority.pre_emp_vulnerability = - item_p->e_RABLevelQoSParameters.allocationRetentionPriority.pre_emptionVulnerability; - } - - itti_send_msg_to_task(TASK_RRC_ENB, ue_desc_p->eNB_instance->instance, message_p); - return 0; + message_p = itti_alloc_new_message(TASK_S1AP, S1AP_E_RAB_MODIFY_REQ); + S1AP_E_RAB_MODIFY_REQ(message_p).ue_initial_id = ue_desc_p->ue_initial_id; + S1AP_E_RAB_MODIFY_REQ(message_p).mme_ue_s1ap_id = mme_ue_s1ap_id; + S1AP_E_RAB_MODIFY_REQ(message_p).eNB_ue_s1ap_id = enb_ue_s1ap_id; + /* id-E-RABToBeModifiedListBearerModReq */ + S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_E_RABModifyRequestIEs_t, ie, container, + S1AP_ProtocolIE_ID_id_E_RABToBeModifiedListBearerModReq, true); + if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ + S1AP_E_RAB_MODIFY_REQ(message_p).nb_e_rabs_tomodify = + ie->value.choice.E_RABToBeModifiedListBearerModReq.list.count; + + for (i = 0; i < ie->value.choice.E_RABToBeModifiedListBearerModReq.list.count; i++) { + S1AP_E_RABToBeModifiedItemBearerModReq_t *item_p; + item_p = &(((S1AP_E_RABToBeModifiedItemBearerModReqIEs_t *)ie->value.choice.E_RABToBeModifiedListBearerModReq.list.array[i])->value.choice.E_RABToBeModifiedItemBearerModReq); + S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].e_rab_id = item_p->e_RAB_ID; + + // check for the NAS PDU + if (item_p->nAS_PDU.size > 0 ) { + S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].nas_pdu.length = item_p->nAS_PDU.size; + S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].nas_pdu.buffer = malloc(sizeof(uint8_t) * item_p->nAS_PDU.size); + memcpy(S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].nas_pdu.buffer, + item_p->nAS_PDU.buf, item_p->nAS_PDU.size); + } else { + S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].nas_pdu.length = 0; + S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].nas_pdu.buffer = NULL; + continue; + } + + /* Set the QOS informations */ + S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].qos.qci = item_p->e_RABLevelQoSParameters.qCI; + S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].qos.allocation_retention_priority.priority_level = + item_p->e_RABLevelQoSParameters.allocationRetentionPriority.priorityLevel; + S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].qos.allocation_retention_priority.pre_emp_capability = + item_p->e_RABLevelQoSParameters.allocationRetentionPriority.pre_emptionCapability; + S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].qos.allocation_retention_priority.pre_emp_vulnerability = + item_p->e_RABLevelQoSParameters.allocationRetentionPriority.pre_emptionVulnerability; + } + + itti_send_msg_to_task(TASK_RRC_ENB, ue_desc_p->eNB_instance->instance, message_p); + } else { /* of if (ie != NULL)*/ + return -1; + } + return 0; } // handle e-rab release command and send it to rrc_end static int s1ap_eNB_handle_e_rab_release_command(uint32_t assoc_id, - uint32_t stream, - S1AP_S1AP_PDU_t *pdu) { - int i; - s1ap_eNB_mme_data_t *mme_desc_p = NULL; - s1ap_eNB_ue_context_t *ue_desc_p = NULL; - MessageDef *message_p = NULL; - S1AP_E_RABReleaseCommand_t *container; - S1AP_E_RABReleaseCommandIEs_t *ie; - S1AP_ENB_UE_S1AP_ID_t enb_ue_s1ap_id; - S1AP_MME_UE_S1AP_ID_t mme_ue_s1ap_id; - DevAssert(pdu != NULL); - container = &pdu->choice.initiatingMessage.value.choice.E_RABReleaseCommand; - - if ((mme_desc_p = s1ap_eNB_get_MME(NULL, assoc_id, 0)) == NULL) { - S1AP_ERROR("[SCTP %d] Received E-RAB release command for non existing MME context\n", assoc_id); - return -1; - } - - /* id-MME-UE-S1AP-ID */ - S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_E_RABReleaseCommandIEs_t, ie, container, - S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID, true); - mme_ue_s1ap_id = ie->value.choice.MME_UE_S1AP_ID; - /* id-eNB-UE-S1AP-ID */ - S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_E_RABReleaseCommandIEs_t, ie, container, - S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID, true); - enb_ue_s1ap_id = ie->value.choice.ENB_UE_S1AP_ID; - - if ((ue_desc_p = s1ap_eNB_get_ue_context(mme_desc_p->s1ap_eNB_instance, - enb_ue_s1ap_id)) == NULL) { - S1AP_ERROR("[SCTP %d] Received E-RAB release command for non existing UE context 0x%06lx\n", assoc_id, - ie->value.choice.ENB_UE_S1AP_ID); - return -1; - } - - /* Initial context request = UE-related procedure -> stream != 0 */ - if (stream == 0) { - S1AP_ERROR("[SCTP %d] Received UE-related procedure on stream (%d)\n", - assoc_id, stream); - return -1; - } - - ue_desc_p->rx_stream = stream; - - if (ue_desc_p->mme_ue_s1ap_id != mme_ue_s1ap_id) { - S1AP_WARN("UE context mme_ue_s1ap_id is different form that of the message (%d != %ld)", - ue_desc_p->mme_ue_s1ap_id, mme_ue_s1ap_id); - } - - S1AP_DEBUG("[SCTP %d] Received E-RAB release command for eNB_UE_S1AP_ID %ld mme_ue_s1ap_id %ld\n", - assoc_id, enb_ue_s1ap_id, mme_ue_s1ap_id); - message_p = itti_alloc_new_message(TASK_S1AP, S1AP_E_RAB_RELEASE_COMMAND); - S1AP_E_RAB_RELEASE_COMMAND(message_p).eNB_ue_s1ap_id = enb_ue_s1ap_id; - S1AP_E_RAB_RELEASE_COMMAND(message_p).mme_ue_s1ap_id = mme_ue_s1ap_id; - /* id-NAS-PDU */ - S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_E_RABReleaseCommandIEs_t, ie, container, - S1AP_ProtocolIE_ID_id_NAS_PDU, false); - - if(ie && ie->value.choice.NAS_PDU.size > 0) { - S1AP_E_RAB_RELEASE_COMMAND(message_p).nas_pdu.length = ie->value.choice.NAS_PDU.size; - S1AP_E_RAB_RELEASE_COMMAND(message_p).nas_pdu.buffer = - malloc(sizeof(uint8_t) * ie->value.choice.NAS_PDU.size); - memcpy(S1AP_E_RAB_RELEASE_COMMAND(message_p).nas_pdu.buffer, - ie->value.choice.NAS_PDU.buf, - ie->value.choice.NAS_PDU.size); - } else { - S1AP_E_RAB_RELEASE_COMMAND(message_p).nas_pdu.length = 0; - S1AP_E_RAB_RELEASE_COMMAND(message_p).nas_pdu.buffer = NULL; - } - - /* id-E-RABToBeReleasedList */ - S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_E_RABReleaseCommandIEs_t, ie, container, - S1AP_ProtocolIE_ID_id_E_RABToBeReleasedList, true); - S1AP_E_RAB_RELEASE_COMMAND(message_p).nb_e_rabs_torelease = ie->value.choice.E_RABList.list.count; - - for (i = 0; i < ie->value.choice.E_RABList.list.count; i++) { - S1AP_E_RABItem_t *item_p; - item_p = &(((S1AP_E_RABItemIEs_t *)ie->value.choice.E_RABList.list.array[i])->value.choice.E_RABItem); - S1AP_E_RAB_RELEASE_COMMAND(message_p).e_rab_release_params[i].e_rab_id = item_p->e_RAB_ID; - S1AP_DEBUG("[SCTP] Received E-RAB release command for e-rab id %ld\n", item_p->e_RAB_ID); - } - - itti_send_msg_to_task(TASK_RRC_ENB, ue_desc_p->eNB_instance->instance, message_p); - return 0; + uint32_t stream, + S1AP_S1AP_PDU_t *pdu) { + int i; + s1ap_eNB_mme_data_t *mme_desc_p = NULL; + s1ap_eNB_ue_context_t *ue_desc_p = NULL; + MessageDef *message_p = NULL; + S1AP_E_RABReleaseCommand_t *container; + S1AP_E_RABReleaseCommandIEs_t *ie; + S1AP_ENB_UE_S1AP_ID_t enb_ue_s1ap_id; + S1AP_MME_UE_S1AP_ID_t mme_ue_s1ap_id; + DevAssert(pdu != NULL); + container = &pdu->choice.initiatingMessage.value.choice.E_RABReleaseCommand; + + if ((mme_desc_p = s1ap_eNB_get_MME(NULL, assoc_id, 0)) == NULL) { + S1AP_ERROR("[SCTP %d] Received E-RAB release command for non existing MME context\n", assoc_id); + return -1; + } + + /* id-MME-UE-S1AP-ID */ + S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_E_RABReleaseCommandIEs_t, ie, container, + S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID, true); + if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ + mme_ue_s1ap_id = ie->value.choice.MME_UE_S1AP_ID; + } else { + return -1; + } + /* id-eNB-UE-S1AP-ID */ + S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_E_RABReleaseCommandIEs_t, ie, container, + S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID, true); + if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ + enb_ue_s1ap_id = ie->value.choice.ENB_UE_S1AP_ID; + } else { + return -1; + } + if ((ue_desc_p = s1ap_eNB_get_ue_context(mme_desc_p->s1ap_eNB_instance, + enb_ue_s1ap_id)) == NULL) { + S1AP_ERROR("[SCTP %d] Received E-RAB release command for non existing UE context 0x%06lx\n", assoc_id, + ie->value.choice.ENB_UE_S1AP_ID); + return -1; + } + + /* Initial context request = UE-related procedure -> stream != 0 */ + if (stream == 0) { + S1AP_ERROR("[SCTP %d] Received UE-related procedure on stream (%d)\n", + assoc_id, stream); + return -1; + } + + ue_desc_p->rx_stream = stream; + + if (ue_desc_p->mme_ue_s1ap_id != mme_ue_s1ap_id) { + S1AP_WARN("UE context mme_ue_s1ap_id is different form that of the message (%d != %ld)", + ue_desc_p->mme_ue_s1ap_id, mme_ue_s1ap_id); + } + + S1AP_DEBUG("[SCTP %d] Received E-RAB release command for eNB_UE_S1AP_ID %ld mme_ue_s1ap_id %ld\n", + assoc_id, enb_ue_s1ap_id, mme_ue_s1ap_id); + message_p = itti_alloc_new_message(TASK_S1AP, S1AP_E_RAB_RELEASE_COMMAND); + S1AP_E_RAB_RELEASE_COMMAND(message_p).eNB_ue_s1ap_id = enb_ue_s1ap_id; + S1AP_E_RAB_RELEASE_COMMAND(message_p).mme_ue_s1ap_id = mme_ue_s1ap_id; + /* id-NAS-PDU */ + S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_E_RABReleaseCommandIEs_t, ie, container, + S1AP_ProtocolIE_ID_id_NAS_PDU, false); + + if(ie && ie->value.choice.NAS_PDU.size > 0) { + S1AP_E_RAB_RELEASE_COMMAND(message_p).nas_pdu.length = ie->value.choice.NAS_PDU.size; + S1AP_E_RAB_RELEASE_COMMAND(message_p).nas_pdu.buffer = + malloc(sizeof(uint8_t) * ie->value.choice.NAS_PDU.size); + memcpy(S1AP_E_RAB_RELEASE_COMMAND(message_p).nas_pdu.buffer, + ie->value.choice.NAS_PDU.buf, + ie->value.choice.NAS_PDU.size); + } else { + S1AP_E_RAB_RELEASE_COMMAND(message_p).nas_pdu.length = 0; + S1AP_E_RAB_RELEASE_COMMAND(message_p).nas_pdu.buffer = NULL; + } + + /* id-E-RABToBeReleasedList */ + S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_E_RABReleaseCommandIEs_t, ie, container, + S1AP_ProtocolIE_ID_id_E_RABToBeReleasedList, true); + if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ + S1AP_E_RAB_RELEASE_COMMAND(message_p).nb_e_rabs_torelease = ie->value.choice.E_RABList.list.count; + + for (i = 0; i < ie->value.choice.E_RABList.list.count; i++) { + S1AP_E_RABItem_t *item_p; + item_p = &(((S1AP_E_RABItemIEs_t *)ie->value.choice.E_RABList.list.array[i])->value.choice.E_RABItem); + S1AP_E_RAB_RELEASE_COMMAND(message_p).e_rab_release_params[i].e_rab_id = item_p->e_RAB_ID; + S1AP_DEBUG("[SCTP] Received E-RAB release command for e-rab id %ld\n", item_p->e_RAB_ID); + } + } else { + return -1; + } + itti_send_msg_to_task(TASK_RRC_ENB, ue_desc_p->eNB_instance->instance, message_p); + return 0; } diff --git a/openair3/S1AP/s1ap_eNB_nas_procedures.c b/openair3/S1AP/s1ap_eNB_nas_procedures.c index 2189140dad0213e506d46b86ab26fcb488fd0714..d1ef83dca641c205fbcc92201ec743a930fe1aaf 100644 --- a/openair3/S1AP/s1ap_eNB_nas_procedures.c +++ b/openair3/S1AP/s1ap_eNB_nas_procedures.c @@ -50,376 +50,376 @@ //------------------------------------------------------------------------------ int s1ap_eNB_handle_nas_first_req( - instance_t instance, s1ap_nas_first_req_t *s1ap_nas_first_req_p) + instance_t instance, s1ap_nas_first_req_t *s1ap_nas_first_req_p) //------------------------------------------------------------------------------ { - s1ap_eNB_instance_t *instance_p = NULL; - struct s1ap_eNB_mme_data_s *mme_desc_p = NULL; - struct s1ap_eNB_ue_context_s *ue_desc_p = NULL; - S1AP_S1AP_PDU_t pdu; - S1AP_InitialUEMessage_t *out; - S1AP_InitialUEMessage_IEs_t *ie; - uint8_t *buffer = NULL; - uint32_t length = 0; - DevAssert(s1ap_nas_first_req_p != NULL); - /* Retrieve the S1AP eNB instance associated with Mod_id */ - instance_p = s1ap_eNB_get_instance(instance); - DevAssert(instance_p != NULL); - memset(&pdu, 0, sizeof(pdu)); - pdu.present = S1AP_S1AP_PDU_PR_initiatingMessage; - pdu.choice.initiatingMessage.procedureCode = S1AP_ProcedureCode_id_initialUEMessage; - pdu.choice.initiatingMessage.criticality = S1AP_Criticality_ignore; - pdu.choice.initiatingMessage.value.present = S1AP_InitiatingMessage__value_PR_InitialUEMessage; - out = &pdu.choice.initiatingMessage.value.choice.InitialUEMessage; - - /* Select the MME corresponding to the provided GUMMEI. */ - if (s1ap_nas_first_req_p->ue_identity.presenceMask & UE_IDENTITIES_gummei) { - mme_desc_p = s1ap_eNB_nnsf_select_mme_by_gummei( - instance_p, - s1ap_nas_first_req_p->establishment_cause, - s1ap_nas_first_req_p->ue_identity.gummei); - - if (mme_desc_p) { - S1AP_INFO("[eNB %d] Chose MME '%s' (assoc_id %d) through GUMMEI MCC %d MNC %d MMEGI %d MMEC %d\n", - instance, - mme_desc_p->mme_name, - mme_desc_p->assoc_id, - s1ap_nas_first_req_p->ue_identity.gummei.mcc, - s1ap_nas_first_req_p->ue_identity.gummei.mnc, - s1ap_nas_first_req_p->ue_identity.gummei.mme_group_id, - s1ap_nas_first_req_p->ue_identity.gummei.mme_code); - } - } - - if (mme_desc_p == NULL) { - /* Select the MME corresponding to the provided s-TMSI. */ - if (s1ap_nas_first_req_p->ue_identity.presenceMask & UE_IDENTITIES_s_tmsi) { - mme_desc_p = s1ap_eNB_nnsf_select_mme_by_mme_code( - instance_p, - s1ap_nas_first_req_p->establishment_cause, - s1ap_nas_first_req_p->selected_plmn_identity, - s1ap_nas_first_req_p->ue_identity.s_tmsi.mme_code); - - if (mme_desc_p) { - S1AP_INFO("[eNB %d] Chose MME '%s' (assoc_id %d) through S-TMSI MMEC %d and selected PLMN Identity index %d MCC %d MNC %d\n", - instance, - mme_desc_p->mme_name, - mme_desc_p->assoc_id, - s1ap_nas_first_req_p->ue_identity.s_tmsi.mme_code, - s1ap_nas_first_req_p->selected_plmn_identity, - instance_p->mcc[s1ap_nas_first_req_p->selected_plmn_identity], - instance_p->mnc[s1ap_nas_first_req_p->selected_plmn_identity]); - } - } - } - - if (mme_desc_p == NULL) { - /* Select MME based on the selected PLMN identity, received through RRC - * Connection Setup Complete */ - mme_desc_p = s1ap_eNB_nnsf_select_mme_by_plmn_id( - instance_p, - s1ap_nas_first_req_p->establishment_cause, - s1ap_nas_first_req_p->selected_plmn_identity); - - if (mme_desc_p) { - S1AP_INFO("[eNB %d] Chose MME '%s' (assoc_id %d) through selected PLMN Identity index %d MCC %d MNC %d\n", - instance, - mme_desc_p->mme_name, - mme_desc_p->assoc_id, - s1ap_nas_first_req_p->selected_plmn_identity, - instance_p->mcc[s1ap_nas_first_req_p->selected_plmn_identity], - instance_p->mnc[s1ap_nas_first_req_p->selected_plmn_identity]); - } - } - - if (mme_desc_p == NULL) { - /* - * If no MME corresponds to the GUMMEI, the s-TMSI, or the selected PLMN - * identity, selects the MME with the highest capacity. - */ - mme_desc_p = s1ap_eNB_nnsf_select_mme( - instance_p, - s1ap_nas_first_req_p->establishment_cause); - - if (mme_desc_p) { - S1AP_INFO("[eNB %d] Chose MME '%s' (assoc_id %d) through highest relative capacity\n", - instance, - mme_desc_p->mme_name, - mme_desc_p->assoc_id); - } - } - - if (mme_desc_p == NULL) { - /* - * In case eNB has no MME associated, the eNB should inform RRC and discard - * this request. + s1ap_eNB_instance_t *instance_p = NULL; + struct s1ap_eNB_mme_data_s *mme_desc_p = NULL; + struct s1ap_eNB_ue_context_s *ue_desc_p = NULL; + S1AP_S1AP_PDU_t pdu; + S1AP_InitialUEMessage_t *out; + S1AP_InitialUEMessage_IEs_t *ie; + uint8_t *buffer = NULL; + uint32_t length = 0; + DevAssert(s1ap_nas_first_req_p != NULL); + /* Retrieve the S1AP eNB instance associated with Mod_id */ + instance_p = s1ap_eNB_get_instance(instance); + DevAssert(instance_p != NULL); + memset(&pdu, 0, sizeof(pdu)); + pdu.present = S1AP_S1AP_PDU_PR_initiatingMessage; + pdu.choice.initiatingMessage.procedureCode = S1AP_ProcedureCode_id_initialUEMessage; + pdu.choice.initiatingMessage.criticality = S1AP_Criticality_ignore; + pdu.choice.initiatingMessage.value.present = S1AP_InitiatingMessage__value_PR_InitialUEMessage; + out = &pdu.choice.initiatingMessage.value.choice.InitialUEMessage; + + /* Select the MME corresponding to the provided GUMMEI. */ + if (s1ap_nas_first_req_p->ue_identity.presenceMask & UE_IDENTITIES_gummei) { + mme_desc_p = s1ap_eNB_nnsf_select_mme_by_gummei( + instance_p, + s1ap_nas_first_req_p->establishment_cause, + s1ap_nas_first_req_p->ue_identity.gummei); + + if (mme_desc_p) { + S1AP_INFO("[eNB %d] Chose MME '%s' (assoc_id %d) through GUMMEI MCC %d MNC %d MMEGI %d MMEC %d\n", + instance, + mme_desc_p->mme_name, + mme_desc_p->assoc_id, + s1ap_nas_first_req_p->ue_identity.gummei.mcc, + s1ap_nas_first_req_p->ue_identity.gummei.mnc, + s1ap_nas_first_req_p->ue_identity.gummei.mme_group_id, + s1ap_nas_first_req_p->ue_identity.gummei.mme_code); + } + } + + if (mme_desc_p == NULL) { + /* Select the MME corresponding to the provided s-TMSI. */ + if (s1ap_nas_first_req_p->ue_identity.presenceMask & UE_IDENTITIES_s_tmsi) { + mme_desc_p = s1ap_eNB_nnsf_select_mme_by_mme_code( + instance_p, + s1ap_nas_first_req_p->establishment_cause, + s1ap_nas_first_req_p->selected_plmn_identity, + s1ap_nas_first_req_p->ue_identity.s_tmsi.mme_code); + + if (mme_desc_p) { + S1AP_INFO("[eNB %d] Chose MME '%s' (assoc_id %d) through S-TMSI MMEC %d and selected PLMN Identity index %d MCC %d MNC %d\n", + instance, + mme_desc_p->mme_name, + mme_desc_p->assoc_id, + s1ap_nas_first_req_p->ue_identity.s_tmsi.mme_code, + s1ap_nas_first_req_p->selected_plmn_identity, + instance_p->mcc[s1ap_nas_first_req_p->selected_plmn_identity], + instance_p->mnc[s1ap_nas_first_req_p->selected_plmn_identity]); + } + } + } + + if (mme_desc_p == NULL) { + /* Select MME based on the selected PLMN identity, received through RRC + * Connection Setup Complete */ + mme_desc_p = s1ap_eNB_nnsf_select_mme_by_plmn_id( + instance_p, + s1ap_nas_first_req_p->establishment_cause, + s1ap_nas_first_req_p->selected_plmn_identity); + + if (mme_desc_p) { + S1AP_INFO("[eNB %d] Chose MME '%s' (assoc_id %d) through selected PLMN Identity index %d MCC %d MNC %d\n", + instance, + mme_desc_p->mme_name, + mme_desc_p->assoc_id, + s1ap_nas_first_req_p->selected_plmn_identity, + instance_p->mcc[s1ap_nas_first_req_p->selected_plmn_identity], + instance_p->mnc[s1ap_nas_first_req_p->selected_plmn_identity]); + } + } + + if (mme_desc_p == NULL) { + /* + * If no MME corresponds to the GUMMEI, the s-TMSI, or the selected PLMN + * identity, selects the MME with the highest capacity. + */ + mme_desc_p = s1ap_eNB_nnsf_select_mme( + instance_p, + s1ap_nas_first_req_p->establishment_cause); + + if (mme_desc_p) { + S1AP_INFO("[eNB %d] Chose MME '%s' (assoc_id %d) through highest relative capacity\n", + instance, + mme_desc_p->mme_name, + mme_desc_p->assoc_id); + } + } + + if (mme_desc_p == NULL) { + /* + * In case eNB has no MME associated, the eNB should inform RRC and discard + * this request. + */ + S1AP_WARN("No MME is associated to the eNB\n"); + // TODO: Inform RRC + return -1; + } + + /* The eNB should allocate a unique eNB UE S1AP ID for this UE. The value + * will be used for the duration of the connectivity. */ - S1AP_WARN("No MME is associated to the eNB\n"); - // TODO: Inform RRC - return -1; - } - - /* The eNB should allocate a unique eNB UE S1AP ID for this UE. The value - * will be used for the duration of the connectivity. - */ - ue_desc_p = s1ap_eNB_allocate_new_UE_context(); - DevAssert(ue_desc_p != NULL); - /* Keep a reference to the selected MME */ - ue_desc_p->mme_ref = mme_desc_p; - ue_desc_p->ue_initial_id = s1ap_nas_first_req_p->ue_initial_id; - ue_desc_p->eNB_instance = instance_p; - ue_desc_p->selected_plmn_identity = s1ap_nas_first_req_p->selected_plmn_identity; - - do { - struct s1ap_eNB_ue_context_s *collision_p; - /* Peek a random value for the eNB_ue_s1ap_id */ - ue_desc_p->eNB_ue_s1ap_id = (random() + random()) & 0x00ffffff; - - if ((collision_p = RB_INSERT(s1ap_ue_map, &instance_p->s1ap_ue_head, ue_desc_p)) - == NULL) { - S1AP_DEBUG("Found usable eNB_ue_s1ap_id: 0x%06x %d(10)\n", - ue_desc_p->eNB_ue_s1ap_id, - ue_desc_p->eNB_ue_s1ap_id); - /* Break the loop as the id is not already used by another UE */ - break; - } - } while(1); - - /* mandatory */ - ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; - ie->criticality = S1AP_Criticality_reject; - ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_ENB_UE_S1AP_ID; - ie->value.choice.ENB_UE_S1AP_ID = ue_desc_p->eNB_ue_s1ap_id; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - /* mandatory */ - ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_NAS_PDU; - ie->criticality = S1AP_Criticality_reject; - ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_NAS_PDU; + ue_desc_p = s1ap_eNB_allocate_new_UE_context(); + DevAssert(ue_desc_p != NULL); + /* Keep a reference to the selected MME */ + ue_desc_p->mme_ref = mme_desc_p; + ue_desc_p->ue_initial_id = s1ap_nas_first_req_p->ue_initial_id; + ue_desc_p->eNB_instance = instance_p; + ue_desc_p->selected_plmn_identity = s1ap_nas_first_req_p->selected_plmn_identity; + + do { + struct s1ap_eNB_ue_context_s *collision_p; + /* Peek a random value for the eNB_ue_s1ap_id */ + ue_desc_p->eNB_ue_s1ap_id = (random() + random()) & 0x00ffffff; + + if ((collision_p = RB_INSERT(s1ap_ue_map, &instance_p->s1ap_ue_head, ue_desc_p)) + == NULL) { + S1AP_DEBUG("Found usable eNB_ue_s1ap_id: 0x%06x %u(10)\n", + ue_desc_p->eNB_ue_s1ap_id, + ue_desc_p->eNB_ue_s1ap_id); + /* Break the loop as the id is not already used by another UE */ + break; + } + } while(1); + + /* mandatory */ + ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_ENB_UE_S1AP_ID; + ie->value.choice.ENB_UE_S1AP_ID = ue_desc_p->eNB_ue_s1ap_id; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + /* mandatory */ + ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_NAS_PDU; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_NAS_PDU; #if 1 - ie->value.choice.NAS_PDU.buf = s1ap_nas_first_req_p->nas_pdu.buffer; + ie->value.choice.NAS_PDU.buf = s1ap_nas_first_req_p->nas_pdu.buffer; #else - ie->value.choice.NAS_PDU.buf = malloc(s1ap_nas_first_req_p->nas_pdu.length); - memcpy(ie->value.choice.NAS_PDU.buf, - s1ap_nas_first_req_p->nas_pdu.buffer, - s1ap_nas_first_req_p->nas_pdu.length); + ie->value.choice.NAS_PDU.buf = malloc(s1ap_nas_first_req_p->nas_pdu.length); + memcpy(ie->value.choice.NAS_PDU.buf, + s1ap_nas_first_req_p->nas_pdu.buffer, + s1ap_nas_first_req_p->nas_pdu.length); #endif - ie->value.choice.NAS_PDU.size = s1ap_nas_first_req_p->nas_pdu.length; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - /* mandatory */ - ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_TAI; - ie->criticality = S1AP_Criticality_reject; - ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_TAI; - /* Assuming TAI is the TAI from the cell */ - INT16_TO_OCTET_STRING(instance_p->tac, &ie->value.choice.TAI.tAC); - MCC_MNC_TO_PLMNID(instance_p->mcc[ue_desc_p->selected_plmn_identity], - instance_p->mnc[ue_desc_p->selected_plmn_identity], - instance_p->mnc_digit_length[ue_desc_p->selected_plmn_identity], - &ie->value.choice.TAI.pLMNidentity); - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - /* mandatory */ - ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_EUTRAN_CGI; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_EUTRAN_CGI; - /* Set the EUTRAN CGI - * The cell identity is defined on 28 bits but as we use macro enb id, - * we have to pad. - */ - //#warning "TODO get cell id from RRC" - MACRO_ENB_ID_TO_CELL_IDENTITY(instance_p->eNB_id, - 0, // Cell ID - &ie->value.choice.EUTRAN_CGI.cell_ID); - MCC_MNC_TO_TBCD(instance_p->mcc[ue_desc_p->selected_plmn_identity], - instance_p->mnc[ue_desc_p->selected_plmn_identity], - instance_p->mnc_digit_length[ue_desc_p->selected_plmn_identity], - &ie->value.choice.EUTRAN_CGI.pLMNidentity); - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - /* Set the establishment cause according to those provided by RRC */ - DevCheck(s1ap_nas_first_req_p->establishment_cause < RRC_CAUSE_LAST, - s1ap_nas_first_req_p->establishment_cause, RRC_CAUSE_LAST, 0); - /* mandatory */ - ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_RRC_Establishment_Cause; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_RRC_Establishment_Cause; - ie->value.choice.RRC_Establishment_Cause = s1ap_nas_first_req_p->establishment_cause; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - - /* optional */ - if (s1ap_nas_first_req_p->ue_identity.presenceMask & UE_IDENTITIES_s_tmsi) { - S1AP_DEBUG("S_TMSI_PRESENT\n"); + ie->value.choice.NAS_PDU.size = s1ap_nas_first_req_p->nas_pdu.length; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + /* mandatory */ ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_S_TMSI; + ie->id = S1AP_ProtocolIE_ID_id_TAI; ie->criticality = S1AP_Criticality_reject; - ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_S_TMSI; - MME_CODE_TO_OCTET_STRING(s1ap_nas_first_req_p->ue_identity.s_tmsi.mme_code, - &ie->value.choice.S_TMSI.mMEC); - M_TMSI_TO_OCTET_STRING(s1ap_nas_first_req_p->ue_identity.s_tmsi.m_tmsi, - &ie->value.choice.S_TMSI.m_TMSI); + ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_TAI; + /* Assuming TAI is the TAI from the cell */ + INT16_TO_OCTET_STRING(instance_p->tac, &ie->value.choice.TAI.tAC); + MCC_MNC_TO_PLMNID(instance_p->mcc[ue_desc_p->selected_plmn_identity], + instance_p->mnc[ue_desc_p->selected_plmn_identity], + instance_p->mnc_digit_length[ue_desc_p->selected_plmn_identity], + &ie->value.choice.TAI.pLMNidentity); ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } - - /* optional */ - if (0) { + /* mandatory */ ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_CSG_Id; - ie->criticality = S1AP_Criticality_reject; - ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_CSG_Id; - // ie->value.choice.CSG_Id = ; + ie->id = S1AP_ProtocolIE_ID_id_EUTRAN_CGI; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_EUTRAN_CGI; + /* Set the EUTRAN CGI + * The cell identity is defined on 28 bits but as we use macro enb id, + * we have to pad. + */ + //#warning "TODO get cell id from RRC" + MACRO_ENB_ID_TO_CELL_IDENTITY(instance_p->eNB_id, + 0, // Cell ID + &ie->value.choice.EUTRAN_CGI.cell_ID); + MCC_MNC_TO_TBCD(instance_p->mcc[ue_desc_p->selected_plmn_identity], + instance_p->mnc[ue_desc_p->selected_plmn_identity], + instance_p->mnc_digit_length[ue_desc_p->selected_plmn_identity], + &ie->value.choice.EUTRAN_CGI.pLMNidentity); ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } - - /* optional */ - if (s1ap_nas_first_req_p->ue_identity.presenceMask & UE_IDENTITIES_gummei) { - S1AP_DEBUG("GUMMEI_ID_PRESENT\n"); + /* Set the establishment cause according to those provided by RRC */ + DevCheck(s1ap_nas_first_req_p->establishment_cause < RRC_CAUSE_LAST, + s1ap_nas_first_req_p->establishment_cause, RRC_CAUSE_LAST, 0); + /* mandatory */ ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_GUMMEI_ID; - ie->criticality = S1AP_Criticality_reject; - ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_GUMMEI; - MCC_MNC_TO_PLMNID( - s1ap_nas_first_req_p->ue_identity.gummei.mcc, - s1ap_nas_first_req_p->ue_identity.gummei.mnc, - s1ap_nas_first_req_p->ue_identity.gummei.mnc_len, - &ie->value.choice.GUMMEI.pLMN_Identity); - MME_GID_TO_OCTET_STRING(s1ap_nas_first_req_p->ue_identity.gummei.mme_group_id, - &ie->value.choice.GUMMEI.mME_Group_ID); - MME_CODE_TO_OCTET_STRING(s1ap_nas_first_req_p->ue_identity.gummei.mme_code, - &ie->value.choice.GUMMEI.mME_Code); + ie->id = S1AP_ProtocolIE_ID_id_RRC_Establishment_Cause; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_RRC_Establishment_Cause; + ie->value.choice.RRC_Establishment_Cause = s1ap_nas_first_req_p->establishment_cause; ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } - /* optional */ + /* optional */ + if (s1ap_nas_first_req_p->ue_identity.presenceMask & UE_IDENTITIES_s_tmsi) { + S1AP_DEBUG("S_TMSI_PRESENT\n"); + ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_S_TMSI; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_S_TMSI; + MME_CODE_TO_OCTET_STRING(s1ap_nas_first_req_p->ue_identity.s_tmsi.mme_code, + &ie->value.choice.S_TMSI.mMEC); + M_TMSI_TO_OCTET_STRING(s1ap_nas_first_req_p->ue_identity.s_tmsi.m_tmsi, + &ie->value.choice.S_TMSI.m_TMSI); + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } + + /* optional */ + if (0) { + ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_CSG_Id; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_CSG_Id; + // ie->value.choice.CSG_Id = ; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } + + /* optional */ + if (s1ap_nas_first_req_p->ue_identity.presenceMask & UE_IDENTITIES_gummei) { + S1AP_DEBUG("GUMMEI_ID_PRESENT\n"); + ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_GUMMEI_ID; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_GUMMEI; + MCC_MNC_TO_PLMNID( + s1ap_nas_first_req_p->ue_identity.gummei.mcc, + s1ap_nas_first_req_p->ue_identity.gummei.mnc, + s1ap_nas_first_req_p->ue_identity.gummei.mnc_len, + &ie->value.choice.GUMMEI.pLMN_Identity); + MME_GID_TO_OCTET_STRING(s1ap_nas_first_req_p->ue_identity.gummei.mme_group_id, + &ie->value.choice.GUMMEI.mME_Group_ID); + MME_CODE_TO_OCTET_STRING(s1ap_nas_first_req_p->ue_identity.gummei.mme_code, + &ie->value.choice.GUMMEI.mME_Code); + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } + + /* optional */ #if (S1AP_VERSION >= MAKE_VERSION(9, 0, 0)) - if (0) { - ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_CellAccessMode; - ie->criticality = S1AP_Criticality_reject; - ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_CellAccessMode; - // ie->value.choice.CellAccessMode = ; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } + if (0) { + ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_CellAccessMode; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_CellAccessMode; + // ie->value.choice.CellAccessMode = ; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } - /* optional */ + /* optional */ #if (S1AP_VERSION >= MAKE_VERSION(10, 0, 0)) - if (0) { - ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_GW_TransportLayerAddress; - ie->criticality = S1AP_Criticality_reject; - ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_TransportLayerAddress; - // ie->value.choice.TransportLayerAddress =; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } + if (0) { + ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_GW_TransportLayerAddress; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_TransportLayerAddress; + // ie->value.choice.TransportLayerAddress =; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } - /* optional */ - if (0) { - ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_RelayNode_Indicator; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_RelayNode_Indicator; - // ie->value.choice.RelayNode_Indicator =; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } + /* optional */ + if (0) { + ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_RelayNode_Indicator; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_RelayNode_Indicator; + // ie->value.choice.RelayNode_Indicator =; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } #if (S1AP_VERSION >= MAKE_VERSION(11, 0, 0)) - /* optional */ - if (0) { - ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_GUMMEIType; - ie->criticality = S1AP_Criticality_reject; - ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_GUMMEIType; - // ie->value.choice.GUMMEIType =; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } + /* optional */ + if (0) { + ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_GUMMEIType; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_GUMMEIType; + // ie->value.choice.GUMMEIType =; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } - /* optional */ /* release 11 */ - if (0) { - ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_Tunnel_Information_for_BBF; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_TunnelInformation; - // ie->value.choice.TunnelInformation =; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } + /* optional */ /* release 11 */ + if (0) { + ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_Tunnel_Information_for_BBF; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_TunnelInformation; + // ie->value.choice.TunnelInformation =; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } - /* optional */ - if (0) { - ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_SIPTO_L_GW_TransportLayerAddress; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_TransportLayerAddress; - // ie->value.choice.TransportLayerAddress = ; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } + /* optional */ + if (0) { + ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_SIPTO_L_GW_TransportLayerAddress; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_TransportLayerAddress; + // ie->value.choice.TransportLayerAddress = ; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } - /* optional */ - if (0) { - ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_LHN_ID; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_LHN_ID; - // ie->value.choice.LHN_ID = ue_release_req_p->eNB_ue_s1ap_id; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } + /* optional */ + if (0) { + ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_LHN_ID; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_LHN_ID; + // ie->value.choice.LHN_ID = ue_release_req_p->eNB_ue_s1ap_id; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } #if (S1AP_VERSION >= MAKE_VERSION(13, 0, 0)) - /* optional */ - if (0) { - ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_MME_Group_ID; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_MME_Group_ID; - // ie->value.choice.MME_Group_ID =; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } + /* optional */ + if (0) { + ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_MME_Group_ID; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_MME_Group_ID; + // ie->value.choice.MME_Group_ID =; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } - /* optional */ - if (0) { - ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_UE_Usage_Type; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_UE_Usage_Type; - // ie->value.choice.UE_Usage_Type =; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } + /* optional */ + if (0) { + ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_UE_Usage_Type; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_UE_Usage_Type; + // ie->value.choice.UE_Usage_Type =; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } - /* optional */ - if (0) { - ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_CE_mode_B_SupportIndicator; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_CE_mode_B_SupportIndicator; - // ie->value.choice.CE_mode_B_SupportIndicator = ; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } + /* optional */ + if (0) { + ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_CE_mode_B_SupportIndicator; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_CE_mode_B_SupportIndicator; + // ie->value.choice.CE_mode_B_SupportIndicator = ; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } #if (S1AP_VERSION >= MAKE_VERSION(14, 0, 0)) - /* optional */ - if (0) { - ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_DCN_ID; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_DCN_ID; - // ie->value.choice.DCN_ID = ; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } + /* optional */ + if (0) { + ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_DCN_ID; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_DCN_ID; + // ie->value.choice.DCN_ID = ; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } - /* optional */ - if (0) { - ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_Coverage_Level; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_Coverage_Level; - // ie->value.choice.Coverage_Level = ue_release_req_p->eNB_ue_s1ap_id; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } + /* optional */ + if (0) { + ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_Coverage_Level; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_Coverage_Level; + // ie->value.choice.Coverage_Level = ue_release_req_p->eNB_ue_s1ap_id; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } #endif /* #if (S1AP_VERSION >= MAKE_VERSION(14, 0, 0)) */ #endif /* #if (S1AP_VERSION >= MAKE_VERSION(13, 0, 0)) */ @@ -427,44 +427,44 @@ int s1ap_eNB_handle_nas_first_req( #endif /* #if (S1AP_VERSION >= MAKE_VERSION(10, 0, 0)) */ #endif /* #if (S1AP_VERSION >= MAKE_VERSION(9, 0, 0)) */ - if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) { - /* Failed to encode message */ - DevMessage("Failed to encode initial UE message\n"); - } - - /* Update the current S1AP UE state */ - ue_desc_p->ue_state = S1AP_UE_WAITING_CSR; - /* Assign a stream for this UE : - * From 3GPP 36.412 7)Transport layers: - * Within the SCTP association established between one MME and eNB pair: - * - a single pair of stream identifiers shall be reserved for the sole use - * of S1AP elementary procedures that utilize non UE-associated signalling. - * - At least one pair of stream identifiers shall be reserved for the sole use - * of S1AP elementary procedures that utilize UE-associated signallings. - * However a few pairs (i.e. more than one) should be reserved. - * - A single UE-associated signalling shall use one SCTP stream and - * the stream should not be changed during the communication of the - * UE-associated signalling. - */ - mme_desc_p->nextstream = (mme_desc_p->nextstream + 1) % mme_desc_p->out_streams; - - if ((mme_desc_p->nextstream == 0) && (mme_desc_p->out_streams > 1)) { - mme_desc_p->nextstream += 1; - } - - ue_desc_p->tx_stream = mme_desc_p->nextstream; - MSC_LOG_TX_MESSAGE( - MSC_S1AP_ENB, - MSC_S1AP_MME, - (const char *)NULL, - 0, - MSC_AS_TIME_FMT" initialUEMessage initiatingMessage eNB_ue_s1ap_id %u", - 0,0,//MSC_AS_TIME_ARGS(ctxt_pP), - ue_desc_p->eNB_ue_s1ap_id); - /* Send encoded message over sctp */ - s1ap_eNB_itti_send_sctp_data_req(instance_p->instance, mme_desc_p->assoc_id, - buffer, length, ue_desc_p->tx_stream); - return 0; + if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) { + /* Failed to encode message */ + DevMessage("Failed to encode initial UE message\n"); + } + + /* Update the current S1AP UE state */ + ue_desc_p->ue_state = S1AP_UE_WAITING_CSR; + /* Assign a stream for this UE : + * From 3GPP 36.412 7)Transport layers: + * Within the SCTP association established between one MME and eNB pair: + * - a single pair of stream identifiers shall be reserved for the sole use + * of S1AP elementary procedures that utilize non UE-associated signalling. + * - At least one pair of stream identifiers shall be reserved for the sole use + * of S1AP elementary procedures that utilize UE-associated signallings. + * However a few pairs (i.e. more than one) should be reserved. + * - A single UE-associated signalling shall use one SCTP stream and + * the stream should not be changed during the communication of the + * UE-associated signalling. + */ + mme_desc_p->nextstream = (mme_desc_p->nextstream + 1) % mme_desc_p->out_streams; + + if ((mme_desc_p->nextstream == 0) && (mme_desc_p->out_streams > 1)) { + mme_desc_p->nextstream += 1; + } + + ue_desc_p->tx_stream = mme_desc_p->nextstream; + MSC_LOG_TX_MESSAGE( + MSC_S1AP_ENB, + MSC_S1AP_MME, + (const char *)NULL, + 0, + MSC_AS_TIME_FMT" initialUEMessage initiatingMessage eNB_ue_s1ap_id %u", + 0,0,//MSC_AS_TIME_ARGS(ctxt_pP), + ue_desc_p->eNB_ue_s1ap_id); + /* Send encoded message over sctp */ + s1ap_eNB_itti_send_sctp_data_req(instance_p->instance, mme_desc_p->assoc_id, + buffer, length, ue_desc_p->tx_stream); + return 0; } //------------------------------------------------------------------------------ @@ -473,246 +473,258 @@ int s1ap_eNB_handle_nas_downlink(uint32_t assoc_id, S1AP_S1AP_PDU_t *pdu) //------------------------------------------------------------------------------ { - s1ap_eNB_mme_data_t *mme_desc_p = NULL; - s1ap_eNB_ue_context_t *ue_desc_p = NULL; - s1ap_eNB_instance_t *s1ap_eNB_instance = NULL; - S1AP_DownlinkNASTransport_t *container; - S1AP_DownlinkNASTransport_IEs_t *ie; - S1AP_ENB_UE_S1AP_ID_t enb_ue_s1ap_id; - S1AP_MME_UE_S1AP_ID_t mme_ue_s1ap_id; - DevAssert(pdu != NULL); - - /* UE-related procedure -> stream != 0 */ - if (stream == 0) { - S1AP_ERROR("[SCTP %d] Received UE-related procedure on stream == 0\n", - assoc_id); - return -1; - } - - if ((mme_desc_p = s1ap_eNB_get_MME(NULL, assoc_id, 0)) == NULL) { - S1AP_ERROR( - "[SCTP %d] Received NAS downlink message for non existing MME context\n", - assoc_id); - return -1; - } - - s1ap_eNB_instance = mme_desc_p->s1ap_eNB_instance; - /* Prepare the S1AP message to encode */ - container = &pdu->choice.initiatingMessage.value.choice.DownlinkNASTransport; - S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_DownlinkNASTransport_IEs_t, ie, container, - S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID, true); - mme_ue_s1ap_id = ie->value.choice.MME_UE_S1AP_ID; - S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_DownlinkNASTransport_IEs_t, ie, container, - S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID, true); - enb_ue_s1ap_id = ie->value.choice.ENB_UE_S1AP_ID; - - if ((ue_desc_p = s1ap_eNB_get_ue_context(s1ap_eNB_instance, - enb_ue_s1ap_id)) == NULL) { - MSC_LOG_RX_DISCARDED_MESSAGE( - MSC_S1AP_ENB, - MSC_S1AP_MME, - NULL, - 0, - MSC_AS_TIME_FMT" downlinkNASTransport eNB_ue_s1ap_id %u mme_ue_s1ap_id %u", - enb_ue_s1ap_id, - mme_ue_s1ap_id); - S1AP_ERROR("[SCTP %d] Received NAS downlink message for non existing UE context eNB_UE_S1AP_ID: 0x%lx\n", - assoc_id, - enb_ue_s1ap_id); - return -1; - } - - if (0 == ue_desc_p->rx_stream) { - ue_desc_p->rx_stream = stream; - } else if (stream != ue_desc_p->rx_stream) { - S1AP_ERROR("[SCTP %d] Received UE-related procedure on stream %u, expecting %u\n", - assoc_id, stream, ue_desc_p->rx_stream); - return -1; - } - - /* Is it the first outcome of the MME for this UE ? If so store the mme - * UE s1ap id. - */ - if (ue_desc_p->mme_ue_s1ap_id == 0) { - ue_desc_p->mme_ue_s1ap_id = mme_ue_s1ap_id; - } else { - /* We already have a mme ue s1ap id check the received is the same */ - if (ue_desc_p->mme_ue_s1ap_id != mme_ue_s1ap_id) { - S1AP_ERROR("[SCTP %d] Mismatch in MME UE S1AP ID (0x%lx != 0x%"PRIx32"\n", - assoc_id, - mme_ue_s1ap_id, - ue_desc_p->mme_ue_s1ap_id - ); - return -1; + s1ap_eNB_mme_data_t *mme_desc_p = NULL; + s1ap_eNB_ue_context_t *ue_desc_p = NULL; + s1ap_eNB_instance_t *s1ap_eNB_instance = NULL; + S1AP_DownlinkNASTransport_t *container; + S1AP_DownlinkNASTransport_IEs_t *ie; + S1AP_ENB_UE_S1AP_ID_t enb_ue_s1ap_id; + S1AP_MME_UE_S1AP_ID_t mme_ue_s1ap_id; + DevAssert(pdu != NULL); + + /* UE-related procedure -> stream != 0 */ + if (stream == 0) { + S1AP_ERROR("[SCTP %d] Received UE-related procedure on stream == 0\n", + assoc_id); + return -1; } - } - - MSC_LOG_RX_MESSAGE( - MSC_S1AP_ENB, - MSC_S1AP_MME, - NULL, - 0, - MSC_AS_TIME_FMT" downlinkNASTransport eNB_ue_s1ap_id %u mme_ue_s1ap_id %u", - assoc_id, - mme_ue_s1ap_id); - S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_DownlinkNASTransport_IEs_t, ie, container, - S1AP_ProtocolIE_ID_id_NAS_PDU, true); - /* Forward the NAS PDU to RRC */ - s1ap_eNB_itti_send_nas_downlink_ind(s1ap_eNB_instance->instance, - ue_desc_p->ue_initial_id, - ue_desc_p->eNB_ue_s1ap_id, - ie->value.choice.NAS_PDU.buf, - ie->value.choice.NAS_PDU.size); - return 0; + + if ((mme_desc_p = s1ap_eNB_get_MME(NULL, assoc_id, 0)) == NULL) { + S1AP_ERROR( + "[SCTP %d] Received NAS downlink message for non existing MME context\n", + assoc_id); + return -1; + } + + s1ap_eNB_instance = mme_desc_p->s1ap_eNB_instance; + /* Prepare the S1AP message to encode */ + container = &pdu->choice.initiatingMessage.value.choice.DownlinkNASTransport; + S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_DownlinkNASTransport_IEs_t, ie, container, + S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID, true); + if (ie == NULL) { /* checked by macro, but cppcheck doesn't see it */ + return -1; + } else { + mme_ue_s1ap_id = ie->value.choice.MME_UE_S1AP_ID; + } + S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_DownlinkNASTransport_IEs_t, ie, container, + S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID, true); + if (ie == NULL) { /* checked by macro, but cppcheck doesn't see it */ + return -1; + } else { + enb_ue_s1ap_id = ie->value.choice.ENB_UE_S1AP_ID; + } + if ((ue_desc_p = s1ap_eNB_get_ue_context(s1ap_eNB_instance, + enb_ue_s1ap_id)) == NULL) { + MSC_LOG_RX_DISCARDED_MESSAGE( + MSC_S1AP_ENB, + MSC_S1AP_MME, + NULL, + 0, + MSC_AS_TIME_FMT" downlinkNASTransport eNB_ue_s1ap_id %u mme_ue_s1ap_id %u", + enb_ue_s1ap_id, + mme_ue_s1ap_id); + S1AP_ERROR("[SCTP %d] Received NAS downlink message for non existing UE context eNB_UE_S1AP_ID: 0x%lx\n", + assoc_id, + enb_ue_s1ap_id); + return -1; + } + + if (0 == ue_desc_p->rx_stream) { + ue_desc_p->rx_stream = stream; + } else if (stream != ue_desc_p->rx_stream) { + S1AP_ERROR("[SCTP %d] Received UE-related procedure on stream %u, expecting %u\n", + assoc_id, stream, ue_desc_p->rx_stream); + return -1; + } + + /* Is it the first outcome of the MME for this UE ? If so store the mme + * UE s1ap id. + */ + if (ue_desc_p->mme_ue_s1ap_id == 0) { + ue_desc_p->mme_ue_s1ap_id = mme_ue_s1ap_id; + } else { + /* We already have a mme ue s1ap id check the received is the same */ + if (ue_desc_p->mme_ue_s1ap_id != mme_ue_s1ap_id) { + S1AP_ERROR("[SCTP %d] Mismatch in MME UE S1AP ID (0x%lx != 0x%"PRIx32"\n", + assoc_id, + mme_ue_s1ap_id, + ue_desc_p->mme_ue_s1ap_id + ); + return -1; + } + } + + MSC_LOG_RX_MESSAGE( + MSC_S1AP_ENB, + MSC_S1AP_MME, + NULL, + 0, + MSC_AS_TIME_FMT" downlinkNASTransport eNB_ue_s1ap_id %u mme_ue_s1ap_id %u", + assoc_id, + mme_ue_s1ap_id); + + S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_DownlinkNASTransport_IEs_t, ie, container, + S1AP_ProtocolIE_ID_id_NAS_PDU, true); + /* Forward the NAS PDU to RRC */ + if (ie != NULL) { /* checked by macro, but cppcheck doesn't see it */ + s1ap_eNB_itti_send_nas_downlink_ind(s1ap_eNB_instance->instance, + ue_desc_p->ue_initial_id, + ue_desc_p->eNB_ue_s1ap_id, + ie->value.choice.NAS_PDU.buf, + ie->value.choice.NAS_PDU.size); + } else { + return -1; + } + return 0; } //------------------------------------------------------------------------------ int s1ap_eNB_nas_uplink(instance_t instance, s1ap_uplink_nas_t *s1ap_uplink_nas_p) //------------------------------------------------------------------------------ { - struct s1ap_eNB_ue_context_s *ue_context_p; - s1ap_eNB_instance_t *s1ap_eNB_instance_p; - S1AP_S1AP_PDU_t pdu; - S1AP_UplinkNASTransport_t *out; - S1AP_UplinkNASTransport_IEs_t *ie; - uint8_t *buffer; - uint32_t length; - DevAssert(s1ap_uplink_nas_p != NULL); - /* Retrieve the S1AP eNB instance associated with Mod_id */ - s1ap_eNB_instance_p = s1ap_eNB_get_instance(instance); - DevAssert(s1ap_eNB_instance_p != NULL); - - if ((ue_context_p = s1ap_eNB_get_ue_context(s1ap_eNB_instance_p, s1ap_uplink_nas_p->eNB_ue_s1ap_id)) == NULL) { - /* The context for this eNB ue s1ap id doesn't exist in the map of eNB UEs */ - S1AP_WARN("Failed to find ue context associated with eNB ue s1ap id: %06x\n", - s1ap_uplink_nas_p->eNB_ue_s1ap_id); - return -1; - } - - /* Uplink NAS transport can occur either during an s1ap connected state - * or during initial attach (for example: NAS authentication). - */ - if (!(ue_context_p->ue_state == S1AP_UE_CONNECTED || - ue_context_p->ue_state == S1AP_UE_WAITING_CSR)) { - S1AP_WARN("You are attempting to send NAS data over non-connected " - "eNB ue s1ap id: %u, current state: %d\n", - s1ap_uplink_nas_p->eNB_ue_s1ap_id, ue_context_p->ue_state); - return -1; - } - - /* Prepare the S1AP message to encode */ - memset(&pdu, 0, sizeof(pdu)); - pdu.present = S1AP_S1AP_PDU_PR_initiatingMessage; - pdu.choice.initiatingMessage.procedureCode = S1AP_ProcedureCode_id_uplinkNASTransport; - pdu.choice.initiatingMessage.criticality = S1AP_Criticality_ignore; - pdu.choice.initiatingMessage.value.present = S1AP_InitiatingMessage__value_PR_UplinkNASTransport; - out = &pdu.choice.initiatingMessage.value.choice.UplinkNASTransport; - /* mandatory */ - ie = (S1AP_UplinkNASTransport_IEs_t *)calloc(1, sizeof(S1AP_UplinkNASTransport_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; - ie->criticality = S1AP_Criticality_reject; - ie->value.present = S1AP_UplinkNASTransport_IEs__value_PR_MME_UE_S1AP_ID; - ie->value.choice.MME_UE_S1AP_ID = ue_context_p->mme_ue_s1ap_id; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - /* mandatory */ - ie = (S1AP_UplinkNASTransport_IEs_t *)calloc(1, sizeof(S1AP_UplinkNASTransport_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; - ie->criticality = S1AP_Criticality_reject; - ie->value.present = S1AP_UplinkNASTransport_IEs__value_PR_ENB_UE_S1AP_ID; - ie->value.choice.ENB_UE_S1AP_ID = ue_context_p->eNB_ue_s1ap_id; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - /* mandatory */ - ie = (S1AP_UplinkNASTransport_IEs_t *)calloc(1, sizeof(S1AP_UplinkNASTransport_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_NAS_PDU; - ie->criticality = S1AP_Criticality_reject; - ie->value.present = S1AP_UplinkNASTransport_IEs__value_PR_NAS_PDU; - ie->value.choice.NAS_PDU.buf = s1ap_uplink_nas_p->nas_pdu.buffer; - ie->value.choice.NAS_PDU.size = s1ap_uplink_nas_p->nas_pdu.length; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - /* mandatory */ - ie = (S1AP_UplinkNASTransport_IEs_t *)calloc(1, sizeof(S1AP_UplinkNASTransport_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_EUTRAN_CGI; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_UplinkNASTransport_IEs__value_PR_EUTRAN_CGI; - MCC_MNC_TO_PLMNID( - s1ap_eNB_instance_p->mcc[ue_context_p->selected_plmn_identity], - s1ap_eNB_instance_p->mnc[ue_context_p->selected_plmn_identity], - s1ap_eNB_instance_p->mnc_digit_length[ue_context_p->selected_plmn_identity], - &ie->value.choice.EUTRAN_CGI.pLMNidentity); - //#warning "TODO get cell id from RRC" - MACRO_ENB_ID_TO_CELL_IDENTITY(s1ap_eNB_instance_p->eNB_id, - 0, - &ie->value.choice.EUTRAN_CGI.cell_ID); - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - /* mandatory */ - ie = (S1AP_UplinkNASTransport_IEs_t *)calloc(1, sizeof(S1AP_UplinkNASTransport_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_TAI; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_UplinkNASTransport_IEs__value_PR_TAI; - MCC_MNC_TO_PLMNID( - s1ap_eNB_instance_p->mcc[ue_context_p->selected_plmn_identity], - s1ap_eNB_instance_p->mnc[ue_context_p->selected_plmn_identity], - s1ap_eNB_instance_p->mnc_digit_length[ue_context_p->selected_plmn_identity], - &ie->value.choice.TAI.pLMNidentity); - TAC_TO_ASN1(s1ap_eNB_instance_p->tac, &ie->value.choice.TAI.tAC); - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - /* optional */ -#if (S1AP_VERSION >= MAKE_VERSION(10, 0, 0)) + struct s1ap_eNB_ue_context_s *ue_context_p; + s1ap_eNB_instance_t *s1ap_eNB_instance_p; + S1AP_S1AP_PDU_t pdu; + S1AP_UplinkNASTransport_t *out; + S1AP_UplinkNASTransport_IEs_t *ie; + uint8_t *buffer; + uint32_t length; + DevAssert(s1ap_uplink_nas_p != NULL); + /* Retrieve the S1AP eNB instance associated with Mod_id */ + s1ap_eNB_instance_p = s1ap_eNB_get_instance(instance); + DevAssert(s1ap_eNB_instance_p != NULL); + + if ((ue_context_p = s1ap_eNB_get_ue_context(s1ap_eNB_instance_p, s1ap_uplink_nas_p->eNB_ue_s1ap_id)) == NULL) { + /* The context for this eNB ue s1ap id doesn't exist in the map of eNB UEs */ + S1AP_WARN("Failed to find ue context associated with eNB ue s1ap id: %06x\n", + s1ap_uplink_nas_p->eNB_ue_s1ap_id); + return -1; + } + + /* Uplink NAS transport can occur either during an s1ap connected state + * or during initial attach (for example: NAS authentication). + */ + if (!(ue_context_p->ue_state == S1AP_UE_CONNECTED || + ue_context_p->ue_state == S1AP_UE_WAITING_CSR)) { + S1AP_WARN("You are attempting to send NAS data over non-connected " + "eNB ue s1ap id: %u, current state: %d\n", + s1ap_uplink_nas_p->eNB_ue_s1ap_id, ue_context_p->ue_state); + return -1; + } - if (0) { + /* Prepare the S1AP message to encode */ + memset(&pdu, 0, sizeof(pdu)); + pdu.present = S1AP_S1AP_PDU_PR_initiatingMessage; + pdu.choice.initiatingMessage.procedureCode = S1AP_ProcedureCode_id_uplinkNASTransport; + pdu.choice.initiatingMessage.criticality = S1AP_Criticality_ignore; + pdu.choice.initiatingMessage.value.present = S1AP_InitiatingMessage__value_PR_UplinkNASTransport; + out = &pdu.choice.initiatingMessage.value.choice.UplinkNASTransport; + /* mandatory */ ie = (S1AP_UplinkNASTransport_IEs_t *)calloc(1, sizeof(S1AP_UplinkNASTransport_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_GW_TransportLayerAddress; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_UplinkNASTransport_IEs__value_PR_TransportLayerAddress; - // ie->value.choice.TransportLayerAddress = ; + ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_UplinkNASTransport_IEs__value_PR_MME_UE_S1AP_ID; + ie->value.choice.MME_UE_S1AP_ID = ue_context_p->mme_ue_s1ap_id; ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } - - /* optional */ -#if (S1AP_VERSION >= MAKE_VERSION(14, 0, 0)) - - if (0) { + /* mandatory */ ie = (S1AP_UplinkNASTransport_IEs_t *)calloc(1, sizeof(S1AP_UplinkNASTransport_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_SIPTO_L_GW_TransportLayerAddress; + ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_UplinkNASTransport_IEs__value_PR_ENB_UE_S1AP_ID; + ie->value.choice.ENB_UE_S1AP_ID = ue_context_p->eNB_ue_s1ap_id; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + /* mandatory */ + ie = (S1AP_UplinkNASTransport_IEs_t *)calloc(1, sizeof(S1AP_UplinkNASTransport_IEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_NAS_PDU; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_UplinkNASTransport_IEs__value_PR_NAS_PDU; + ie->value.choice.NAS_PDU.buf = s1ap_uplink_nas_p->nas_pdu.buffer; + ie->value.choice.NAS_PDU.size = s1ap_uplink_nas_p->nas_pdu.length; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + /* mandatory */ + ie = (S1AP_UplinkNASTransport_IEs_t *)calloc(1, sizeof(S1AP_UplinkNASTransport_IEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_EUTRAN_CGI; ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_UplinkNASTransport_IEs__value_PR_TransportLayerAddress; - // ie->value.choice.TransportLayerAddress = ; + ie->value.present = S1AP_UplinkNASTransport_IEs__value_PR_EUTRAN_CGI; + MCC_MNC_TO_PLMNID( + s1ap_eNB_instance_p->mcc[ue_context_p->selected_plmn_identity], + s1ap_eNB_instance_p->mnc[ue_context_p->selected_plmn_identity], + s1ap_eNB_instance_p->mnc_digit_length[ue_context_p->selected_plmn_identity], + &ie->value.choice.EUTRAN_CGI.pLMNidentity); + //#warning "TODO get cell id from RRC" + MACRO_ENB_ID_TO_CELL_IDENTITY(s1ap_eNB_instance_p->eNB_id, + 0, + &ie->value.choice.EUTRAN_CGI.cell_ID); ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } - - /* optional */ - if (0) { + /* mandatory */ ie = (S1AP_UplinkNASTransport_IEs_t *)calloc(1, sizeof(S1AP_UplinkNASTransport_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_LHN_ID; + ie->id = S1AP_ProtocolIE_ID_id_TAI; ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_UplinkNASTransport_IEs__value_PR_LHN_ID; - // ie->value.choice.LHN_ID =; + ie->value.present = S1AP_UplinkNASTransport_IEs__value_PR_TAI; + MCC_MNC_TO_PLMNID( + s1ap_eNB_instance_p->mcc[ue_context_p->selected_plmn_identity], + s1ap_eNB_instance_p->mnc[ue_context_p->selected_plmn_identity], + s1ap_eNB_instance_p->mnc_digit_length[ue_context_p->selected_plmn_identity], + &ie->value.choice.TAI.pLMNidentity); + TAC_TO_ASN1(s1ap_eNB_instance_p->tac, &ie->value.choice.TAI.tAC); ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } + /* optional */ +#if (S1AP_VERSION >= MAKE_VERSION(10, 0, 0)) + + if (0) { + ie = (S1AP_UplinkNASTransport_IEs_t *)calloc(1, sizeof(S1AP_UplinkNASTransport_IEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_GW_TransportLayerAddress; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_UplinkNASTransport_IEs__value_PR_TransportLayerAddress; + // ie->value.choice.TransportLayerAddress = ; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } + + /* optional */ +#if (S1AP_VERSION >= MAKE_VERSION(14, 0, 0)) + + if (0) { + ie = (S1AP_UplinkNASTransport_IEs_t *)calloc(1, sizeof(S1AP_UplinkNASTransport_IEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_SIPTO_L_GW_TransportLayerAddress; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_UplinkNASTransport_IEs__value_PR_TransportLayerAddress; + // ie->value.choice.TransportLayerAddress = ; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } + + /* optional */ + if (0) { + ie = (S1AP_UplinkNASTransport_IEs_t *)calloc(1, sizeof(S1AP_UplinkNASTransport_IEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_LHN_ID; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_UplinkNASTransport_IEs__value_PR_LHN_ID; + // ie->value.choice.LHN_ID =; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } #endif /* #if (S1AP_VERSION >= MAKE_VERSION(14, 0, 0)) */ #endif /* #if (S1AP_VERSION >= MAKE_VERSION(10, 0, 0)) */ - if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) { - S1AP_ERROR("Failed to encode uplink NAS transport\n"); - /* Encode procedure has failed... */ - return -1; - } - - MSC_LOG_TX_MESSAGE( - MSC_S1AP_ENB, - MSC_S1AP_MME, - (const char *)NULL, - 0, - MSC_AS_TIME_FMT" uplinkNASTransport initiatingMessage eNB_ue_s1ap_id %u mme_ue_s1ap_id %u", - 0,0,//MSC_AS_TIME_ARGS(ctxt_pP), - ue_context_p->eNB_ue_s1ap_id, - ue_context_p->mme_ue_s1ap_id); - /* UE associated signalling -> use the allocated stream */ - s1ap_eNB_itti_send_sctp_data_req(s1ap_eNB_instance_p->instance, - ue_context_p->mme_ref->assoc_id, buffer, - length, ue_context_p->tx_stream); - return 0; + if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) { + S1AP_ERROR("Failed to encode uplink NAS transport\n"); + /* Encode procedure has failed... */ + return -1; + } + + MSC_LOG_TX_MESSAGE( + MSC_S1AP_ENB, + MSC_S1AP_MME, + (const char *)NULL, + 0, + MSC_AS_TIME_FMT" uplinkNASTransport initiatingMessage eNB_ue_s1ap_id %u mme_ue_s1ap_id %u", + 0,0,//MSC_AS_TIME_ARGS(ctxt_pP), + ue_context_p->eNB_ue_s1ap_id, + ue_context_p->mme_ue_s1ap_id); + /* UE associated signalling -> use the allocated stream */ + s1ap_eNB_itti_send_sctp_data_req(s1ap_eNB_instance_p->instance, + ue_context_p->mme_ref->assoc_id, buffer, + length, ue_context_p->tx_stream); + return 0; } @@ -721,264 +733,264 @@ int s1ap_eNB_nas_non_delivery_ind(instance_t instance, s1ap_nas_non_delivery_ind_t *s1ap_nas_non_delivery_ind) //------------------------------------------------------------------------------ { - struct s1ap_eNB_ue_context_s *ue_context_p; - s1ap_eNB_instance_t *s1ap_eNB_instance_p; - S1AP_S1AP_PDU_t pdu; - S1AP_NASNonDeliveryIndication_t *out; - S1AP_NASNonDeliveryIndication_IEs_t *ie; - uint8_t *buffer; - uint32_t length; - DevAssert(s1ap_nas_non_delivery_ind != NULL); - /* Retrieve the S1AP eNB instance associated with Mod_id */ - s1ap_eNB_instance_p = s1ap_eNB_get_instance(instance); - DevAssert(s1ap_eNB_instance_p != NULL); - - if ((ue_context_p = s1ap_eNB_get_ue_context(s1ap_eNB_instance_p, s1ap_nas_non_delivery_ind->eNB_ue_s1ap_id)) == NULL) { - /* The context for this eNB ue s1ap id doesn't exist in the map of eNB UEs */ - S1AP_WARN("Failed to find ue context associated with eNB ue s1ap id: %06x\n", - s1ap_nas_non_delivery_ind->eNB_ue_s1ap_id); - MSC_LOG_EVENT( - MSC_S1AP_ENB, - MSC_AS_TIME_FMT" Sent of NAS_NON_DELIVERY_IND to MME failed, no context for eNB_ue_s1ap_id %06x", - s1ap_nas_non_delivery_ind->eNB_ue_s1ap_id); - return -1; - } - - /* Prepare the S1AP message to encode */ - memset(&pdu, 0, sizeof(pdu)); - pdu.present = S1AP_S1AP_PDU_PR_initiatingMessage; - pdu.choice.initiatingMessage.procedureCode = S1AP_ProcedureCode_id_NASNonDeliveryIndication; - pdu.choice.initiatingMessage.criticality = S1AP_Criticality_ignore; - pdu.choice.initiatingMessage.value.present = S1AP_InitiatingMessage__value_PR_NASNonDeliveryIndication; - out = &pdu.choice.initiatingMessage.value.choice.NASNonDeliveryIndication; - /* mandatory */ - ie = (S1AP_NASNonDeliveryIndication_IEs_t *)calloc(1, sizeof(S1AP_NASNonDeliveryIndication_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; - ie->criticality = S1AP_Criticality_reject; - ie->value.present = S1AP_NASNonDeliveryIndication_IEs__value_PR_MME_UE_S1AP_ID; - ie->value.choice.MME_UE_S1AP_ID = ue_context_p->mme_ue_s1ap_id; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - /* mandatory */ - ie = (S1AP_NASNonDeliveryIndication_IEs_t *)calloc(1, sizeof(S1AP_NASNonDeliveryIndication_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; - ie->criticality = S1AP_Criticality_reject; - ie->value.present = S1AP_NASNonDeliveryIndication_IEs__value_PR_ENB_UE_S1AP_ID; - ie->value.choice.ENB_UE_S1AP_ID = ue_context_p->eNB_ue_s1ap_id; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - /* mandatory */ - ie = (S1AP_NASNonDeliveryIndication_IEs_t *)calloc(1, sizeof(S1AP_NASNonDeliveryIndication_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_NAS_PDU; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_NASNonDeliveryIndication_IEs__value_PR_NAS_PDU; - ie->value.choice.NAS_PDU.buf = s1ap_nas_non_delivery_ind->nas_pdu.buffer; - ie->value.choice.NAS_PDU.size = s1ap_nas_non_delivery_ind->nas_pdu.length; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - /* mandatory */ - ie = (S1AP_NASNonDeliveryIndication_IEs_t *)calloc(1, sizeof(S1AP_NASNonDeliveryIndication_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_Cause; - ie->criticality = S1AP_Criticality_ignore; - /* Send a dummy cause */ - ie->value.present = S1AP_NASNonDeliveryIndication_IEs__value_PR_Cause; - ie->value.choice.Cause.present = S1AP_Cause_PR_radioNetwork; - ie->value.choice.Cause.choice.radioNetwork = S1AP_CauseRadioNetwork_radio_connection_with_ue_lost; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - - if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) { - S1AP_ERROR("Failed to encode NAS NON delivery indication\n"); - /* Encode procedure has failed... */ - MSC_LOG_EVENT( - MSC_S1AP_ENB, - MSC_AS_TIME_FMT" Sent of NAS_NON_DELIVERY_IND to MME failed (encoding)"); - return -1; - } - - MSC_LOG_TX_MESSAGE( - MSC_S1AP_ENB, - MSC_S1AP_MME, - (const char *)buffer, - length, - MSC_AS_TIME_FMT" NASNonDeliveryIndication initiatingMessage eNB_ue_s1ap_id %u mme_ue_s1ap_id %u", - 0,0,//MSC_AS_TIME_ARGS(ctxt_pP), - ue_context_p->eNB_ue_s1ap_id, - ue_context_p->mme_ue_s1ap_id); - /* UE associated signalling -> use the allocated stream */ - s1ap_eNB_itti_send_sctp_data_req(s1ap_eNB_instance_p->instance, - ue_context_p->mme_ref->assoc_id, buffer, - length, ue_context_p->tx_stream); - return 0; + struct s1ap_eNB_ue_context_s *ue_context_p; + s1ap_eNB_instance_t *s1ap_eNB_instance_p; + S1AP_S1AP_PDU_t pdu; + S1AP_NASNonDeliveryIndication_t *out; + S1AP_NASNonDeliveryIndication_IEs_t *ie; + uint8_t *buffer; + uint32_t length; + DevAssert(s1ap_nas_non_delivery_ind != NULL); + /* Retrieve the S1AP eNB instance associated with Mod_id */ + s1ap_eNB_instance_p = s1ap_eNB_get_instance(instance); + DevAssert(s1ap_eNB_instance_p != NULL); + + if ((ue_context_p = s1ap_eNB_get_ue_context(s1ap_eNB_instance_p, s1ap_nas_non_delivery_ind->eNB_ue_s1ap_id)) == NULL) { + /* The context for this eNB ue s1ap id doesn't exist in the map of eNB UEs */ + S1AP_WARN("Failed to find ue context associated with eNB ue s1ap id: %06x\n", + s1ap_nas_non_delivery_ind->eNB_ue_s1ap_id); + MSC_LOG_EVENT( + MSC_S1AP_ENB, + MSC_AS_TIME_FMT" Sent of NAS_NON_DELIVERY_IND to MME failed, no context for eNB_ue_s1ap_id %06x", + s1ap_nas_non_delivery_ind->eNB_ue_s1ap_id); + return -1; + } + + /* Prepare the S1AP message to encode */ + memset(&pdu, 0, sizeof(pdu)); + pdu.present = S1AP_S1AP_PDU_PR_initiatingMessage; + pdu.choice.initiatingMessage.procedureCode = S1AP_ProcedureCode_id_NASNonDeliveryIndication; + pdu.choice.initiatingMessage.criticality = S1AP_Criticality_ignore; + pdu.choice.initiatingMessage.value.present = S1AP_InitiatingMessage__value_PR_NASNonDeliveryIndication; + out = &pdu.choice.initiatingMessage.value.choice.NASNonDeliveryIndication; + /* mandatory */ + ie = (S1AP_NASNonDeliveryIndication_IEs_t *)calloc(1, sizeof(S1AP_NASNonDeliveryIndication_IEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_NASNonDeliveryIndication_IEs__value_PR_MME_UE_S1AP_ID; + ie->value.choice.MME_UE_S1AP_ID = ue_context_p->mme_ue_s1ap_id; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + /* mandatory */ + ie = (S1AP_NASNonDeliveryIndication_IEs_t *)calloc(1, sizeof(S1AP_NASNonDeliveryIndication_IEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_NASNonDeliveryIndication_IEs__value_PR_ENB_UE_S1AP_ID; + ie->value.choice.ENB_UE_S1AP_ID = ue_context_p->eNB_ue_s1ap_id; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + /* mandatory */ + ie = (S1AP_NASNonDeliveryIndication_IEs_t *)calloc(1, sizeof(S1AP_NASNonDeliveryIndication_IEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_NAS_PDU; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_NASNonDeliveryIndication_IEs__value_PR_NAS_PDU; + ie->value.choice.NAS_PDU.buf = s1ap_nas_non_delivery_ind->nas_pdu.buffer; + ie->value.choice.NAS_PDU.size = s1ap_nas_non_delivery_ind->nas_pdu.length; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + /* mandatory */ + ie = (S1AP_NASNonDeliveryIndication_IEs_t *)calloc(1, sizeof(S1AP_NASNonDeliveryIndication_IEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_Cause; + ie->criticality = S1AP_Criticality_ignore; + /* Send a dummy cause */ + ie->value.present = S1AP_NASNonDeliveryIndication_IEs__value_PR_Cause; + ie->value.choice.Cause.present = S1AP_Cause_PR_radioNetwork; + ie->value.choice.Cause.choice.radioNetwork = S1AP_CauseRadioNetwork_radio_connection_with_ue_lost; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + + if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) { + S1AP_ERROR("Failed to encode NAS NON delivery indication\n"); + /* Encode procedure has failed... */ + MSC_LOG_EVENT( + MSC_S1AP_ENB, + MSC_AS_TIME_FMT" Sent of NAS_NON_DELIVERY_IND to MME failed (encoding)"); + return -1; + } + + MSC_LOG_TX_MESSAGE( + MSC_S1AP_ENB, + MSC_S1AP_MME, + (const char *)buffer, + length, + MSC_AS_TIME_FMT" NASNonDeliveryIndication initiatingMessage eNB_ue_s1ap_id %u mme_ue_s1ap_id %u", + 0,0,//MSC_AS_TIME_ARGS(ctxt_pP), + ue_context_p->eNB_ue_s1ap_id, + ue_context_p->mme_ue_s1ap_id); + /* UE associated signalling -> use the allocated stream */ + s1ap_eNB_itti_send_sctp_data_req(s1ap_eNB_instance_p->instance, + ue_context_p->mme_ref->assoc_id, buffer, + length, ue_context_p->tx_stream); + return 0; } //------------------------------------------------------------------------------ int s1ap_eNB_initial_ctxt_resp( - instance_t instance, s1ap_initial_context_setup_resp_t *initial_ctxt_resp_p) + instance_t instance, s1ap_initial_context_setup_resp_t *initial_ctxt_resp_p) //------------------------------------------------------------------------------ { - s1ap_eNB_instance_t *s1ap_eNB_instance_p = NULL; - struct s1ap_eNB_ue_context_s *ue_context_p = NULL; - S1AP_S1AP_PDU_t pdu; - S1AP_InitialContextSetupResponse_t *out; - S1AP_InitialContextSetupResponseIEs_t *ie; - uint8_t *buffer = NULL; - uint32_t length; - int i; - /* Retrieve the S1AP eNB instance associated with Mod_id */ - s1ap_eNB_instance_p = s1ap_eNB_get_instance(instance); - DevAssert(initial_ctxt_resp_p != NULL); - DevAssert(s1ap_eNB_instance_p != NULL); - - if ((ue_context_p = s1ap_eNB_get_ue_context(s1ap_eNB_instance_p, - initial_ctxt_resp_p->eNB_ue_s1ap_id)) == NULL) { - /* The context for this eNB ue s1ap id doesn't exist in the map of eNB UEs */ - S1AP_WARN("Failed to find ue context associated with eNB ue s1ap id: 0x%06x\n", - initial_ctxt_resp_p->eNB_ue_s1ap_id); - return -1; - } - - /* Uplink NAS transport can occur either during an s1ap connected state - * or during initial attach (for example: NAS authentication). - */ - if (!(ue_context_p->ue_state == S1AP_UE_CONNECTED || - ue_context_p->ue_state == S1AP_UE_WAITING_CSR)) { - S1AP_WARN("You are attempting to send NAS data over non-connected " - "eNB ue s1ap id: %06x, current state: %d\n", - initial_ctxt_resp_p->eNB_ue_s1ap_id, ue_context_p->ue_state); - return -1; - } - - /* Prepare the S1AP message to encode */ - memset(&pdu, 0, sizeof(pdu)); - pdu.present = S1AP_S1AP_PDU_PR_successfulOutcome; - pdu.choice.successfulOutcome.procedureCode = S1AP_ProcedureCode_id_InitialContextSetup; - pdu.choice.successfulOutcome.criticality = S1AP_Criticality_reject; - pdu.choice.successfulOutcome.value.present = S1AP_SuccessfulOutcome__value_PR_InitialContextSetupResponse; - out = &pdu.choice.successfulOutcome.value.choice.InitialContextSetupResponse; - /* mandatory */ - ie = (S1AP_InitialContextSetupResponseIEs_t *)calloc(1, sizeof(S1AP_InitialContextSetupResponseIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_InitialContextSetupResponseIEs__value_PR_MME_UE_S1AP_ID; - ie->value.choice.MME_UE_S1AP_ID = ue_context_p->mme_ue_s1ap_id; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - /* mandatory */ - ie = (S1AP_InitialContextSetupResponseIEs_t *)calloc(1, sizeof(S1AP_InitialContextSetupResponseIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_InitialContextSetupResponseIEs__value_PR_ENB_UE_S1AP_ID; - ie->value.choice.ENB_UE_S1AP_ID = initial_ctxt_resp_p->eNB_ue_s1ap_id; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - /* mandatory */ - ie = (S1AP_InitialContextSetupResponseIEs_t *)calloc(1, sizeof(S1AP_InitialContextSetupResponseIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_E_RABSetupListCtxtSURes; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_InitialContextSetupResponseIEs__value_PR_E_RABSetupListCtxtSURes; - - for (i = 0; i < initial_ctxt_resp_p->nb_of_e_rabs; i++) { - S1AP_E_RABSetupItemCtxtSUResIEs_t *item; + s1ap_eNB_instance_t *s1ap_eNB_instance_p = NULL; + struct s1ap_eNB_ue_context_s *ue_context_p = NULL; + S1AP_S1AP_PDU_t pdu; + S1AP_InitialContextSetupResponse_t *out; + S1AP_InitialContextSetupResponseIEs_t *ie; + uint8_t *buffer = NULL; + uint32_t length; + int i; + /* Retrieve the S1AP eNB instance associated with Mod_id */ + s1ap_eNB_instance_p = s1ap_eNB_get_instance(instance); + DevAssert(initial_ctxt_resp_p != NULL); + DevAssert(s1ap_eNB_instance_p != NULL); + + if ((ue_context_p = s1ap_eNB_get_ue_context(s1ap_eNB_instance_p, + initial_ctxt_resp_p->eNB_ue_s1ap_id)) == NULL) { + /* The context for this eNB ue s1ap id doesn't exist in the map of eNB UEs */ + S1AP_WARN("Failed to find ue context associated with eNB ue s1ap id: 0x%06x\n", + initial_ctxt_resp_p->eNB_ue_s1ap_id); + return -1; + } + + /* Uplink NAS transport can occur either during an s1ap connected state + * or during initial attach (for example: NAS authentication). + */ + if (!(ue_context_p->ue_state == S1AP_UE_CONNECTED || + ue_context_p->ue_state == S1AP_UE_WAITING_CSR)) { + S1AP_WARN("You are attempting to send NAS data over non-connected " + "eNB ue s1ap id: %06x, current state: %d\n", + initial_ctxt_resp_p->eNB_ue_s1ap_id, ue_context_p->ue_state); + return -1; + } + + /* Prepare the S1AP message to encode */ + memset(&pdu, 0, sizeof(pdu)); + pdu.present = S1AP_S1AP_PDU_PR_successfulOutcome; + pdu.choice.successfulOutcome.procedureCode = S1AP_ProcedureCode_id_InitialContextSetup; + pdu.choice.successfulOutcome.criticality = S1AP_Criticality_reject; + pdu.choice.successfulOutcome.value.present = S1AP_SuccessfulOutcome__value_PR_InitialContextSetupResponse; + out = &pdu.choice.successfulOutcome.value.choice.InitialContextSetupResponse; /* mandatory */ - item = (S1AP_E_RABSetupItemCtxtSUResIEs_t *)calloc(1, sizeof(S1AP_E_RABSetupItemCtxtSUResIEs_t)); - item->id = S1AP_ProtocolIE_ID_id_E_RABSetupItemCtxtSURes; - item->criticality = S1AP_Criticality_ignore; - item->value.present = S1AP_E_RABSetupItemCtxtSUResIEs__value_PR_E_RABSetupItemCtxtSURes; - item->value.choice.E_RABSetupItemCtxtSURes.e_RAB_ID = initial_ctxt_resp_p->e_rabs[i].e_rab_id; - GTP_TEID_TO_ASN1(initial_ctxt_resp_p->e_rabs[i].gtp_teid, &item->value.choice.E_RABSetupItemCtxtSURes.gTP_TEID); - item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.buf = malloc(initial_ctxt_resp_p->e_rabs[i].eNB_addr.length); - memcpy(item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.buf, - initial_ctxt_resp_p->e_rabs[i].eNB_addr.buffer, - initial_ctxt_resp_p->e_rabs[i].eNB_addr.length); - item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.size = initial_ctxt_resp_p->e_rabs[i].eNB_addr.length; - item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.bits_unused = 0; - S1AP_DEBUG("initial_ctxt_resp_p: e_rab ID %ld, enb_addr %d.%d.%d.%d, SIZE %ld \n", - item->value.choice.E_RABSetupItemCtxtSURes.e_RAB_ID, - item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.buf[0], - item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.buf[1], - item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.buf[2], - item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.buf[3], - item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.size); - ASN_SEQUENCE_ADD(&ie->value.choice.E_RABSetupListCtxtSURes.list, item); - } - - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - - /* optional */ - if (initial_ctxt_resp_p->nb_of_e_rabs_failed) { ie = (S1AP_InitialContextSetupResponseIEs_t *)calloc(1, sizeof(S1AP_InitialContextSetupResponseIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_E_RABFailedToSetupListCtxtSURes; + ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_InitialContextSetupResponseIEs__value_PR_E_RABList; - - for (i = 0; i < initial_ctxt_resp_p->nb_of_e_rabs_failed; i++) { - S1AP_E_RABItemIEs_t *item; - /* mandatory */ - item = (S1AP_E_RABItemIEs_t *)calloc(1, sizeof(S1AP_E_RABItemIEs_t)); - item->id = S1AP_ProtocolIE_ID_id_E_RABItem; - item->criticality = S1AP_Criticality_ignore; - item->value.present = S1AP_E_RABItemIEs__value_PR_E_RABItem; - item->value.choice.E_RABItem.e_RAB_ID = initial_ctxt_resp_p->e_rabs_failed[i].e_rab_id; - item->value.choice.E_RABItem.cause.present = initial_ctxt_resp_p->e_rabs_failed[i].cause; - - switch(item->value.choice.E_RABItem.cause.present) { - case S1AP_Cause_PR_radioNetwork: - item->value.choice.E_RABItem.cause.choice.radioNetwork = initial_ctxt_resp_p->e_rabs_failed[i].cause_value; - break; - - case S1AP_Cause_PR_transport: - item->value.choice.E_RABItem.cause.choice.transport = initial_ctxt_resp_p->e_rabs_failed[i].cause_value; - break; - - case S1AP_Cause_PR_nas: - item->value.choice.E_RABItem.cause.choice.nas = initial_ctxt_resp_p->e_rabs_failed[i].cause_value; - break; - - case S1AP_Cause_PR_protocol: - item->value.choice.E_RABItem.cause.choice.protocol = initial_ctxt_resp_p->e_rabs_failed[i].cause_value; - break; + ie->value.present = S1AP_InitialContextSetupResponseIEs__value_PR_MME_UE_S1AP_ID; + ie->value.choice.MME_UE_S1AP_ID = ue_context_p->mme_ue_s1ap_id; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + /* mandatory */ + ie = (S1AP_InitialContextSetupResponseIEs_t *)calloc(1, sizeof(S1AP_InitialContextSetupResponseIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_InitialContextSetupResponseIEs__value_PR_ENB_UE_S1AP_ID; + ie->value.choice.ENB_UE_S1AP_ID = initial_ctxt_resp_p->eNB_ue_s1ap_id; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + /* mandatory */ + ie = (S1AP_InitialContextSetupResponseIEs_t *)calloc(1, sizeof(S1AP_InitialContextSetupResponseIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_E_RABSetupListCtxtSURes; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_InitialContextSetupResponseIEs__value_PR_E_RABSetupListCtxtSURes; + + for (i = 0; i < initial_ctxt_resp_p->nb_of_e_rabs; i++) { + S1AP_E_RABSetupItemCtxtSUResIEs_t *item; + /* mandatory */ + item = (S1AP_E_RABSetupItemCtxtSUResIEs_t *)calloc(1, sizeof(S1AP_E_RABSetupItemCtxtSUResIEs_t)); + item->id = S1AP_ProtocolIE_ID_id_E_RABSetupItemCtxtSURes; + item->criticality = S1AP_Criticality_ignore; + item->value.present = S1AP_E_RABSetupItemCtxtSUResIEs__value_PR_E_RABSetupItemCtxtSURes; + item->value.choice.E_RABSetupItemCtxtSURes.e_RAB_ID = initial_ctxt_resp_p->e_rabs[i].e_rab_id; + GTP_TEID_TO_ASN1(initial_ctxt_resp_p->e_rabs[i].gtp_teid, &item->value.choice.E_RABSetupItemCtxtSURes.gTP_TEID); + item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.buf = malloc(initial_ctxt_resp_p->e_rabs[i].eNB_addr.length); + memcpy(item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.buf, + initial_ctxt_resp_p->e_rabs[i].eNB_addr.buffer, + initial_ctxt_resp_p->e_rabs[i].eNB_addr.length); + item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.size = initial_ctxt_resp_p->e_rabs[i].eNB_addr.length; + item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.bits_unused = 0; + S1AP_DEBUG("initial_ctxt_resp_p: e_rab ID %ld, enb_addr %d.%d.%d.%d, SIZE %ld \n", + item->value.choice.E_RABSetupItemCtxtSURes.e_RAB_ID, + item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.buf[0], + item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.buf[1], + item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.buf[2], + item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.buf[3], + item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.size); + ASN_SEQUENCE_ADD(&ie->value.choice.E_RABSetupListCtxtSURes.list, item); + } - case S1AP_Cause_PR_misc: - item->value.choice.E_RABItem.cause.choice.misc = initial_ctxt_resp_p->e_rabs_failed[i].cause_value; - break; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - case S1AP_Cause_PR_NOTHING: - default: - break; - } + /* optional */ + if (initial_ctxt_resp_p->nb_of_e_rabs_failed) { + ie = (S1AP_InitialContextSetupResponseIEs_t *)calloc(1, sizeof(S1AP_InitialContextSetupResponseIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_E_RABFailedToSetupListCtxtSURes; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_InitialContextSetupResponseIEs__value_PR_E_RABList; + + for (i = 0; i < initial_ctxt_resp_p->nb_of_e_rabs_failed; i++) { + S1AP_E_RABItemIEs_t *item; + /* mandatory */ + item = (S1AP_E_RABItemIEs_t *)calloc(1, sizeof(S1AP_E_RABItemIEs_t)); + item->id = S1AP_ProtocolIE_ID_id_E_RABItem; + item->criticality = S1AP_Criticality_ignore; + item->value.present = S1AP_E_RABItemIEs__value_PR_E_RABItem; + item->value.choice.E_RABItem.e_RAB_ID = initial_ctxt_resp_p->e_rabs_failed[i].e_rab_id; + item->value.choice.E_RABItem.cause.present = initial_ctxt_resp_p->e_rabs_failed[i].cause; + + switch(item->value.choice.E_RABItem.cause.present) { + case S1AP_Cause_PR_radioNetwork: + item->value.choice.E_RABItem.cause.choice.radioNetwork = initial_ctxt_resp_p->e_rabs_failed[i].cause_value; + break; + + case S1AP_Cause_PR_transport: + item->value.choice.E_RABItem.cause.choice.transport = initial_ctxt_resp_p->e_rabs_failed[i].cause_value; + break; + + case S1AP_Cause_PR_nas: + item->value.choice.E_RABItem.cause.choice.nas = initial_ctxt_resp_p->e_rabs_failed[i].cause_value; + break; + + case S1AP_Cause_PR_protocol: + item->value.choice.E_RABItem.cause.choice.protocol = initial_ctxt_resp_p->e_rabs_failed[i].cause_value; + break; + + case S1AP_Cause_PR_misc: + item->value.choice.E_RABItem.cause.choice.misc = initial_ctxt_resp_p->e_rabs_failed[i].cause_value; + break; + + case S1AP_Cause_PR_NOTHING: + default: + break; + } + + S1AP_DEBUG("initial context setup response: failed e_rab ID %ld\n", item->value.choice.E_RABItem.e_RAB_ID); + ASN_SEQUENCE_ADD(&ie->value.choice.E_RABList.list, item); + } + + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } - S1AP_DEBUG("initial context setup response: failed e_rab ID %ld\n", item->value.choice.E_RABItem.e_RAB_ID); - ASN_SEQUENCE_ADD(&ie->value.choice.E_RABList.list, item); + /* optional */ + if (0) { + ie = (S1AP_InitialContextSetupResponseIEs_t *)calloc(1, sizeof(S1AP_InitialContextSetupResponseIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_CriticalityDiagnostics; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_InitialContextSetupResponseIEs__value_PR_CriticalityDiagnostics; + // ie->value.choice.CriticalityDiagnostics =; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); } - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } + if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) { + S1AP_ERROR("Failed to encode uplink NAS transport\n"); + /* Encode procedure has failed... */ + return -1; + } - /* optional */ - if (0) { - ie = (S1AP_InitialContextSetupResponseIEs_t *)calloc(1, sizeof(S1AP_InitialContextSetupResponseIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_CriticalityDiagnostics; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_InitialContextSetupResponseIEs__value_PR_CriticalityDiagnostics; - // ie->value.choice.CriticalityDiagnostics =; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } - - if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) { - S1AP_ERROR("Failed to encode uplink NAS transport\n"); - /* Encode procedure has failed... */ - return -1; - } - - MSC_LOG_TX_MESSAGE( - MSC_S1AP_ENB, - MSC_S1AP_MME, - (const char *)buffer, - length, - MSC_AS_TIME_FMT" InitialContextSetup successfulOutcome eNB_ue_s1ap_id %u mme_ue_s1ap_id %u", - 0,0,//MSC_AS_TIME_ARGS(ctxt_pP), - initial_ctxt_resp_p->eNB_ue_s1ap_id, - ue_context_p->mme_ue_s1ap_id); - /* UE associated signalling -> use the allocated stream */ - s1ap_eNB_itti_send_sctp_data_req(s1ap_eNB_instance_p->instance, - ue_context_p->mme_ref->assoc_id, buffer, - length, ue_context_p->tx_stream); - return 0; + MSC_LOG_TX_MESSAGE( + MSC_S1AP_ENB, + MSC_S1AP_MME, + (const char *)buffer, + length, + MSC_AS_TIME_FMT" InitialContextSetup successfulOutcome eNB_ue_s1ap_id %u mme_ue_s1ap_id %u", + 0,0,//MSC_AS_TIME_ARGS(ctxt_pP), + initial_ctxt_resp_p->eNB_ue_s1ap_id, + ue_context_p->mme_ue_s1ap_id); + /* UE associated signalling -> use the allocated stream */ + s1ap_eNB_itti_send_sctp_data_req(s1ap_eNB_instance_p->instance, + ue_context_p->mme_ref->assoc_id, buffer, + length, ue_context_p->tx_stream); + return 0; } //------------------------------------------------------------------------------ @@ -986,100 +998,100 @@ int s1ap_eNB_ue_capabilities(instance_t instance, s1ap_ue_cap_info_ind_t *ue_cap_info_ind_p) //------------------------------------------------------------------------------ { - s1ap_eNB_instance_t *s1ap_eNB_instance_p; - struct s1ap_eNB_ue_context_s *ue_context_p; - S1AP_S1AP_PDU_t pdu; - S1AP_UECapabilityInfoIndication_t *out; - S1AP_UECapabilityInfoIndicationIEs_t *ie; - uint8_t *buffer; - uint32_t length; - /* Retrieve the S1AP eNB instance associated with Mod_id */ - s1ap_eNB_instance_p = s1ap_eNB_get_instance(instance); - DevAssert(ue_cap_info_ind_p != NULL); - DevAssert(s1ap_eNB_instance_p != NULL); - - if ((ue_context_p = s1ap_eNB_get_ue_context(s1ap_eNB_instance_p, - ue_cap_info_ind_p->eNB_ue_s1ap_id)) == NULL) { - /* The context for this eNB ue s1ap id doesn't exist in the map of eNB UEs */ - S1AP_WARN("Failed to find ue context associated with eNB ue s1ap id: %u\n", - ue_cap_info_ind_p->eNB_ue_s1ap_id); - return -1; - } - - /* UE capabilities message can occur either during an s1ap connected state - * or during initial attach (for example: NAS authentication). - */ - if (!(ue_context_p->ue_state == S1AP_UE_CONNECTED || - ue_context_p->ue_state == S1AP_UE_WAITING_CSR)) { - S1AP_WARN("You are attempting to send NAS data over non-connected " - "eNB ue s1ap id: %u, current state: %d\n", - ue_cap_info_ind_p->eNB_ue_s1ap_id, ue_context_p->ue_state); - return -1; - } - - /* Prepare the S1AP message to encode */ - memset(&pdu, 0, sizeof(pdu)); - pdu.present = S1AP_S1AP_PDU_PR_initiatingMessage; - pdu.choice.initiatingMessage.procedureCode = S1AP_ProcedureCode_id_UECapabilityInfoIndication; - pdu.choice.initiatingMessage.criticality = S1AP_Criticality_ignore; - pdu.choice.initiatingMessage.value.present = S1AP_InitiatingMessage__value_PR_UECapabilityInfoIndication; - out = &pdu.choice.initiatingMessage.value.choice.UECapabilityInfoIndication; - /* mandatory */ - ie = (S1AP_UECapabilityInfoIndicationIEs_t *)calloc(1, sizeof(S1AP_UECapabilityInfoIndicationIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; - ie->criticality = S1AP_Criticality_reject; - ie->value.present = S1AP_UECapabilityInfoIndicationIEs__value_PR_MME_UE_S1AP_ID; - ie->value.choice.MME_UE_S1AP_ID = ue_context_p->mme_ue_s1ap_id; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - /* mandatory */ - ie = (S1AP_UECapabilityInfoIndicationIEs_t *)calloc(1, sizeof(S1AP_UECapabilityInfoIndicationIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; - ie->criticality = S1AP_Criticality_reject; - ie->value.present = S1AP_UECapabilityInfoIndicationIEs__value_PR_ENB_UE_S1AP_ID; - ie->value.choice.ENB_UE_S1AP_ID = ue_cap_info_ind_p->eNB_ue_s1ap_id; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - /* mandatory */ - ie = (S1AP_UECapabilityInfoIndicationIEs_t *)calloc(1, sizeof(S1AP_UECapabilityInfoIndicationIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_UERadioCapability; - ie->criticality = S1AP_Criticality_reject; - ie->value.present = S1AP_UECapabilityInfoIndicationIEs__value_PR_UERadioCapability; - ie->value.choice.UERadioCapability.buf = ue_cap_info_ind_p->ue_radio_cap.buffer; - ie->value.choice.UERadioCapability.size = ue_cap_info_ind_p->ue_radio_cap.length; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - /* optional */ -#if (S1AP_VERSION >= MAKE_VERSION(12, 0, 0)) + s1ap_eNB_instance_t *s1ap_eNB_instance_p; + struct s1ap_eNB_ue_context_s *ue_context_p; + S1AP_S1AP_PDU_t pdu; + S1AP_UECapabilityInfoIndication_t *out; + S1AP_UECapabilityInfoIndicationIEs_t *ie; + uint8_t *buffer; + uint32_t length; + /* Retrieve the S1AP eNB instance associated with Mod_id */ + s1ap_eNB_instance_p = s1ap_eNB_get_instance(instance); + DevAssert(ue_cap_info_ind_p != NULL); + DevAssert(s1ap_eNB_instance_p != NULL); + + if ((ue_context_p = s1ap_eNB_get_ue_context(s1ap_eNB_instance_p, + ue_cap_info_ind_p->eNB_ue_s1ap_id)) == NULL) { + /* The context for this eNB ue s1ap id doesn't exist in the map of eNB UEs */ + S1AP_WARN("Failed to find ue context associated with eNB ue s1ap id: %u\n", + ue_cap_info_ind_p->eNB_ue_s1ap_id); + return -1; + } - if (0) { + /* UE capabilities message can occur either during an s1ap connected state + * or during initial attach (for example: NAS authentication). + */ + if (!(ue_context_p->ue_state == S1AP_UE_CONNECTED || + ue_context_p->ue_state == S1AP_UE_WAITING_CSR)) { + S1AP_WARN("You are attempting to send NAS data over non-connected " + "eNB ue s1ap id: %u, current state: %d\n", + ue_cap_info_ind_p->eNB_ue_s1ap_id, ue_context_p->ue_state); + return -1; + } + + /* Prepare the S1AP message to encode */ + memset(&pdu, 0, sizeof(pdu)); + pdu.present = S1AP_S1AP_PDU_PR_initiatingMessage; + pdu.choice.initiatingMessage.procedureCode = S1AP_ProcedureCode_id_UECapabilityInfoIndication; + pdu.choice.initiatingMessage.criticality = S1AP_Criticality_ignore; + pdu.choice.initiatingMessage.value.present = S1AP_InitiatingMessage__value_PR_UECapabilityInfoIndication; + out = &pdu.choice.initiatingMessage.value.choice.UECapabilityInfoIndication; + /* mandatory */ ie = (S1AP_UECapabilityInfoIndicationIEs_t *)calloc(1, sizeof(S1AP_UECapabilityInfoIndicationIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_UERadioCapabilityForPaging; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_UECapabilityInfoIndicationIEs__value_PR_UERadioCapabilityForPaging; - // ie->value.choice.UERadioCapabilityForPaging = ; + ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_UECapabilityInfoIndicationIEs__value_PR_MME_UE_S1AP_ID; + ie->value.choice.MME_UE_S1AP_ID = ue_context_p->mme_ue_s1ap_id; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + /* mandatory */ + ie = (S1AP_UECapabilityInfoIndicationIEs_t *)calloc(1, sizeof(S1AP_UECapabilityInfoIndicationIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_UECapabilityInfoIndicationIEs__value_PR_ENB_UE_S1AP_ID; + ie->value.choice.ENB_UE_S1AP_ID = ue_cap_info_ind_p->eNB_ue_s1ap_id; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + /* mandatory */ + ie = (S1AP_UECapabilityInfoIndicationIEs_t *)calloc(1, sizeof(S1AP_UECapabilityInfoIndicationIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_UERadioCapability; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_UECapabilityInfoIndicationIEs__value_PR_UERadioCapability; + ie->value.choice.UERadioCapability.buf = ue_cap_info_ind_p->ue_radio_cap.buffer; + ie->value.choice.UERadioCapability.size = ue_cap_info_ind_p->ue_radio_cap.length; ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } + /* optional */ +#if (S1AP_VERSION >= MAKE_VERSION(12, 0, 0)) + + if (0) { + ie = (S1AP_UECapabilityInfoIndicationIEs_t *)calloc(1, sizeof(S1AP_UECapabilityInfoIndicationIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_UERadioCapabilityForPaging; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_UECapabilityInfoIndicationIEs__value_PR_UERadioCapabilityForPaging; + // ie->value.choice.UERadioCapabilityForPaging = ; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } #endif /* #if (S1AP_VERSION >= MAKE_VERSION(14, 0, 0)) */ - if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) { - /* Encode procedure has failed... */ - S1AP_ERROR("Failed to encode UE capabilities indication\n"); - return -1; - } - - MSC_LOG_TX_MESSAGE( - MSC_S1AP_ENB, - MSC_S1AP_MME, - (const char *)buffer, - length, - MSC_AS_TIME_FMT" UECapabilityInfoIndication initiatingMessage eNB_ue_s1ap_id %u mme_ue_s1ap_id %u", - 0,0,//MSC_AS_TIME_ARGS(ctxt_pP), - ue_cap_info_ind_p->eNB_ue_s1ap_id, - ue_context_p->mme_ue_s1ap_id); - /* UE associated signalling -> use the allocated stream */ - s1ap_eNB_itti_send_sctp_data_req(s1ap_eNB_instance_p->instance, - ue_context_p->mme_ref->assoc_id, buffer, - length, ue_context_p->tx_stream); - return 0; + if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) { + /* Encode procedure has failed... */ + S1AP_ERROR("Failed to encode UE capabilities indication\n"); + return -1; + } + + MSC_LOG_TX_MESSAGE( + MSC_S1AP_ENB, + MSC_S1AP_MME, + (const char *)buffer, + length, + MSC_AS_TIME_FMT" UECapabilityInfoIndication initiatingMessage eNB_ue_s1ap_id %u mme_ue_s1ap_id %u", + 0,0,//MSC_AS_TIME_ARGS(ctxt_pP), + ue_cap_info_ind_p->eNB_ue_s1ap_id, + ue_context_p->mme_ue_s1ap_id); + /* UE associated signalling -> use the allocated stream */ + s1ap_eNB_itti_send_sctp_data_req(s1ap_eNB_instance_p->instance, + ue_context_p->mme_ref->assoc_id, buffer, + length, ue_context_p->tx_stream); + return 0; } //------------------------------------------------------------------------------ @@ -1087,183 +1099,183 @@ int s1ap_eNB_e_rab_setup_resp(instance_t instance, s1ap_e_rab_setup_resp_t *e_rab_setup_resp_p) //------------------------------------------------------------------------------ { - s1ap_eNB_instance_t *s1ap_eNB_instance_p = NULL; - struct s1ap_eNB_ue_context_s *ue_context_p = NULL; - S1AP_S1AP_PDU_t pdu; - S1AP_E_RABSetupResponse_t *out; - S1AP_E_RABSetupResponseIEs_t *ie; - uint8_t *buffer = NULL; - uint32_t length; - int i; - /* Retrieve the S1AP eNB instance associated with Mod_id */ - s1ap_eNB_instance_p = s1ap_eNB_get_instance(instance); - DevAssert(e_rab_setup_resp_p != NULL); - DevAssert(s1ap_eNB_instance_p != NULL); - - if ((ue_context_p = s1ap_eNB_get_ue_context(s1ap_eNB_instance_p, - e_rab_setup_resp_p->eNB_ue_s1ap_id)) == NULL) { - /* The context for this eNB ue s1ap id doesn't exist in the map of eNB UEs */ - S1AP_WARN("Failed to find ue context associated with eNB ue s1ap id: 0x%06x\n", - e_rab_setup_resp_p->eNB_ue_s1ap_id); - return -1; - } - - /* Uplink NAS transport can occur either during an s1ap connected state - * or during initial attach (for example: NAS authentication). - */ - if (!(ue_context_p->ue_state == S1AP_UE_CONNECTED || - ue_context_p->ue_state == S1AP_UE_WAITING_CSR)) { - S1AP_WARN("You are attempting to send NAS data over non-connected " - "eNB ue s1ap id: %06x, current state: %d\n", - e_rab_setup_resp_p->eNB_ue_s1ap_id, ue_context_p->ue_state); - return -1; - } - - /* Prepare the S1AP message to encode */ - memset(&pdu, 0, sizeof(pdu)); - pdu.present = S1AP_S1AP_PDU_PR_successfulOutcome; - pdu.choice.successfulOutcome.procedureCode = S1AP_ProcedureCode_id_E_RABModify; - pdu.choice.successfulOutcome.criticality = S1AP_Criticality_reject; - pdu.choice.successfulOutcome.value.present = S1AP_SuccessfulOutcome__value_PR_E_RABSetupResponse; - out = &pdu.choice.successfulOutcome.value.choice.E_RABSetupResponse; - /* mandatory */ - ie = (S1AP_E_RABSetupResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABSetupResponseIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_E_RABSetupResponseIEs__value_PR_MME_UE_S1AP_ID; - ie->value.choice.MME_UE_S1AP_ID = ue_context_p->mme_ue_s1ap_id; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - /* mandatory */ - ie = (S1AP_E_RABSetupResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABSetupResponseIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_E_RABSetupResponseIEs__value_PR_ENB_UE_S1AP_ID; - ie->value.choice.ENB_UE_S1AP_ID = e_rab_setup_resp_p->eNB_ue_s1ap_id; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - - /* optional */ - if (e_rab_setup_resp_p->nb_of_e_rabs > 0) { - ie = (S1AP_E_RABSetupResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABSetupResponseIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_E_RABSetupListBearerSURes; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_E_RABSetupResponseIEs__value_PR_E_RABSetupListBearerSURes; - - for (i = 0; i < e_rab_setup_resp_p->nb_of_e_rabs; i++) { - S1AP_E_RABSetupItemBearerSUResIEs_t *item; - /* mandatory */ - item = (S1AP_E_RABSetupItemBearerSUResIEs_t *)calloc(1, sizeof(S1AP_E_RABSetupItemBearerSUResIEs_t)); - item->id = S1AP_ProtocolIE_ID_id_E_RABSetupItemBearerSURes; - item->criticality = S1AP_Criticality_ignore; - item->value.present = S1AP_E_RABSetupItemBearerSUResIEs__value_PR_E_RABSetupItemBearerSURes; - item->value.choice.E_RABSetupItemBearerSURes.e_RAB_ID = e_rab_setup_resp_p->e_rabs[i].e_rab_id; - GTP_TEID_TO_ASN1(e_rab_setup_resp_p->e_rabs[i].gtp_teid, &item->value.choice.E_RABSetupItemBearerSURes.gTP_TEID); - item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.buf = malloc(e_rab_setup_resp_p->e_rabs[i].eNB_addr.length); - memcpy(item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.buf, - e_rab_setup_resp_p->e_rabs[i].eNB_addr.buffer, - e_rab_setup_resp_p->e_rabs[i].eNB_addr.length); - item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.size = e_rab_setup_resp_p->e_rabs[i].eNB_addr.length; - item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.bits_unused = 0; - S1AP_DEBUG("e_rab_setup_resp: e_rab ID %ld, teid %u, enb_addr %d.%d.%d.%d, SIZE %ld\n", - item->value.choice.E_RABSetupItemBearerSURes.e_RAB_ID, - e_rab_setup_resp_p->e_rabs[i].gtp_teid, - item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.buf[0], - item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.buf[1], - item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.buf[2], - item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.buf[3], - item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.size); - ASN_SEQUENCE_ADD(&ie->value.choice.E_RABSetupListBearerSURes.list, item); + s1ap_eNB_instance_t *s1ap_eNB_instance_p = NULL; + struct s1ap_eNB_ue_context_s *ue_context_p = NULL; + S1AP_S1AP_PDU_t pdu; + S1AP_E_RABSetupResponse_t *out; + S1AP_E_RABSetupResponseIEs_t *ie; + uint8_t *buffer = NULL; + uint32_t length; + int i; + /* Retrieve the S1AP eNB instance associated with Mod_id */ + s1ap_eNB_instance_p = s1ap_eNB_get_instance(instance); + DevAssert(e_rab_setup_resp_p != NULL); + DevAssert(s1ap_eNB_instance_p != NULL); + + if ((ue_context_p = s1ap_eNB_get_ue_context(s1ap_eNB_instance_p, + e_rab_setup_resp_p->eNB_ue_s1ap_id)) == NULL) { + /* The context for this eNB ue s1ap id doesn't exist in the map of eNB UEs */ + S1AP_WARN("Failed to find ue context associated with eNB ue s1ap id: 0x%06x\n", + e_rab_setup_resp_p->eNB_ue_s1ap_id); + return -1; } - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } + /* Uplink NAS transport can occur either during an s1ap connected state + * or during initial attach (for example: NAS authentication). + */ + if (!(ue_context_p->ue_state == S1AP_UE_CONNECTED || + ue_context_p->ue_state == S1AP_UE_WAITING_CSR)) { + S1AP_WARN("You are attempting to send NAS data over non-connected " + "eNB ue s1ap id: %06x, current state: %d\n", + e_rab_setup_resp_p->eNB_ue_s1ap_id, ue_context_p->ue_state); + return -1; + } - /* optional */ - if (e_rab_setup_resp_p->nb_of_e_rabs_failed > 0) { + /* Prepare the S1AP message to encode */ + memset(&pdu, 0, sizeof(pdu)); + pdu.present = S1AP_S1AP_PDU_PR_successfulOutcome; + pdu.choice.successfulOutcome.procedureCode = S1AP_ProcedureCode_id_E_RABModify; + pdu.choice.successfulOutcome.criticality = S1AP_Criticality_reject; + pdu.choice.successfulOutcome.value.present = S1AP_SuccessfulOutcome__value_PR_E_RABSetupResponse; + out = &pdu.choice.successfulOutcome.value.choice.E_RABSetupResponse; + /* mandatory */ ie = (S1AP_E_RABSetupResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABSetupResponseIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_E_RABFailedToSetupListBearerSURes; + ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_E_RABSetupResponseIEs__value_PR_E_RABList; - - for (i = 0; i < e_rab_setup_resp_p->nb_of_e_rabs_failed; i++) { - S1AP_E_RABItemIEs_t *item; - item = (S1AP_E_RABItemIEs_t *)calloc(1, sizeof(S1AP_E_RABItemIEs_t)); - item->id = S1AP_ProtocolIE_ID_id_E_RABItem; - item->criticality = S1AP_Criticality_ignore; - item->value.present = S1AP_E_RABItemIEs__value_PR_E_RABItem; - item->value.choice.E_RABItem.e_RAB_ID = e_rab_setup_resp_p->e_rabs_failed[i].e_rab_id; - item->value.choice.E_RABItem.cause.present = e_rab_setup_resp_p->e_rabs_failed[i].cause; - - switch(item->value.choice.E_RABItem.cause.present) { - case S1AP_Cause_PR_radioNetwork: - item->value.choice.E_RABItem.cause.choice.radioNetwork = e_rab_setup_resp_p->e_rabs_failed[i].cause_value; - break; - - case S1AP_Cause_PR_transport: - item->value.choice.E_RABItem.cause.choice.transport = e_rab_setup_resp_p->e_rabs_failed[i].cause_value; - break; - - case S1AP_Cause_PR_nas: - item->value.choice.E_RABItem.cause.choice.nas = e_rab_setup_resp_p->e_rabs_failed[i].cause_value; - break; - - case S1AP_Cause_PR_protocol: - item->value.choice.E_RABItem.cause.choice.protocol = e_rab_setup_resp_p->e_rabs_failed[i].cause_value; - break; + ie->value.present = S1AP_E_RABSetupResponseIEs__value_PR_MME_UE_S1AP_ID; + ie->value.choice.MME_UE_S1AP_ID = ue_context_p->mme_ue_s1ap_id; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + /* mandatory */ + ie = (S1AP_E_RABSetupResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABSetupResponseIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_E_RABSetupResponseIEs__value_PR_ENB_UE_S1AP_ID; + ie->value.choice.ENB_UE_S1AP_ID = e_rab_setup_resp_p->eNB_ue_s1ap_id; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - case S1AP_Cause_PR_misc: - item->value.choice.E_RABItem.cause.choice.misc = e_rab_setup_resp_p->e_rabs_failed[i].cause_value; - break; + /* optional */ + if (e_rab_setup_resp_p->nb_of_e_rabs > 0) { + ie = (S1AP_E_RABSetupResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABSetupResponseIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_E_RABSetupListBearerSURes; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_E_RABSetupResponseIEs__value_PR_E_RABSetupListBearerSURes; + + for (i = 0; i < e_rab_setup_resp_p->nb_of_e_rabs; i++) { + S1AP_E_RABSetupItemBearerSUResIEs_t *item; + /* mandatory */ + item = (S1AP_E_RABSetupItemBearerSUResIEs_t *)calloc(1, sizeof(S1AP_E_RABSetupItemBearerSUResIEs_t)); + item->id = S1AP_ProtocolIE_ID_id_E_RABSetupItemBearerSURes; + item->criticality = S1AP_Criticality_ignore; + item->value.present = S1AP_E_RABSetupItemBearerSUResIEs__value_PR_E_RABSetupItemBearerSURes; + item->value.choice.E_RABSetupItemBearerSURes.e_RAB_ID = e_rab_setup_resp_p->e_rabs[i].e_rab_id; + GTP_TEID_TO_ASN1(e_rab_setup_resp_p->e_rabs[i].gtp_teid, &item->value.choice.E_RABSetupItemBearerSURes.gTP_TEID); + item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.buf = malloc(e_rab_setup_resp_p->e_rabs[i].eNB_addr.length); + memcpy(item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.buf, + e_rab_setup_resp_p->e_rabs[i].eNB_addr.buffer, + e_rab_setup_resp_p->e_rabs[i].eNB_addr.length); + item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.size = e_rab_setup_resp_p->e_rabs[i].eNB_addr.length; + item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.bits_unused = 0; + S1AP_DEBUG("e_rab_setup_resp: e_rab ID %ld, teid %u, enb_addr %d.%d.%d.%d, SIZE %ld\n", + item->value.choice.E_RABSetupItemBearerSURes.e_RAB_ID, + e_rab_setup_resp_p->e_rabs[i].gtp_teid, + item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.buf[0], + item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.buf[1], + item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.buf[2], + item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.buf[3], + item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.size); + ASN_SEQUENCE_ADD(&ie->value.choice.E_RABSetupListBearerSURes.list, item); + } + + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } - case S1AP_Cause_PR_NOTHING: - default: - break; - } + /* optional */ + if (e_rab_setup_resp_p->nb_of_e_rabs_failed > 0) { + ie = (S1AP_E_RABSetupResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABSetupResponseIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_E_RABFailedToSetupListBearerSURes; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_E_RABSetupResponseIEs__value_PR_E_RABList; + + for (i = 0; i < e_rab_setup_resp_p->nb_of_e_rabs_failed; i++) { + S1AP_E_RABItemIEs_t *item; + item = (S1AP_E_RABItemIEs_t *)calloc(1, sizeof(S1AP_E_RABItemIEs_t)); + item->id = S1AP_ProtocolIE_ID_id_E_RABItem; + item->criticality = S1AP_Criticality_ignore; + item->value.present = S1AP_E_RABItemIEs__value_PR_E_RABItem; + item->value.choice.E_RABItem.e_RAB_ID = e_rab_setup_resp_p->e_rabs_failed[i].e_rab_id; + item->value.choice.E_RABItem.cause.present = e_rab_setup_resp_p->e_rabs_failed[i].cause; + + switch(item->value.choice.E_RABItem.cause.present) { + case S1AP_Cause_PR_radioNetwork: + item->value.choice.E_RABItem.cause.choice.radioNetwork = e_rab_setup_resp_p->e_rabs_failed[i].cause_value; + break; + + case S1AP_Cause_PR_transport: + item->value.choice.E_RABItem.cause.choice.transport = e_rab_setup_resp_p->e_rabs_failed[i].cause_value; + break; + + case S1AP_Cause_PR_nas: + item->value.choice.E_RABItem.cause.choice.nas = e_rab_setup_resp_p->e_rabs_failed[i].cause_value; + break; + + case S1AP_Cause_PR_protocol: + item->value.choice.E_RABItem.cause.choice.protocol = e_rab_setup_resp_p->e_rabs_failed[i].cause_value; + break; + + case S1AP_Cause_PR_misc: + item->value.choice.E_RABItem.cause.choice.misc = e_rab_setup_resp_p->e_rabs_failed[i].cause_value; + break; + + case S1AP_Cause_PR_NOTHING: + default: + break; + } + + S1AP_DEBUG("e_rab_modify_resp: failed e_rab ID %ld\n", item->value.choice.E_RABItem.e_RAB_ID); + ASN_SEQUENCE_ADD(&ie->value.choice.E_RABList.list, item); + } + + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } - S1AP_DEBUG("e_rab_modify_resp: failed e_rab ID %ld\n", item->value.choice.E_RABItem.e_RAB_ID); - ASN_SEQUENCE_ADD(&ie->value.choice.E_RABList.list, item); + /* optional */ + if (0) { + ie = (S1AP_E_RABSetupResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABSetupResponseIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_CriticalityDiagnostics; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_E_RABSetupResponseIEs__value_PR_CriticalityDiagnostics; + // ie->value.choice.CriticalityDiagnostics = ; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); } - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } + /* S1AP_E_RABSetupListBearerSURes_t e_RABSetupListBearerSURes; + memset(&e_RABSetupListBearerSURes, 0, sizeof(S1AP_E_RABSetupListBearerSURes_t)); + if (s1ap_encode_s1ap_e_rabsetuplistbearersures(&e_RABSetupListBearerSURes, &initial_ies_p->e_RABSetupListBearerSURes.s1ap_E_RABSetupItemBearerSURes) < 0 ) + return -1; + ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_S1AP_E_RABSetupListBearerSURes, &e_RABSetupListBearerSURes); + */ + fprintf(stderr, "start encode\n"); + + if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) { + S1AP_ERROR("Failed to encode uplink transport\n"); + /* Encode procedure has failed... */ + return -1; + } - /* optional */ - if (0) { - ie = (S1AP_E_RABSetupResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABSetupResponseIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_CriticalityDiagnostics; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_E_RABSetupResponseIEs__value_PR_CriticalityDiagnostics; - // ie->value.choice.CriticalityDiagnostics = ; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } - - /* S1AP_E_RABSetupListBearerSURes_t e_RABSetupListBearerSURes; - memset(&e_RABSetupListBearerSURes, 0, sizeof(S1AP_E_RABSetupListBearerSURes_t)); - if (s1ap_encode_s1ap_e_rabsetuplistbearersures(&e_RABSetupListBearerSURes, &initial_ies_p->e_RABSetupListBearerSURes.s1ap_E_RABSetupItemBearerSURes) < 0 ) - return -1; - ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_S1AP_E_RABSetupListBearerSURes, &e_RABSetupListBearerSURes); - */ - fprintf(stderr, "start encode\n"); - - if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) { - S1AP_ERROR("Failed to encode uplink transport\n"); - /* Encode procedure has failed... */ - return -1; - } - - MSC_LOG_TX_MESSAGE( - MSC_S1AP_ENB, - MSC_S1AP_MME, - (const char *)buffer, - length, - MSC_AS_TIME_FMT" E_RAN Setup successfulOutcome eNB_ue_s1ap_id %u mme_ue_s1ap_id %u", - 0,0,//MSC_AS_TIME_ARGS(ctxt_pP), - e_rab_setup_resp_p->eNB_ue_s1ap_id, - ue_context_p->mme_ue_s1ap_id); - /* UE associated signalling -> use the allocated stream */ - s1ap_eNB_itti_send_sctp_data_req(s1ap_eNB_instance_p->instance, - ue_context_p->mme_ref->assoc_id, buffer, - length, ue_context_p->tx_stream); - return 0; + MSC_LOG_TX_MESSAGE( + MSC_S1AP_ENB, + MSC_S1AP_MME, + (const char *)buffer, + length, + MSC_AS_TIME_FMT" E_RAN Setup successfulOutcome eNB_ue_s1ap_id %u mme_ue_s1ap_id %u", + 0,0,//MSC_AS_TIME_ARGS(ctxt_pP), + e_rab_setup_resp_p->eNB_ue_s1ap_id, + ue_context_p->mme_ue_s1ap_id); + /* UE associated signalling -> use the allocated stream */ + s1ap_eNB_itti_send_sctp_data_req(s1ap_eNB_instance_p->instance, + ue_context_p->mme_ref->assoc_id, buffer, + length, ue_context_p->tx_stream); + return 0; } //------------------------------------------------------------------------------ @@ -1271,325 +1283,325 @@ int s1ap_eNB_e_rab_modify_resp(instance_t instance, s1ap_e_rab_modify_resp_t *e_rab_modify_resp_p) //------------------------------------------------------------------------------ { - s1ap_eNB_instance_t *s1ap_eNB_instance_p = NULL; - struct s1ap_eNB_ue_context_s *ue_context_p = NULL; - S1AP_S1AP_PDU_t pdu; - S1AP_E_RABModifyResponse_t *out; - S1AP_E_RABModifyResponseIEs_t *ie; - uint8_t *buffer = NULL; - uint32_t length; - int i; - /* Retrieve the S1AP eNB instance associated with Mod_id */ - s1ap_eNB_instance_p = s1ap_eNB_get_instance(instance); - DevAssert(e_rab_modify_resp_p != NULL); - DevAssert(s1ap_eNB_instance_p != NULL); - - if ((ue_context_p = s1ap_eNB_get_ue_context(s1ap_eNB_instance_p, - e_rab_modify_resp_p->eNB_ue_s1ap_id)) == NULL) { - /* The context for this eNB ue s1ap id doesn't exist in the map of eNB UEs */ - S1AP_WARN("Failed to find ue context associated with eNB ue s1ap id: 0x%06x\n", - e_rab_modify_resp_p->eNB_ue_s1ap_id); - return -1; - } - - /* Uplink NAS transport can occur either during an s1ap connected state - * or during initial attach (for example: NAS authentication). - */ - if (!(ue_context_p->ue_state == S1AP_UE_CONNECTED || - ue_context_p->ue_state == S1AP_UE_WAITING_CSR)) { - S1AP_WARN("You are attempting to send NAS data over non-connected " - "eNB ue s1ap id: %06x, current state: %d\n", - e_rab_modify_resp_p->eNB_ue_s1ap_id, ue_context_p->ue_state); - return -1; - } - - /* Prepare the S1AP message to encode */ - memset(&pdu, 0, sizeof(pdu)); - pdu.present = S1AP_S1AP_PDU_PR_successfulOutcome; - pdu.choice.successfulOutcome.procedureCode = S1AP_ProcedureCode_id_E_RABModify; - pdu.choice.successfulOutcome.criticality = S1AP_Criticality_reject; - pdu.choice.successfulOutcome.value.present = S1AP_SuccessfulOutcome__value_PR_E_RABModifyResponse; - out = &pdu.choice.successfulOutcome.value.choice.E_RABModifyResponse; - /* mandatory */ - ie = (S1AP_E_RABModifyResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABModifyResponseIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_E_RABModifyResponseIEs__value_PR_MME_UE_S1AP_ID; - ie->value.choice.MME_UE_S1AP_ID = ue_context_p->mme_ue_s1ap_id; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - /* mandatory */ - ie = (S1AP_E_RABModifyResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABModifyResponseIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_E_RABModifyResponseIEs__value_PR_ENB_UE_S1AP_ID; - ie->value.choice.ENB_UE_S1AP_ID = e_rab_modify_resp_p->eNB_ue_s1ap_id; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - - /* optional */ - if (e_rab_modify_resp_p->nb_of_e_rabs > 0) { - ie = (S1AP_E_RABModifyResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABModifyResponseIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_E_RABModifyListBearerModRes; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_E_RABModifyResponseIEs__value_PR_E_RABModifyListBearerModRes; + s1ap_eNB_instance_t *s1ap_eNB_instance_p = NULL; + struct s1ap_eNB_ue_context_s *ue_context_p = NULL; + S1AP_S1AP_PDU_t pdu; + S1AP_E_RABModifyResponse_t *out; + S1AP_E_RABModifyResponseIEs_t *ie; + uint8_t *buffer = NULL; + uint32_t length; + int i; + /* Retrieve the S1AP eNB instance associated with Mod_id */ + s1ap_eNB_instance_p = s1ap_eNB_get_instance(instance); + DevAssert(e_rab_modify_resp_p != NULL); + DevAssert(s1ap_eNB_instance_p != NULL); + + if ((ue_context_p = s1ap_eNB_get_ue_context(s1ap_eNB_instance_p, + e_rab_modify_resp_p->eNB_ue_s1ap_id)) == NULL) { + /* The context for this eNB ue s1ap id doesn't exist in the map of eNB UEs */ + S1AP_WARN("Failed to find ue context associated with eNB ue s1ap id: 0x%06x\n", + e_rab_modify_resp_p->eNB_ue_s1ap_id); + return -1; + } - for (i = 0; i < e_rab_modify_resp_p->nb_of_e_rabs; i++) { - S1AP_E_RABModifyItemBearerModResIEs_t *item; - item = (S1AP_E_RABModifyItemBearerModResIEs_t *)calloc(1, sizeof(S1AP_E_RABModifyItemBearerModResIEs_t)); - item->id = S1AP_ProtocolIE_ID_id_E_RABModifyItemBearerModRes; - item->criticality = S1AP_Criticality_ignore; - item->value.present = S1AP_E_RABModifyItemBearerModResIEs__value_PR_E_RABModifyItemBearerModRes; - item->value.choice.E_RABModifyItemBearerModRes.e_RAB_ID = e_rab_modify_resp_p->e_rabs[i].e_rab_id; - S1AP_DEBUG("e_rab_modify_resp: modified e_rab ID %ld\n", item->value.choice.E_RABModifyItemBearerModRes.e_RAB_ID); - ASN_SEQUENCE_ADD(&ie->value.choice.E_RABModifyListBearerModRes.list, item); + /* Uplink NAS transport can occur either during an s1ap connected state + * or during initial attach (for example: NAS authentication). + */ + if (!(ue_context_p->ue_state == S1AP_UE_CONNECTED || + ue_context_p->ue_state == S1AP_UE_WAITING_CSR)) { + S1AP_WARN("You are attempting to send NAS data over non-connected " + "eNB ue s1ap id: %06x, current state: %d\n", + e_rab_modify_resp_p->eNB_ue_s1ap_id, ue_context_p->ue_state); + return -1; } + /* Prepare the S1AP message to encode */ + memset(&pdu, 0, sizeof(pdu)); + pdu.present = S1AP_S1AP_PDU_PR_successfulOutcome; + pdu.choice.successfulOutcome.procedureCode = S1AP_ProcedureCode_id_E_RABModify; + pdu.choice.successfulOutcome.criticality = S1AP_Criticality_reject; + pdu.choice.successfulOutcome.value.present = S1AP_SuccessfulOutcome__value_PR_E_RABModifyResponse; + out = &pdu.choice.successfulOutcome.value.choice.E_RABModifyResponse; + /* mandatory */ + ie = (S1AP_E_RABModifyResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABModifyResponseIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_E_RABModifyResponseIEs__value_PR_MME_UE_S1AP_ID; + ie->value.choice.MME_UE_S1AP_ID = ue_context_p->mme_ue_s1ap_id; ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } - - /* optional */ - if (e_rab_modify_resp_p->nb_of_e_rabs_failed > 0) { + /* mandatory */ ie = (S1AP_E_RABModifyResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABModifyResponseIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_E_RABFailedToModifyList; + ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_E_RABModifyResponseIEs__value_PR_E_RABList; - - for (i = 0; i < e_rab_modify_resp_p->nb_of_e_rabs_failed; i++) { - S1AP_E_RABItemIEs_t *item; - item = (S1AP_E_RABItemIEs_t *)calloc(1, sizeof(S1AP_E_RABItemIEs_t)); - item->id = S1AP_ProtocolIE_ID_id_E_RABItem; - item->criticality = S1AP_Criticality_ignore; - item->value.present = S1AP_E_RABItemIEs__value_PR_E_RABItem; - item->value.choice.E_RABItem.e_RAB_ID = e_rab_modify_resp_p->e_rabs_failed[i].e_rab_id; - item->value.choice.E_RABItem.cause.present = e_rab_modify_resp_p->e_rabs_failed[i].cause; - - switch(item->value.choice.E_RABItem.cause.present) { - case S1AP_Cause_PR_radioNetwork: - item->value.choice.E_RABItem.cause.choice.radioNetwork = e_rab_modify_resp_p->e_rabs_failed[i].cause_value; - break; - - case S1AP_Cause_PR_transport: - item->value.choice.E_RABItem.cause.choice.transport = e_rab_modify_resp_p->e_rabs_failed[i].cause_value; - break; + ie->value.present = S1AP_E_RABModifyResponseIEs__value_PR_ENB_UE_S1AP_ID; + ie->value.choice.ENB_UE_S1AP_ID = e_rab_modify_resp_p->eNB_ue_s1ap_id; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - case S1AP_Cause_PR_nas: - item->value.choice.E_RABItem.cause.choice.nas = e_rab_modify_resp_p->e_rabs_failed[i].cause_value; - break; + /* optional */ + if (e_rab_modify_resp_p->nb_of_e_rabs > 0) { + ie = (S1AP_E_RABModifyResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABModifyResponseIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_E_RABModifyListBearerModRes; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_E_RABModifyResponseIEs__value_PR_E_RABModifyListBearerModRes; + + for (i = 0; i < e_rab_modify_resp_p->nb_of_e_rabs; i++) { + S1AP_E_RABModifyItemBearerModResIEs_t *item; + item = (S1AP_E_RABModifyItemBearerModResIEs_t *)calloc(1, sizeof(S1AP_E_RABModifyItemBearerModResIEs_t)); + item->id = S1AP_ProtocolIE_ID_id_E_RABModifyItemBearerModRes; + item->criticality = S1AP_Criticality_ignore; + item->value.present = S1AP_E_RABModifyItemBearerModResIEs__value_PR_E_RABModifyItemBearerModRes; + item->value.choice.E_RABModifyItemBearerModRes.e_RAB_ID = e_rab_modify_resp_p->e_rabs[i].e_rab_id; + S1AP_DEBUG("e_rab_modify_resp: modified e_rab ID %ld\n", item->value.choice.E_RABModifyItemBearerModRes.e_RAB_ID); + ASN_SEQUENCE_ADD(&ie->value.choice.E_RABModifyListBearerModRes.list, item); + } + + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } - case S1AP_Cause_PR_protocol: - item->value.choice.E_RABItem.cause.choice.protocol = e_rab_modify_resp_p->e_rabs_failed[i].cause_value; - break; + /* optional */ + if (e_rab_modify_resp_p->nb_of_e_rabs_failed > 0) { + ie = (S1AP_E_RABModifyResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABModifyResponseIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_E_RABFailedToModifyList; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_E_RABModifyResponseIEs__value_PR_E_RABList; + + for (i = 0; i < e_rab_modify_resp_p->nb_of_e_rabs_failed; i++) { + S1AP_E_RABItemIEs_t *item; + item = (S1AP_E_RABItemIEs_t *)calloc(1, sizeof(S1AP_E_RABItemIEs_t)); + item->id = S1AP_ProtocolIE_ID_id_E_RABItem; + item->criticality = S1AP_Criticality_ignore; + item->value.present = S1AP_E_RABItemIEs__value_PR_E_RABItem; + item->value.choice.E_RABItem.e_RAB_ID = e_rab_modify_resp_p->e_rabs_failed[i].e_rab_id; + item->value.choice.E_RABItem.cause.present = e_rab_modify_resp_p->e_rabs_failed[i].cause; + + switch(item->value.choice.E_RABItem.cause.present) { + case S1AP_Cause_PR_radioNetwork: + item->value.choice.E_RABItem.cause.choice.radioNetwork = e_rab_modify_resp_p->e_rabs_failed[i].cause_value; + break; + + case S1AP_Cause_PR_transport: + item->value.choice.E_RABItem.cause.choice.transport = e_rab_modify_resp_p->e_rabs_failed[i].cause_value; + break; + + case S1AP_Cause_PR_nas: + item->value.choice.E_RABItem.cause.choice.nas = e_rab_modify_resp_p->e_rabs_failed[i].cause_value; + break; + + case S1AP_Cause_PR_protocol: + item->value.choice.E_RABItem.cause.choice.protocol = e_rab_modify_resp_p->e_rabs_failed[i].cause_value; + break; + + case S1AP_Cause_PR_misc: + item->value.choice.E_RABItem.cause.choice.misc = e_rab_modify_resp_p->e_rabs_failed[i].cause_value; + break; + + case S1AP_Cause_PR_NOTHING: + default: + break; + } + + S1AP_DEBUG("e_rab_modify_resp: failed e_rab ID %ld\n", item->value.choice.E_RABItem.e_RAB_ID); + ASN_SEQUENCE_ADD(&ie->value.choice.E_RABList.list, item); + } + + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } - case S1AP_Cause_PR_misc: - item->value.choice.E_RABItem.cause.choice.misc = e_rab_modify_resp_p->e_rabs_failed[i].cause_value; - break; + /* optional */ + if (0) { + ie = (S1AP_E_RABModifyResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABModifyResponseIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_CriticalityDiagnostics; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_E_RABModifyResponseIEs__value_PR_CriticalityDiagnostics; + // ie->value.choice.CriticalityDiagnostics = ; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } - case S1AP_Cause_PR_NOTHING: - default: - break; - } + fprintf(stderr, "start encode\n"); - S1AP_DEBUG("e_rab_modify_resp: failed e_rab ID %ld\n", item->value.choice.E_RABItem.e_RAB_ID); - ASN_SEQUENCE_ADD(&ie->value.choice.E_RABList.list, item); + if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) { + S1AP_ERROR("Failed to encode uplink transport\n"); + /* Encode procedure has failed... */ + return -1; } - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } - - /* optional */ - if (0) { - ie = (S1AP_E_RABModifyResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABModifyResponseIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_CriticalityDiagnostics; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_E_RABModifyResponseIEs__value_PR_CriticalityDiagnostics; - // ie->value.choice.CriticalityDiagnostics = ; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } - - fprintf(stderr, "start encode\n"); - - if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) { - S1AP_ERROR("Failed to encode uplink transport\n"); - /* Encode procedure has failed... */ - return -1; - } - - MSC_LOG_TX_MESSAGE( - MSC_S1AP_ENB, - MSC_S1AP_MME, - (const char *)buffer, - length, - MSC_AS_TIME_FMT" E_RAN Modify successful Outcome eNB_ue_s1ap_id %u mme_ue_s1ap_id %u", - 0,0,//MSC_AS_TIME_ARGS(ctxt_pP), - e_rab_modify_resp_p->eNB_ue_s1ap_id, - ue_context_p->mme_ue_s1ap_id); - /* UE associated signalling -> use the allocated stream */ - s1ap_eNB_itti_send_sctp_data_req(s1ap_eNB_instance_p->instance, - ue_context_p->mme_ref->assoc_id, buffer, - length, ue_context_p->tx_stream); - return 0; + MSC_LOG_TX_MESSAGE( + MSC_S1AP_ENB, + MSC_S1AP_MME, + (const char *)buffer, + length, + MSC_AS_TIME_FMT" E_RAN Modify successful Outcome eNB_ue_s1ap_id %u mme_ue_s1ap_id %u", + 0,0,//MSC_AS_TIME_ARGS(ctxt_pP), + e_rab_modify_resp_p->eNB_ue_s1ap_id, + ue_context_p->mme_ue_s1ap_id); + /* UE associated signalling -> use the allocated stream */ + s1ap_eNB_itti_send_sctp_data_req(s1ap_eNB_instance_p->instance, + ue_context_p->mme_ref->assoc_id, buffer, + length, ue_context_p->tx_stream); + return 0; } //------------------------------------------------------------------------------ int s1ap_eNB_e_rab_release_resp(instance_t instance, s1ap_e_rab_release_resp_t *e_rab_release_resp_p) //------------------------------------------------------------------------------ { - s1ap_eNB_instance_t *s1ap_eNB_instance_p = NULL; - struct s1ap_eNB_ue_context_s *ue_context_p = NULL; - S1AP_S1AP_PDU_t pdu; - S1AP_E_RABReleaseResponse_t *out; - S1AP_E_RABReleaseResponseIEs_t *ie; - uint8_t *buffer = NULL; - uint32_t length; - int i; - /* Retrieve the S1AP eNB instance associated with Mod_id */ - s1ap_eNB_instance_p = s1ap_eNB_get_instance(instance); - DevAssert(e_rab_release_resp_p != NULL); - DevAssert(s1ap_eNB_instance_p != NULL); - - if ((ue_context_p = s1ap_eNB_get_ue_context(s1ap_eNB_instance_p, - e_rab_release_resp_p->eNB_ue_s1ap_id)) == NULL) { - /* The context for this eNB ue s1ap id doesn't exist in the map of eNB UEs */ - S1AP_WARN("Failed to find ue context associated with eNB ue s1ap id: %u\n", - e_rab_release_resp_p->eNB_ue_s1ap_id); - return -1; - } - - /* Prepare the S1AP message to encode */ - memset(&pdu, 0, sizeof(pdu)); - pdu.present = S1AP_S1AP_PDU_PR_successfulOutcome; - pdu.choice.successfulOutcome.procedureCode = S1AP_ProcedureCode_id_E_RABRelease; - pdu.choice.successfulOutcome.criticality = S1AP_Criticality_reject; - pdu.choice.successfulOutcome.value.present = S1AP_SuccessfulOutcome__value_PR_E_RABReleaseResponse; - out = &pdu.choice.successfulOutcome.value.choice.E_RABReleaseResponse; - /* mandatory */ - ie = (S1AP_E_RABReleaseResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABReleaseResponseIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_E_RABReleaseResponseIEs__value_PR_MME_UE_S1AP_ID; - ie->value.choice.MME_UE_S1AP_ID = ue_context_p->mme_ue_s1ap_id; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - /* mandatory */ - ie = (S1AP_E_RABReleaseResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABReleaseResponseIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_E_RABReleaseResponseIEs__value_PR_ENB_UE_S1AP_ID; - ie->value.choice.ENB_UE_S1AP_ID = e_rab_release_resp_p->eNB_ue_s1ap_id; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - - /* optional */ - if (e_rab_release_resp_p->nb_of_e_rabs_released > 0) { - ie = (S1AP_E_RABReleaseResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABReleaseResponseIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_E_RABReleaseListBearerRelComp; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_E_RABReleaseResponseIEs__value_PR_E_RABReleaseListBearerRelComp; - - for (i = 0; i < e_rab_release_resp_p->nb_of_e_rabs_released; i++) { - S1AP_E_RABReleaseItemBearerRelCompIEs_t *item; - item = (S1AP_E_RABReleaseItemBearerRelCompIEs_t *)calloc(1, sizeof(S1AP_E_RABReleaseItemBearerRelCompIEs_t)); - item->id = S1AP_ProtocolIE_ID_id_E_RABReleaseItemBearerRelComp; - item->criticality = S1AP_Criticality_ignore; - item->value.present = S1AP_E_RABReleaseItemBearerRelCompIEs__value_PR_E_RABReleaseItemBearerRelComp; - item->value.choice.E_RABReleaseItemBearerRelComp.e_RAB_ID = e_rab_release_resp_p->e_rab_release[i].e_rab_id; - S1AP_DEBUG("e_rab_release_resp: e_rab ID %ld\n", item->value.choice.E_RABReleaseItemBearerRelComp.e_RAB_ID); - ASN_SEQUENCE_ADD(&ie->value.choice.E_RABReleaseListBearerRelComp.list, item); + s1ap_eNB_instance_t *s1ap_eNB_instance_p = NULL; + struct s1ap_eNB_ue_context_s *ue_context_p = NULL; + S1AP_S1AP_PDU_t pdu; + S1AP_E_RABReleaseResponse_t *out; + S1AP_E_RABReleaseResponseIEs_t *ie; + uint8_t *buffer = NULL; + uint32_t length; + int i; + /* Retrieve the S1AP eNB instance associated with Mod_id */ + s1ap_eNB_instance_p = s1ap_eNB_get_instance(instance); + DevAssert(e_rab_release_resp_p != NULL); + DevAssert(s1ap_eNB_instance_p != NULL); + + if ((ue_context_p = s1ap_eNB_get_ue_context(s1ap_eNB_instance_p, + e_rab_release_resp_p->eNB_ue_s1ap_id)) == NULL) { + /* The context for this eNB ue s1ap id doesn't exist in the map of eNB UEs */ + S1AP_WARN("Failed to find ue context associated with eNB ue s1ap id: %u\n", + e_rab_release_resp_p->eNB_ue_s1ap_id); + return -1; } + /* Prepare the S1AP message to encode */ + memset(&pdu, 0, sizeof(pdu)); + pdu.present = S1AP_S1AP_PDU_PR_successfulOutcome; + pdu.choice.successfulOutcome.procedureCode = S1AP_ProcedureCode_id_E_RABRelease; + pdu.choice.successfulOutcome.criticality = S1AP_Criticality_reject; + pdu.choice.successfulOutcome.value.present = S1AP_SuccessfulOutcome__value_PR_E_RABReleaseResponse; + out = &pdu.choice.successfulOutcome.value.choice.E_RABReleaseResponse; + /* mandatory */ + ie = (S1AP_E_RABReleaseResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABReleaseResponseIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_E_RABReleaseResponseIEs__value_PR_MME_UE_S1AP_ID; + ie->value.choice.MME_UE_S1AP_ID = ue_context_p->mme_ue_s1ap_id; ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } - - /* optional */ - if (e_rab_release_resp_p->nb_of_e_rabs_failed > 0) { + /* mandatory */ ie = (S1AP_E_RABReleaseResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABReleaseResponseIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_E_RABFailedToReleaseList; + ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_E_RABReleaseResponseIEs__value_PR_E_RABList; - - for (i = 0; i < e_rab_release_resp_p->nb_of_e_rabs_failed; i++) { - S1AP_E_RABItemIEs_t *item; - item = (S1AP_E_RABItemIEs_t *)calloc(1, sizeof(S1AP_E_RABItemIEs_t)); - item->id = S1AP_ProtocolIE_ID_id_E_RABItem; - item->criticality = S1AP_Criticality_ignore; - item->value.present = S1AP_E_RABItemIEs__value_PR_E_RABItem; - item->value.choice.E_RABItem.e_RAB_ID = e_rab_release_resp_p->e_rabs_failed[i].e_rab_id; - item->value.choice.E_RABItem.cause.present = e_rab_release_resp_p->e_rabs_failed[i].cause; - - switch(item->value.choice.E_RABItem.cause.present) { - case S1AP_Cause_PR_radioNetwork: - item->value.choice.E_RABItem.cause.choice.radioNetwork = e_rab_release_resp_p->e_rabs_failed[i].cause_value; - break; - - case S1AP_Cause_PR_transport: - item->value.choice.E_RABItem.cause.choice.transport = e_rab_release_resp_p->e_rabs_failed[i].cause_value; - break; - - case S1AP_Cause_PR_nas: - item->value.choice.E_RABItem.cause.choice.nas = e_rab_release_resp_p->e_rabs_failed[i].cause_value; - break; - - case S1AP_Cause_PR_protocol: - item->value.choice.E_RABItem.cause.choice.protocol = e_rab_release_resp_p->e_rabs_failed[i].cause_value; - break; - - case S1AP_Cause_PR_misc: - item->value.choice.E_RABItem.cause.choice.misc = e_rab_release_resp_p->e_rabs_failed[i].cause_value; - break; - - case S1AP_Cause_PR_NOTHING: - default: - break; - } + ie->value.present = S1AP_E_RABReleaseResponseIEs__value_PR_ENB_UE_S1AP_ID; + ie->value.choice.ENB_UE_S1AP_ID = e_rab_release_resp_p->eNB_ue_s1ap_id; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - ASN_SEQUENCE_ADD(&ie->value.choice.E_RABList.list, item); + /* optional */ + if (e_rab_release_resp_p->nb_of_e_rabs_released > 0) { + ie = (S1AP_E_RABReleaseResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABReleaseResponseIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_E_RABReleaseListBearerRelComp; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_E_RABReleaseResponseIEs__value_PR_E_RABReleaseListBearerRelComp; + + for (i = 0; i < e_rab_release_resp_p->nb_of_e_rabs_released; i++) { + S1AP_E_RABReleaseItemBearerRelCompIEs_t *item; + item = (S1AP_E_RABReleaseItemBearerRelCompIEs_t *)calloc(1, sizeof(S1AP_E_RABReleaseItemBearerRelCompIEs_t)); + item->id = S1AP_ProtocolIE_ID_id_E_RABReleaseItemBearerRelComp; + item->criticality = S1AP_Criticality_ignore; + item->value.present = S1AP_E_RABReleaseItemBearerRelCompIEs__value_PR_E_RABReleaseItemBearerRelComp; + item->value.choice.E_RABReleaseItemBearerRelComp.e_RAB_ID = e_rab_release_resp_p->e_rab_release[i].e_rab_id; + S1AP_DEBUG("e_rab_release_resp: e_rab ID %ld\n", item->value.choice.E_RABReleaseItemBearerRelComp.e_RAB_ID); + ASN_SEQUENCE_ADD(&ie->value.choice.E_RABReleaseListBearerRelComp.list, item); + } + + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); } - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } + /* optional */ + if (e_rab_release_resp_p->nb_of_e_rabs_failed > 0) { + ie = (S1AP_E_RABReleaseResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABReleaseResponseIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_E_RABFailedToReleaseList; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_E_RABReleaseResponseIEs__value_PR_E_RABList; + + for (i = 0; i < e_rab_release_resp_p->nb_of_e_rabs_failed; i++) { + S1AP_E_RABItemIEs_t *item; + item = (S1AP_E_RABItemIEs_t *)calloc(1, sizeof(S1AP_E_RABItemIEs_t)); + item->id = S1AP_ProtocolIE_ID_id_E_RABItem; + item->criticality = S1AP_Criticality_ignore; + item->value.present = S1AP_E_RABItemIEs__value_PR_E_RABItem; + item->value.choice.E_RABItem.e_RAB_ID = e_rab_release_resp_p->e_rabs_failed[i].e_rab_id; + item->value.choice.E_RABItem.cause.present = e_rab_release_resp_p->e_rabs_failed[i].cause; + + switch(item->value.choice.E_RABItem.cause.present) { + case S1AP_Cause_PR_radioNetwork: + item->value.choice.E_RABItem.cause.choice.radioNetwork = e_rab_release_resp_p->e_rabs_failed[i].cause_value; + break; + + case S1AP_Cause_PR_transport: + item->value.choice.E_RABItem.cause.choice.transport = e_rab_release_resp_p->e_rabs_failed[i].cause_value; + break; + + case S1AP_Cause_PR_nas: + item->value.choice.E_RABItem.cause.choice.nas = e_rab_release_resp_p->e_rabs_failed[i].cause_value; + break; + + case S1AP_Cause_PR_protocol: + item->value.choice.E_RABItem.cause.choice.protocol = e_rab_release_resp_p->e_rabs_failed[i].cause_value; + break; + + case S1AP_Cause_PR_misc: + item->value.choice.E_RABItem.cause.choice.misc = e_rab_release_resp_p->e_rabs_failed[i].cause_value; + break; + + case S1AP_Cause_PR_NOTHING: + default: + break; + } + + ASN_SEQUENCE_ADD(&ie->value.choice.E_RABList.list, item); + } + + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } - /* optional */ - if (0) { - ie = (S1AP_E_RABReleaseResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABReleaseResponseIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_CriticalityDiagnostics; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_E_RABReleaseResponseIEs__value_PR_CriticalityDiagnostics; - // ie->value.choice.CriticalityDiagnostics = ; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } + /* optional */ + if (0) { + ie = (S1AP_E_RABReleaseResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABReleaseResponseIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_CriticalityDiagnostics; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_E_RABReleaseResponseIEs__value_PR_CriticalityDiagnostics; + // ie->value.choice.CriticalityDiagnostics = ; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } - /* optional */ + /* optional */ #if (S1AP_VERSION >= MAKE_VERSION(12, 0, 0)) - if(0) { - ie = (S1AP_E_RABReleaseResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABReleaseResponseIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_UserLocationInformation; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_E_RABReleaseResponseIEs__value_PR_UserLocationInformation; - // ie->value.choice.UserLocationInformation = ; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } + if(0) { + ie = (S1AP_E_RABReleaseResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABReleaseResponseIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_UserLocationInformation; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_E_RABReleaseResponseIEs__value_PR_UserLocationInformation; + // ie->value.choice.UserLocationInformation = ; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } #endif /* #if (S1AP_VERSION >= MAKE_VERSION(14, 0, 0)) */ - fprintf(stderr, "start encode\n"); - - if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) { - S1AP_ERROR("Failed to encode release response\n"); - /* Encode procedure has failed... */ - return -1; - } - - MSC_LOG_TX_MESSAGE( - MSC_S1AP_ENB, - MSC_S1AP_MME, - (const char *)buffer, - length, - MSC_AS_TIME_FMT" E_RAN Release successfulOutcome eNB_ue_s1ap_id %u mme_ue_s1ap_id %u", - 0,0,//MSC_AS_TIME_ARGS(ctxt_pP), - e_rab_release_resp_p->eNB_ue_s1ap_id, - ue_context_p->mme_ue_s1ap_id); - /* UE associated signalling -> use the allocated stream */ - s1ap_eNB_itti_send_sctp_data_req(s1ap_eNB_instance_p->instance, - ue_context_p->mme_ref->assoc_id, buffer, - length, ue_context_p->tx_stream); - S1AP_INFO("e_rab_release_response sended eNB_UE_S1AP_ID %d mme_ue_s1ap_id %d nb_of_e_rabs_released %d nb_of_e_rabs_failed %d\n", - e_rab_release_resp_p->eNB_ue_s1ap_id, ue_context_p->mme_ue_s1ap_id,e_rab_release_resp_p->nb_of_e_rabs_released,e_rab_release_resp_p->nb_of_e_rabs_failed); - return 0; + fprintf(stderr, "start encode\n"); + + if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) { + S1AP_ERROR("Failed to encode release response\n"); + /* Encode procedure has failed... */ + return -1; + } + + MSC_LOG_TX_MESSAGE( + MSC_S1AP_ENB, + MSC_S1AP_MME, + (const char *)buffer, + length, + MSC_AS_TIME_FMT" E_RAN Release successfulOutcome eNB_ue_s1ap_id %u mme_ue_s1ap_id %u", + 0,0,//MSC_AS_TIME_ARGS(ctxt_pP), + e_rab_release_resp_p->eNB_ue_s1ap_id, + ue_context_p->mme_ue_s1ap_id); + /* UE associated signalling -> use the allocated stream */ + s1ap_eNB_itti_send_sctp_data_req(s1ap_eNB_instance_p->instance, + ue_context_p->mme_ref->assoc_id, buffer, + length, ue_context_p->tx_stream); + S1AP_INFO("e_rab_release_response sended eNB_UE_S1AP_ID %d mme_ue_s1ap_id %d nb_of_e_rabs_released %d nb_of_e_rabs_failed %d\n", + e_rab_release_resp_p->eNB_ue_s1ap_id, ue_context_p->mme_ue_s1ap_id,e_rab_release_resp_p->nb_of_e_rabs_released,e_rab_release_resp_p->nb_of_e_rabs_failed); + return 0; } diff --git a/openair3/S1AP/s1ap_eNB_overload.c b/openair3/S1AP/s1ap_eNB_overload.c index cf208fc16e3e47dfaa2d63d64842bed52caa9397..9358ae62bdb6286873240f3194af9e609921172f 100644 --- a/openair3/S1AP/s1ap_eNB_overload.c +++ b/openair3/S1AP/s1ap_eNB_overload.c @@ -47,60 +47,60 @@ int s1ap_eNB_handle_overload_start(uint32_t assoc_id, uint32_t stream, S1AP_S1AP_PDU_t *pdu) { - s1ap_eNB_mme_data_t *mme_desc_p; - S1AP_OverloadStart_t *container; - S1AP_OverloadStartIEs_t *ie; - - DevAssert(pdu != NULL); - - container = &pdu->choice.initiatingMessage.value.choice.OverloadStart; - - S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_OverloadStartIEs_t, ie, container, - S1AP_ProtocolIE_ID_id_OverloadResponse, true); - - DevCheck(ie->value.choice.OverloadResponse.present == - S1AP_OverloadResponse_PR_overloadAction, - S1AP_OverloadResponse_PR_overloadAction, 0, 0); - - /* Non UE-associated signalling -> stream 0 */ - DevCheck(stream == 0, stream, 0, 0); - - if ((mme_desc_p = s1ap_eNB_get_MME(NULL, assoc_id, 0)) == NULL) { - /* No MME context associated */ - return -1; - } - - /* Mark the MME as overloaded and set the overload state according to - * the value received. - */ - mme_desc_p->state = S1AP_ENB_OVERLOAD; - mme_desc_p->overload_state = - ie->value.choice.OverloadResponse.choice.overloadAction; - - return 0; + s1ap_eNB_mme_data_t *mme_desc_p; + S1AP_OverloadStart_t *container; + S1AP_OverloadStartIEs_t *ie; + + DevAssert(pdu != NULL); + + container = &pdu->choice.initiatingMessage.value.choice.OverloadStart; + + S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_OverloadStartIEs_t, ie, container, + S1AP_ProtocolIE_ID_id_OverloadResponse, true); + if (ie != NULL) { + DevCheck(ie->value.choice.OverloadResponse.present == + S1AP_OverloadResponse_PR_overloadAction, + S1AP_OverloadResponse_PR_overloadAction, 0, 0); + } + /* Non UE-associated signalling -> stream 0 */ + DevCheck(stream == 0, stream, 0, 0); + + if ((mme_desc_p = s1ap_eNB_get_MME(NULL, assoc_id, 0)) == NULL) { + /* No MME context associated */ + return -1; + } + + /* Mark the MME as overloaded and set the overload state according to + * the value received. + */ + mme_desc_p->state = S1AP_ENB_OVERLOAD; + mme_desc_p->overload_state = + ie->value.choice.OverloadResponse.choice.overloadAction; + + return 0; } int s1ap_eNB_handle_overload_stop(uint32_t assoc_id, uint32_t stream, S1AP_S1AP_PDU_t *pdu) { - /* We received Overload stop message, meaning that the MME is no more - * overloaded. This is an empty message, with only message header and no - * Information Element. - */ - DevAssert(pdu != NULL); + /* We received Overload stop message, meaning that the MME is no more + * overloaded. This is an empty message, with only message header and no + * Information Element. + */ + DevAssert(pdu != NULL); - s1ap_eNB_mme_data_t *mme_desc_p; + s1ap_eNB_mme_data_t *mme_desc_p; - /* Non UE-associated signalling -> stream 0 */ - DevCheck(stream == 0, stream, 0, 0); + /* Non UE-associated signalling -> stream 0 */ + DevCheck(stream == 0, stream, 0, 0); - if ((mme_desc_p = s1ap_eNB_get_MME(NULL, assoc_id, 0)) == NULL) { - /* No MME context associated */ - return -1; - } + if ((mme_desc_p = s1ap_eNB_get_MME(NULL, assoc_id, 0)) == NULL) { + /* No MME context associated */ + return -1; + } - mme_desc_p->state = S1AP_ENB_STATE_CONNECTED; - mme_desc_p->overload_state = S1AP_NO_OVERLOAD; - return 0; + mme_desc_p->state = S1AP_ENB_STATE_CONNECTED; + mme_desc_p->overload_state = S1AP_NO_OVERLOAD; + return 0; } diff --git a/openair3/S1AP/s1ap_eNB_trace.c b/openair3/S1AP/s1ap_eNB_trace.c index 653aa98ccdd1390c965e11c018cc9d9b7db18616..6d7a6ff1a57fda8eb47f5451052fdb50daa419e1 100644 --- a/openair3/S1AP/s1ap_eNB_trace.c +++ b/openair3/S1AP/s1ap_eNB_trace.c @@ -42,107 +42,108 @@ void s1ap_eNB_generate_trace_failure(struct s1ap_eNB_ue_context_s *ue_desc_p, S1AP_E_UTRAN_Trace_ID_t *trace_id, S1AP_Cause_t *cause_p) { - S1AP_S1AP_PDU_t pdu; - S1AP_TraceFailureIndication_t *out; - S1AP_TraceFailureIndicationIEs_t *ie; - uint8_t *buffer = NULL; - uint32_t length; - - DevAssert(ue_desc_p != NULL); - DevAssert(trace_id != NULL); - DevAssert(cause_p != NULL); - - /* Prepare the S1AP message to encode */ - memset(&pdu, 0, sizeof(pdu)); - pdu.present = S1AP_S1AP_PDU_PR_initiatingMessage; - pdu.choice.initiatingMessage.procedureCode = S1AP_ProcedureCode_id_TraceFailureIndication; - pdu.choice.initiatingMessage.criticality = S1AP_Criticality_ignore; - pdu.choice.initiatingMessage.value.present = S1AP_InitiatingMessage__value_PR_TraceFailureIndication; - out = &pdu.choice.initiatingMessage.value.choice.TraceFailureIndication; - - /* mandatory */ - ie = (S1AP_TraceFailureIndicationIEs_t *)calloc(1, sizeof(S1AP_TraceFailureIndicationIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; - ie->criticality = S1AP_Criticality_reject; - ie->value.present = S1AP_TraceFailureIndicationIEs__value_PR_MME_UE_S1AP_ID; - ie->value.choice.MME_UE_S1AP_ID = ue_desc_p->mme_ue_s1ap_id; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - - /* mandatory */ - ie = (S1AP_TraceFailureIndicationIEs_t *)calloc(1, sizeof(S1AP_TraceFailureIndicationIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; - ie->criticality = S1AP_Criticality_reject; - ie->value.present = S1AP_TraceFailureIndicationIEs__value_PR_ENB_UE_S1AP_ID; - ie->value.choice.ENB_UE_S1AP_ID = ue_desc_p->eNB_ue_s1ap_id; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - - /* mandatory */ - ie = (S1AP_TraceFailureIndicationIEs_t *)calloc(1, sizeof(S1AP_TraceFailureIndicationIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_E_UTRAN_Trace_ID; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_TraceFailureIndicationIEs__value_PR_E_UTRAN_Trace_ID; - memcpy(&ie->value.choice.E_UTRAN_Trace_ID, trace_id, sizeof(S1AP_E_UTRAN_Trace_ID_t)); - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - - /* mandatory */ - ie = (S1AP_TraceFailureIndicationIEs_t *)calloc(1, sizeof(S1AP_TraceFailureIndicationIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_Cause; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_TraceFailureIndicationIEs__value_PR_Cause; - memcpy(&ie->value.choice.Cause, cause_p, sizeof(S1AP_Cause_t)); - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - - if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) { - return; - } - - s1ap_eNB_itti_send_sctp_data_req(ue_desc_p->mme_ref->s1ap_eNB_instance->instance, - ue_desc_p->mme_ref->assoc_id, buffer, - length, ue_desc_p->tx_stream); + S1AP_S1AP_PDU_t pdu; + S1AP_TraceFailureIndication_t *out; + S1AP_TraceFailureIndicationIEs_t *ie; + uint8_t *buffer = NULL; + uint32_t length; + + DevAssert(ue_desc_p != NULL); + DevAssert(trace_id != NULL); + DevAssert(cause_p != NULL); + + /* Prepare the S1AP message to encode */ + memset(&pdu, 0, sizeof(pdu)); + pdu.present = S1AP_S1AP_PDU_PR_initiatingMessage; + pdu.choice.initiatingMessage.procedureCode = S1AP_ProcedureCode_id_TraceFailureIndication; + pdu.choice.initiatingMessage.criticality = S1AP_Criticality_ignore; + pdu.choice.initiatingMessage.value.present = S1AP_InitiatingMessage__value_PR_TraceFailureIndication; + out = &pdu.choice.initiatingMessage.value.choice.TraceFailureIndication; + + /* mandatory */ + ie = (S1AP_TraceFailureIndicationIEs_t *)calloc(1, sizeof(S1AP_TraceFailureIndicationIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_TraceFailureIndicationIEs__value_PR_MME_UE_S1AP_ID; + ie->value.choice.MME_UE_S1AP_ID = ue_desc_p->mme_ue_s1ap_id; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + + /* mandatory */ + ie = (S1AP_TraceFailureIndicationIEs_t *)calloc(1, sizeof(S1AP_TraceFailureIndicationIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_TraceFailureIndicationIEs__value_PR_ENB_UE_S1AP_ID; + ie->value.choice.ENB_UE_S1AP_ID = ue_desc_p->eNB_ue_s1ap_id; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + + /* mandatory */ + ie = (S1AP_TraceFailureIndicationIEs_t *)calloc(1, sizeof(S1AP_TraceFailureIndicationIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_E_UTRAN_Trace_ID; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_TraceFailureIndicationIEs__value_PR_E_UTRAN_Trace_ID; + memcpy(&ie->value.choice.E_UTRAN_Trace_ID, trace_id, sizeof(S1AP_E_UTRAN_Trace_ID_t)); + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + + /* mandatory */ + ie = (S1AP_TraceFailureIndicationIEs_t *)calloc(1, sizeof(S1AP_TraceFailureIndicationIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_Cause; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_TraceFailureIndicationIEs__value_PR_Cause; + memcpy(&ie->value.choice.Cause, cause_p, sizeof(S1AP_Cause_t)); + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + + if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) { + return; + } + + s1ap_eNB_itti_send_sctp_data_req(ue_desc_p->mme_ref->s1ap_eNB_instance->instance, + ue_desc_p->mme_ref->assoc_id, buffer, + length, ue_desc_p->tx_stream); } int s1ap_eNB_handle_trace_start(uint32_t assoc_id, uint32_t stream, S1AP_S1AP_PDU_t *pdu) { - S1AP_TraceStart_t *container; - S1AP_TraceStartIEs_t *ie; - struct s1ap_eNB_ue_context_s *ue_desc_p; - struct s1ap_eNB_mme_data_s *mme_ref_p; - - DevAssert(pdu != NULL); - - container = &pdu->choice.initiatingMessage.value.choice.TraceStart; - - S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_TraceStartIEs_t, ie, container, - S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID, TRUE); - mme_ref_p = s1ap_eNB_get_MME(NULL, assoc_id, 0); - DevAssert(mme_ref_p != NULL); - - if ((ue_desc_p = s1ap_eNB_get_ue_context(mme_ref_p->s1ap_eNB_instance, - ie->value.choice.ENB_UE_S1AP_ID)) == NULL) { - /* Could not find context associated with this eNB_ue_s1ap_id -> generate - * trace failure indication. - */ - S1AP_E_UTRAN_Trace_ID_t trace_id; - S1AP_Cause_t cause; - memset(&trace_id, 0, sizeof(S1AP_E_UTRAN_Trace_ID_t)); - memset(&cause, 0, sizeof(S1AP_Cause_t)); - cause.present = S1AP_Cause_PR_radioNetwork; - cause.choice.radioNetwork = S1AP_CauseRadioNetwork_unknown_pair_ue_s1ap_id; - s1ap_eNB_generate_trace_failure(ue_desc_p, &trace_id, &cause); - } - - return 0; + S1AP_TraceStart_t *container; + S1AP_TraceStartIEs_t *ie; + struct s1ap_eNB_ue_context_s *ue_desc_p; + struct s1ap_eNB_mme_data_s *mme_ref_p; + + DevAssert(pdu != NULL); + + container = &pdu->choice.initiatingMessage.value.choice.TraceStart; + + S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_TraceStartIEs_t, ie, container, + S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID, TRUE); + mme_ref_p = s1ap_eNB_get_MME(NULL, assoc_id, 0); + DevAssert(mme_ref_p != NULL); + + ue_desc_p = s1ap_eNB_get_ue_context(mme_ref_p->s1ap_eNB_instance, + ie->value.choice.ENB_UE_S1AP_ID); + if (ue_desc_p == NULL) { + /* Could not find context associated with this eNB_ue_s1ap_id -> generate + * trace failure indication. + */ + S1AP_E_UTRAN_Trace_ID_t trace_id; + S1AP_Cause_t cause; + memset(&trace_id, 0, sizeof(S1AP_E_UTRAN_Trace_ID_t)); + memset(&cause, 0, sizeof(S1AP_Cause_t)); + cause.present = S1AP_Cause_PR_radioNetwork; + cause.choice.radioNetwork = S1AP_CauseRadioNetwork_unknown_pair_ue_s1ap_id; + s1ap_eNB_generate_trace_failure(NULL, &trace_id, &cause); + } + + return 0; } int s1ap_eNB_handle_deactivate_trace(uint32_t assoc_id, uint32_t stream, S1AP_S1AP_PDU_t *message_p) { - // S1AP_DeactivateTraceIEs_t *deactivate_trace_p; - // - // deactivate_trace_p = &message_p->msg.deactivateTraceIEs; + // S1AP_DeactivateTraceIEs_t *deactivate_trace_p; + // + // deactivate_trace_p = &message_p->msg.deactivateTraceIEs; - return 0; + return 0; } diff --git a/openair3/SCTP/sctp_eNB_task.c b/openair3/SCTP/sctp_eNB_task.c index e7265d66d6485c25e74f5cf128e0a89e932001f8..b0c18c36923b1e9a65e3c548258d8de1de024cb7 100644 --- a/openair3/SCTP/sctp_eNB_task.c +++ b/openair3/SCTP/sctp_eNB_task.c @@ -59,33 +59,33 @@ enum sctp_connection_type_e { - SCTP_TYPE_CLIENT, - SCTP_TYPE_SERVER, - SCTP_TYPE_MULTI_SERVER, - SCTP_TYPE_MAX + SCTP_TYPE_CLIENT, + SCTP_TYPE_SERVER, + SCTP_TYPE_MULTI_SERVER, + SCTP_TYPE_MAX }; typedef struct sctp_cnx_list_elm_s { - STAILQ_ENTRY(sctp_cnx_list_elm_s) entries; - - /* Type of this association - */ - enum sctp_connection_type_e connection_type; - - int sd; ///< Socket descriptor of connection */ - uint16_t local_port; - uint16_t in_streams; ///< Number of input streams negociated for this connection - uint16_t out_streams; ///< Number of output streams negotiated for this connection - uint16_t ppid; ///< Payload protocol Identifier - int32_t assoc_id; ///< SCTP association id for the connection (note4debug host byte order) - uint32_t messages_recv; ///< Number of messages received on this connection - uint32_t messages_sent; ///< Number of messages sent on this connection - task_id_t task_id; ///< Task id of the task who asked for this connection - instance_t instance; ///< Instance - uint16_t cnx_id; ///< Upper layer identifier - - struct sockaddr *peer_addresses;///< A list of peer addresses for server socket - int nb_peer_addresses; ///< For server socket + STAILQ_ENTRY(sctp_cnx_list_elm_s) entries; + + /* Type of this association + */ + enum sctp_connection_type_e connection_type; + + int sd; ///< Socket descriptor of connection */ + uint16_t local_port; + uint16_t in_streams; ///< Number of input streams negociated for this connection + uint16_t out_streams; ///< Number of output streams negotiated for this connection + uint16_t ppid; ///< Payload protocol Identifier + int32_t assoc_id; ///< SCTP association id for the connection (note4debug host byte order) + uint32_t messages_recv; ///< Number of messages received on this connection + uint32_t messages_sent; ///< Number of messages sent on this connection + task_id_t task_id; ///< Task id of the task who asked for this connection + instance_t instance; ///< Instance + uint16_t cnx_id; ///< Upper layer identifier + + struct sockaddr *peer_addresses;///< A list of peer addresses for server socket + int nb_peer_addresses; ///< For server socket } sctp_cnx_list_elm_t; @@ -95,962 +95,965 @@ static uint16_t sctp_nb_cnx = 0; //------------------------------------------------------------------------------ struct sctp_cnx_list_elm_s *sctp_get_cnx(int32_t assoc_id, int sd) { - struct sctp_cnx_list_elm_s *elm; + struct sctp_cnx_list_elm_s *elm; - STAILQ_FOREACH(elm, &sctp_cnx_list, entries) { - if (assoc_id != -1) { - if (elm->assoc_id == assoc_id) { - return elm; - } - } else { - if (elm->sd == sd) { - return elm; - } + STAILQ_FOREACH(elm, &sctp_cnx_list, entries) { + if (assoc_id != -1) { + if (elm->assoc_id == assoc_id) { + return elm; + } + } else { + if (elm->sd == sd) { + return elm; + } + } } - } - return NULL; + return NULL; } //------------------------------------------------------------------------------ static inline void sctp_eNB_accept_associations_multi( - struct sctp_cnx_list_elm_s *sctp_cnx) + struct sctp_cnx_list_elm_s *sctp_cnx) { - int ns; - int n; - int flags = 0; - socklen_t from_len; - struct sctp_sndrcvinfo sinfo; + int ns; + int n; + int flags = 0; + socklen_t from_len; + struct sctp_sndrcvinfo sinfo; - struct sockaddr_in addr; - uint8_t buffer[SCTP_RECV_BUFFER_SIZE]; + struct sockaddr_in addr; + uint8_t buffer[SCTP_RECV_BUFFER_SIZE]; - DevAssert(sctp_cnx != NULL); + DevAssert(sctp_cnx != NULL); - memset((void *)&addr, 0, sizeof(struct sockaddr_in)); - from_len = (socklen_t)sizeof(struct sockaddr_in); - memset((void *)&sinfo, 0, sizeof(struct sctp_sndrcvinfo)); + memset((void *)&addr, 0, sizeof(struct sockaddr_in)); + from_len = (socklen_t)sizeof(struct sockaddr_in); + memset((void *)&sinfo, 0, sizeof(struct sctp_sndrcvinfo)); - n = sctp_recvmsg(sctp_cnx->sd, (void *)buffer, SCTP_RECV_BUFFER_SIZE, - (struct sockaddr *)&addr, &from_len, - &sinfo, &flags); + n = sctp_recvmsg(sctp_cnx->sd, (void *)buffer, SCTP_RECV_BUFFER_SIZE, + (struct sockaddr *)&addr, &from_len, + &sinfo, &flags); - if (n < 0) { - if (errno == ENOTCONN) { - SCTP_DEBUG("Received not connected for sd %d\n", sctp_cnx->sd); - close(sctp_cnx->sd); - } else { - SCTP_DEBUG("An error occured during read\n"); - SCTP_ERROR("sctp_recvmsg (fd %d, len %d ): %s:%d\n", sctp_cnx->sd, n, strerror(errno), errno); + if (n < 0) { + if (errno == ENOTCONN) { + SCTP_DEBUG("Received not connected for sd %d\n", sctp_cnx->sd); + close(sctp_cnx->sd); + } else { + SCTP_DEBUG("An error occured during read\n"); + SCTP_ERROR("sctp_recvmsg (fd %d, len %d ): %s:%d\n", sctp_cnx->sd, n, strerror(errno), errno); + } + return; } - return; - } - if (flags & MSG_NOTIFICATION) { - union sctp_notification *snp; - snp = (union sctp_notification *)buffer; + if (flags & MSG_NOTIFICATION) { + union sctp_notification *snp; + snp = (union sctp_notification *)buffer; - SCTP_DEBUG("Received notification for sd %d, type %u\n", - sctp_cnx->sd, snp->sn_header.sn_type); + SCTP_DEBUG("Received notification for sd %d, type %u\n", + sctp_cnx->sd, snp->sn_header.sn_type); - /* Association has changed. */ - if (SCTP_ASSOC_CHANGE == snp->sn_header.sn_type) { - struct sctp_assoc_change *sctp_assoc_changed; - sctp_assoc_changed = &snp->sn_assoc_change; + /* Association has changed. */ + if (SCTP_ASSOC_CHANGE == snp->sn_header.sn_type) { + struct sctp_assoc_change *sctp_assoc_changed; + sctp_assoc_changed = &snp->sn_assoc_change; - SCTP_DEBUG("Client association changed: %d\n", sctp_assoc_changed->sac_state); + SCTP_DEBUG("Client association changed: %d\n", sctp_assoc_changed->sac_state); - /* New physical association requested by a peer */ - switch (sctp_assoc_changed->sac_state) { - case SCTP_COMM_UP: { - SCTP_DEBUG("Comm up notified for sd %d, assigned assoc_id %d\n", - sctp_cnx->sd, sctp_assoc_changed->sac_assoc_id); - struct sctp_cnx_list_elm_s *new_cnx; + /* New physical association requested by a peer */ + switch (sctp_assoc_changed->sac_state) { + case SCTP_COMM_UP: { + SCTP_DEBUG("Comm up notified for sd %d, assigned assoc_id %d\n", + sctp_cnx->sd, sctp_assoc_changed->sac_assoc_id); + struct sctp_cnx_list_elm_s *new_cnx; - new_cnx = calloc(1, sizeof(*sctp_cnx)); + new_cnx = calloc(1, sizeof(*sctp_cnx)); - DevAssert(new_cnx != NULL); + DevAssert(new_cnx != NULL); - new_cnx->connection_type = SCTP_TYPE_CLIENT; + new_cnx->connection_type = SCTP_TYPE_CLIENT; - ns = sctp_peeloff(sctp_cnx->sd, sctp_assoc_changed->sac_assoc_id); + ns = sctp_peeloff(sctp_cnx->sd, sctp_assoc_changed->sac_assoc_id); - new_cnx->sd = ns; - new_cnx->task_id = sctp_cnx->task_id; - new_cnx->cnx_id = 0; - new_cnx->ppid = sctp_cnx->ppid; - new_cnx->instance = sctp_cnx->instance; - new_cnx->local_port = sctp_cnx->local_port; - new_cnx->assoc_id = sctp_assoc_changed->sac_assoc_id; + new_cnx->sd = ns; + new_cnx->task_id = sctp_cnx->task_id; + new_cnx->cnx_id = 0; + new_cnx->ppid = sctp_cnx->ppid; + new_cnx->instance = sctp_cnx->instance; + new_cnx->local_port = sctp_cnx->local_port; + new_cnx->assoc_id = sctp_assoc_changed->sac_assoc_id; - if (sctp_get_sockinfo(ns, &new_cnx->in_streams, &new_cnx->out_streams, - &new_cnx->assoc_id) != 0) { - SCTP_ERROR("sctp_get_sockinfo failed\n"); - close(ns); - free(new_cnx); - return; - } + if (sctp_get_sockinfo(ns, &new_cnx->in_streams, &new_cnx->out_streams, + &new_cnx->assoc_id) != 0) { + SCTP_ERROR("sctp_get_sockinfo failed\n"); + close(ns); + free(new_cnx); + return; + } - /* Insert new element at end of list */ - STAILQ_INSERT_TAIL(&sctp_cnx_list, new_cnx, entries); - sctp_nb_cnx++; + /* Insert new element at end of list */ + STAILQ_INSERT_TAIL(&sctp_cnx_list, new_cnx, entries); + sctp_nb_cnx++; - /* Add the socket to list of fd monitored by ITTI */ - itti_subscribe_event_fd(TASK_SCTP, ns); + /* Add the socket to list of fd monitored by ITTI */ + itti_subscribe_event_fd(TASK_SCTP, ns); - sctp_itti_send_association_ind(new_cnx->task_id, new_cnx->instance, - new_cnx->assoc_id, new_cnx->local_port, - new_cnx->out_streams, new_cnx->in_streams); - } - break; + sctp_itti_send_association_ind(new_cnx->task_id, new_cnx->instance, + new_cnx->assoc_id, new_cnx->local_port, + new_cnx->out_streams, new_cnx->in_streams); + } + break; - default: - break; - } + default: + break; + } + } + } else { + SCTP_DEBUG("No notification from SCTP\n"); } - } else { - SCTP_DEBUG("No notification from SCTP\n"); - } } //------------------------------------------------------------------------------ void sctp_handle_new_association_req_multi( - const instance_t instance, - const task_id_t requestor, - const sctp_new_association_req_multi_t * const sctp_new_association_req_p) + const instance_t instance, + const task_id_t requestor, + const sctp_new_association_req_multi_t * const sctp_new_association_req_p) { - int ns; - int sd; + int ns; + int sd; - int32_t assoc_id = 0; + int32_t assoc_id = 0; - struct sctp_cnx_list_elm_s *sctp_cnx = NULL; - enum sctp_connection_type_e connection_type = SCTP_TYPE_CLIENT; + struct sctp_cnx_list_elm_s *sctp_cnx = NULL; + enum sctp_connection_type_e connection_type = SCTP_TYPE_CLIENT; - /* Prepare a new SCTP association as requested by upper layer and try to connect - * to remote host. - */ - DevAssert(sctp_new_association_req_p != NULL); + /* Prepare a new SCTP association as requested by upper layer and try to connect + * to remote host. + */ + DevAssert(sctp_new_association_req_p != NULL); - sd = sctp_new_association_req_p->multi_sd; + sd = sctp_new_association_req_p->multi_sd; - /* Create new socket with IPv6 affinity */ + /* Create new socket with IPv6 affinity */ //#warning "SCTP may Force IPv4 only, here" - /* Mark the socket as non-blocking */ - //if (fcntl(sd, F_SETFL, O_NONBLOCK) < 0) { + /* Mark the socket as non-blocking */ + //if (fcntl(sd, F_SETFL, O_NONBLOCK) < 0) { //SCTP_ERROR("fcntl F_SETFL O_NONBLOCK failed: %s\n", - // strerror(errno)); + // strerror(errno)); //close(sd); //return; - //} - - /* SOCK_STREAM socket type requires an explicit connect to the remote host - * address and port. - * Only use IPv4 for the first connection attempt - */ - if ((sctp_new_association_req_p->remote_address.ipv6 != 0) || - (sctp_new_association_req_p->remote_address.ipv4 != 0)) { - uint8_t address_index = 0; - uint8_t used_address = sctp_new_association_req_p->remote_address.ipv6 + - sctp_new_association_req_p->remote_address.ipv4; - struct sockaddr_in addr[used_address]; - - memset(addr, 0, used_address * sizeof(struct sockaddr_in)); - - if (sctp_new_association_req_p->remote_address.ipv6 == 1) { - if (inet_pton(AF_INET6, sctp_new_association_req_p->remote_address.ipv6_address, - &addr[address_index].sin_addr.s_addr) != 1) { - SCTP_ERROR("Failed to convert ipv6 address %*s to network type\n", - (int)strlen(sctp_new_association_req_p->remote_address.ipv6_address), - sctp_new_association_req_p->remote_address.ipv6_address); - //close(sd); - //return; - exit(1); - } - - SCTP_DEBUG("Converted ipv6 address %*s to network type\n", - (int)strlen(sctp_new_association_req_p->remote_address.ipv6_address), - sctp_new_association_req_p->remote_address.ipv6_address); - - addr[address_index].sin_family = AF_INET6; - addr[address_index].sin_port = htons(sctp_new_association_req_p->port); - address_index++; - } + //} - if (sctp_new_association_req_p->remote_address.ipv4 == 1) { - if (inet_pton(AF_INET, sctp_new_association_req_p->remote_address.ipv4_address, - &addr[address_index].sin_addr.s_addr) != 1) { - SCTP_ERROR("Failed to convert ipv4 address %*s to network type\n", - (int)strlen(sctp_new_association_req_p->remote_address.ipv4_address), - sctp_new_association_req_p->remote_address.ipv4_address); - //close(sd); - //return; - exit(1); - } - - SCTP_DEBUG("Converted ipv4 address %*s to network type\n", - (int)strlen(sctp_new_association_req_p->remote_address.ipv4_address), - sctp_new_association_req_p->remote_address.ipv4_address); - - addr[address_index].sin_family = AF_INET; - addr[address_index].sin_port = htons(sctp_new_association_req_p->port); - address_index++; - } + /* SOCK_STREAM socket type requires an explicit connect to the remote host + * address and port. + * Only use IPv4 for the first connection attempt + */ + if ((sctp_new_association_req_p->remote_address.ipv6 != 0) || + (sctp_new_association_req_p->remote_address.ipv4 != 0)) { + uint8_t address_index = 0; + uint8_t used_address = sctp_new_association_req_p->remote_address.ipv6 + + sctp_new_association_req_p->remote_address.ipv4; + struct sockaddr_in addr[used_address]; + + memset(addr, 0, used_address * sizeof(struct sockaddr_in)); + + if (sctp_new_association_req_p->remote_address.ipv6 == 1) { + if (inet_pton(AF_INET6, sctp_new_association_req_p->remote_address.ipv6_address, + &addr[address_index].sin_addr.s_addr) != 1) { + SCTP_ERROR("Failed to convert ipv6 address %*s to network type\n", + (int)strlen(sctp_new_association_req_p->remote_address.ipv6_address), + sctp_new_association_req_p->remote_address.ipv6_address); + //close(sd); + //return; + exit(1); + } + + SCTP_DEBUG("Converted ipv6 address %*s to network type\n", + (int)strlen(sctp_new_association_req_p->remote_address.ipv6_address), + sctp_new_association_req_p->remote_address.ipv6_address); + + addr[address_index].sin_family = AF_INET6; + addr[address_index].sin_port = htons(sctp_new_association_req_p->port); + address_index++; + } - /* Connect to remote host and port */ - if (sctp_connectx(sd, (struct sockaddr *)addr, 1, &assoc_id) < 0) { - /* sctp_connectx on non-blocking socket return EINPROGRESS */ - if (errno != EINPROGRESS) { - SCTP_ERROR("Connect failed: %s\n", strerror(errno)); - sctp_itti_send_association_resp( - requestor, instance, -1, sctp_new_association_req_p->ulp_cnx_id, - SCTP_STATE_UNREACHABLE, 0, 0); - /* Add the socket to list of fd monitored by ITTI */ - //itti_unsubscribe_event_fd(TASK_SCTP, sd); - //close(sd); - return; - } else { - SCTP_DEBUG("connectx assoc_id %d in progress..., used %d addresses\n", - assoc_id, used_address); - } - } else { - SCTP_DEBUG("sctp_connectx SUCCESS, used %d addresses assoc_id %d\n", - used_address, - assoc_id); + if (sctp_new_association_req_p->remote_address.ipv4 == 1) { + if (inet_pton(AF_INET, sctp_new_association_req_p->remote_address.ipv4_address, + &addr[address_index].sin_addr.s_addr) != 1) { + SCTP_ERROR("Failed to convert ipv4 address %*s to network type\n", + (int)strlen(sctp_new_association_req_p->remote_address.ipv4_address), + sctp_new_association_req_p->remote_address.ipv4_address); + //close(sd); + //return; + exit(1); + } + + SCTP_DEBUG("Converted ipv4 address %*s to network type\n", + (int)strlen(sctp_new_association_req_p->remote_address.ipv4_address), + sctp_new_association_req_p->remote_address.ipv4_address); + + addr[address_index].sin_family = AF_INET; + addr[address_index].sin_port = htons(sctp_new_association_req_p->port); + address_index++; + } + + /* Connect to remote host and port */ + if (sctp_connectx(sd, (struct sockaddr *)addr, 1, &assoc_id) < 0) { + /* sctp_connectx on non-blocking socket return EINPROGRESS */ + if (errno != EINPROGRESS) { + SCTP_ERROR("Connect failed: %s\n", strerror(errno)); + sctp_itti_send_association_resp( + requestor, instance, -1, sctp_new_association_req_p->ulp_cnx_id, + SCTP_STATE_UNREACHABLE, 0, 0); + /* Add the socket to list of fd monitored by ITTI */ + //itti_unsubscribe_event_fd(TASK_SCTP, sd); + //close(sd); + return; + } else { + SCTP_DEBUG("connectx assoc_id %d in progress..., used %d addresses\n", + assoc_id, used_address); + } + } else { + SCTP_DEBUG("sctp_connectx SUCCESS, used %d addresses assoc_id %d\n", + used_address, + assoc_id); + } } - } - ns = sctp_peeloff(sd,assoc_id); + ns = sctp_peeloff(sd,assoc_id); - sctp_cnx = calloc(1, sizeof(*sctp_cnx)); + sctp_cnx = calloc(1, sizeof(*sctp_cnx)); - sctp_cnx->connection_type = connection_type; + sctp_cnx->connection_type = connection_type; - sctp_cnx->sd = ns; - sctp_cnx->task_id = requestor; - sctp_cnx->cnx_id = sctp_new_association_req_p->ulp_cnx_id; - sctp_cnx->ppid = sctp_new_association_req_p->ppid; - sctp_cnx->instance = instance; - sctp_cnx->assoc_id = assoc_id; + sctp_cnx->sd = ns; + sctp_cnx->task_id = requestor; + sctp_cnx->cnx_id = sctp_new_association_req_p->ulp_cnx_id; + sctp_cnx->ppid = sctp_new_association_req_p->ppid; + sctp_cnx->instance = instance; + sctp_cnx->assoc_id = assoc_id; - /* Add the socket to list of fd monitored by ITTI */ - itti_subscribe_event_fd(TASK_SCTP, ns); + /* Add the socket to list of fd monitored by ITTI */ + itti_subscribe_event_fd(TASK_SCTP, ns); - /* Insert new element at end of list */ - STAILQ_INSERT_TAIL(&sctp_cnx_list, sctp_cnx, entries); - sctp_nb_cnx++; + /* Insert new element at end of list */ + STAILQ_INSERT_TAIL(&sctp_cnx_list, sctp_cnx, entries); + sctp_nb_cnx++; - SCTP_DEBUG("Inserted new descriptor for sd %d in list, nb elements %u, assoc_id %d\n", - ns, sctp_nb_cnx, assoc_id); + SCTP_DEBUG("Inserted new descriptor for sd %d in list, nb elements %u, assoc_id %d\n", + ns, sctp_nb_cnx, assoc_id); } //------------------------------------------------------------------------------ void sctp_handle_new_association_req( - const instance_t instance, - const task_id_t requestor, - const sctp_new_association_req_t * const sctp_new_association_req_p) + const instance_t instance, + const task_id_t requestor, + const sctp_new_association_req_t * const sctp_new_association_req_p) { - int sd = 0; - int32_t assoc_id = 0; - - struct sctp_event_subscribe events; - - struct sctp_cnx_list_elm_s *sctp_cnx = NULL; - enum sctp_connection_type_e connection_type = SCTP_TYPE_CLIENT; - - struct ifreq ifr; - struct ifaddrs *ifaddr = NULL; - struct ifaddrs *ifa = NULL; - int family = 0; - int s = 0; - struct in_addr in; - struct in6_addr in6; - /* Prepare a new SCTP association as requested by upper layer and try to connect - * to remote host. - */ - DevAssert(sctp_new_association_req_p != NULL); - - /* Create new socket with IPv6 affinity */ + int sd = 0; + int32_t assoc_id = 0; + + struct sctp_event_subscribe events; + + struct sctp_cnx_list_elm_s *sctp_cnx = NULL; + enum sctp_connection_type_e connection_type = SCTP_TYPE_CLIENT; + + struct ifreq ifr; + struct ifaddrs *ifaddr = NULL; + struct ifaddrs *ifa = NULL; + int family = 0; + int s = 0; + struct in_addr in; + struct in6_addr in6; + /* Prepare a new SCTP association as requested by upper layer and try to connect + * to remote host. + */ + DevAssert(sctp_new_association_req_p != NULL); + + /* Create new socket with IPv6 affinity */ //#warning "SCTP may Force IPv4 only, here" #ifdef NO_VIRTUAL_MACHINE - // in init chunk appears a list of host addresses, IPv4 and IPv4 in an arbitrary (unsorted) order - // SCTP hearbeats starts with first ipv4 addresses then stop triyng with other ipv4 addresses - // if it encounters an IPv6 address in list, so we can force the building of IPv4 addresses only - // with AF_INET (the working IPv4 address can be the last in the list...) - if ((sd = socket(AF_INET6, SOCK_STREAM, IPPROTO_SCTP)) < 0) { + // in init chunk appears a list of host addresses, IPv4 and IPv4 in an arbitrary (unsorted) order + // SCTP hearbeats starts with first ipv4 addresses then stop triyng with other ipv4 addresses + // if it encounters an IPv6 address in list, so we can force the building of IPv4 addresses only + // with AF_INET (the working IPv4 address can be the last in the list...) + if ((sd = socket(AF_INET6, SOCK_STREAM, IPPROTO_SCTP)) < 0) { #else - if ((sd = socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP)) < 0) { + if ((sd = socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP)) < 0) { #endif - SCTP_ERROR("Socket creation failed: %s\n", strerror(errno)); - return; - } - - /* Add the socket to list of fd monitored by ITTI */ - itti_subscribe_event_fd(TASK_SCTP, sd); - - if (sctp_set_init_opt(sd, - sctp_new_association_req_p->in_streams, - sctp_new_association_req_p->out_streams, - SCTP_MAX_ATTEMPTS, SCTP_TIMEOUT) != 0) { - SCTP_ERROR("Setsockopt IPPROTO_SCTP_INITMSG failed: %s\n", - strerror(errno)); - itti_unsubscribe_event_fd(TASK_SCTP, sd); - close(sd); - return; - } - - /* Subscribe to all events */ - memset((void *)&events, 1, sizeof(struct sctp_event_subscribe)); - - if (setsockopt(sd, IPPROTO_SCTP, SCTP_EVENTS, &events, - sizeof(struct sctp_event_subscribe)) < 0) { - SCTP_ERROR("Setsockopt IPPROTO_SCTP_EVENTS failed: %s\n", - strerror(errno)); - close(sd); - return; - } - - // Bind to device ... or we could bind to address also - if (getifaddrs(&ifaddr) == -1) { - SCTP_ERROR("getifaddrs failed: %s\n", strerror(errno)); - close(sd); - } - - /* Walk through linked list, maintaining head pointer so we - can free list later */ - for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) { - if (ifa->ifa_addr == NULL) - continue; - - family = ifa->ifa_addr->sa_family; - - /* For an AF_INET* interface address, display the address */ - if (sctp_new_association_req_p->local_address.ipv4 && family == AF_INET) { - // compare address - s = inet_aton(sctp_new_association_req_p->local_address.ipv4_address, - &in); - - if (s > 0 ) { - if (((struct sockaddr_in*)ifa->ifa_addr)->sin_addr.s_addr == in.s_addr) { - struct sockaddr_in locaddr; - locaddr.sin_family = AF_INET; - locaddr.sin_port = htons(sctp_new_association_req_p->port); - locaddr.sin_addr.s_addr = in.s_addr; - - if (sctp_bindx(sd, (struct sockaddr*)&locaddr, 1, SCTP_BINDX_ADD_ADDR) < 0) { - SCTP_ERROR("sctp_bindx SCTP_BINDX_ADD_ADDR failed: %s\n", - strerror(errno)); - } else { - SCTP_DEBUG("sctp_bindx SCTP_BINDX_ADD_ADDR socket bound to : %s\n", - inet_ntoa(locaddr.sin_addr)); - } - break; - - } - } - } else if (sctp_new_association_req_p->local_address.ipv6 && family == AF_INET6) { - // compare address - s = inet_pton(AF_INET6, - sctp_new_association_req_p->local_address.ipv6_address, - &in6); - - if (s == 1 ) { - if (memcmp(&((struct sockaddr_in6*)ifa->ifa_addr)->sin6_addr, - &in6, sizeof(in6)) == 0) { - memset(&ifr, 0, sizeof(ifr)); - snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s", ifa->ifa_name); - - if (setsockopt(sd, SOL_SOCKET, SO_BINDTODEVICE, (void *)&ifr, sizeof(ifr)) < 0) { - SCTP_ERROR("Setsockopt SOL_SOCKET failed: %s\n", - strerror(errno)); - } else { - SCTP_DEBUG("Setsockopt SOL_SOCKET socket bound to : %s\n", - ifa->ifa_name); - } - - break; - } - } + SCTP_ERROR("Socket creation failed: %s\n", strerror(errno)); + return; } - } - - freeifaddrs(ifaddr); - - /* Mark the socket as non-blocking */ - if (fcntl(sd, F_SETFL, O_NONBLOCK) < 0) { - SCTP_ERROR("fcntl F_SETFL O_NONBLOCK failed: %s\n", - strerror(errno)); - close(sd); - return; - } - - /* SOCK_STREAM socket type requires an explicit connect to the remote host - * address and port. - * Only use IPv4 for the first connection attempt - */ - if ((sctp_new_association_req_p->remote_address.ipv6 != 0) || - (sctp_new_association_req_p->remote_address.ipv4 != 0)) { - uint8_t address_index = 0; - uint8_t used_address = sctp_new_association_req_p->remote_address.ipv6 + - sctp_new_association_req_p->remote_address.ipv4; - struct sockaddr_in addr[used_address]; - - memset(addr, 0, used_address * sizeof(struct sockaddr_in)); - - if (sctp_new_association_req_p->remote_address.ipv6 == 1) { - if (inet_pton(AF_INET6, sctp_new_association_req_p->remote_address.ipv6_address, - &addr[address_index].sin_addr.s_addr) != 1) { - SCTP_ERROR("Failed to convert ipv6 address %*s to network type\n", - (int)strlen(sctp_new_association_req_p->remote_address.ipv6_address), - sctp_new_association_req_p->remote_address.ipv6_address); + + /* Add the socket to list of fd monitored by ITTI */ + itti_subscribe_event_fd(TASK_SCTP, sd); + + if (sctp_set_init_opt(sd, + sctp_new_association_req_p->in_streams, + sctp_new_association_req_p->out_streams, + SCTP_MAX_ATTEMPTS, SCTP_TIMEOUT) != 0) { + SCTP_ERROR("Setsockopt IPPROTO_SCTP_INITMSG failed: %s\n", + strerror(errno)); + itti_unsubscribe_event_fd(TASK_SCTP, sd); close(sd); return; - } - - SCTP_DEBUG("Converted ipv6 address %*s to network type\n", - (int)strlen(sctp_new_association_req_p->remote_address.ipv6_address), - sctp_new_association_req_p->remote_address.ipv6_address); - - addr[address_index].sin_family = AF_INET6; - addr[address_index].sin_port = htons(sctp_new_association_req_p->port); - address_index++; } - if (sctp_new_association_req_p->remote_address.ipv4 == 1) { - if (inet_pton(AF_INET, sctp_new_association_req_p->remote_address.ipv4_address, - &addr[address_index].sin_addr.s_addr) != 1) { - SCTP_ERROR("Failed to convert ipv4 address %*s to network type\n", - (int)strlen(sctp_new_association_req_p->remote_address.ipv4_address), - sctp_new_association_req_p->remote_address.ipv4_address); + /* Subscribe to all events */ + memset((void *)&events, 1, sizeof(struct sctp_event_subscribe)); + + if (setsockopt(sd, IPPROTO_SCTP, SCTP_EVENTS, &events, + sizeof(struct sctp_event_subscribe)) < 0) { + SCTP_ERROR("Setsockopt IPPROTO_SCTP_EVENTS failed: %s\n", + strerror(errno)); close(sd); return; - } + } - SCTP_DEBUG("Converted ipv4 address %*s to network type\n", - (int)strlen(sctp_new_association_req_p->remote_address.ipv4_address), - sctp_new_association_req_p->remote_address.ipv4_address); + // Bind to device ... or we could bind to address also + if (getifaddrs(&ifaddr) == -1) { + SCTP_ERROR("getifaddrs failed: %s\n", strerror(errno)); + close(sd); + } - addr[address_index].sin_family = AF_INET; - addr[address_index].sin_port = htons(sctp_new_association_req_p->port); - address_index++; + /* Walk through linked list, maintaining head pointer so we + can free list later */ + for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) { + if (ifa->ifa_addr == NULL) + continue; + + family = ifa->ifa_addr->sa_family; + + /* For an AF_INET* interface address, display the address */ + if (sctp_new_association_req_p->local_address.ipv4 && family == AF_INET) { + // compare address + s = inet_aton(sctp_new_association_req_p->local_address.ipv4_address, + &in); + + if (s > 0 ) { + if (((struct sockaddr_in*)ifa->ifa_addr)->sin_addr.s_addr == in.s_addr) { + struct sockaddr_in locaddr; + locaddr.sin_family = AF_INET; + locaddr.sin_port = htons(sctp_new_association_req_p->port); + locaddr.sin_addr.s_addr = in.s_addr; + + if (sctp_bindx(sd, (struct sockaddr*)&locaddr, 1, SCTP_BINDX_ADD_ADDR) < 0) { + SCTP_ERROR("sctp_bindx SCTP_BINDX_ADD_ADDR failed: %s\n", + strerror(errno)); + } else { + SCTP_DEBUG("sctp_bindx SCTP_BINDX_ADD_ADDR socket bound to : %s\n", + inet_ntoa(locaddr.sin_addr)); + } + break; + + } + } + } else if (sctp_new_association_req_p->local_address.ipv6 && family == AF_INET6) { + // compare address + s = inet_pton(AF_INET6, + sctp_new_association_req_p->local_address.ipv6_address, + &in6); + + if (s == 1 ) { + if (memcmp(&((struct sockaddr_in6*)ifa->ifa_addr)->sin6_addr, + &in6, sizeof(in6)) == 0) { + memset(&ifr, 0, sizeof(ifr)); + snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s", ifa->ifa_name); + + if (setsockopt(sd, SOL_SOCKET, SO_BINDTODEVICE, (void *)&ifr, sizeof(ifr)) < 0) { + SCTP_ERROR("Setsockopt SOL_SOCKET failed: %s\n", + strerror(errno)); + } else { + SCTP_DEBUG("Setsockopt SOL_SOCKET socket bound to : %s\n", + ifa->ifa_name); + } + + break; + } + } + } } - /* Connect to remote host and port */ - if (sctp_connectx(sd, (struct sockaddr *)addr, 1, &assoc_id) < 0) { - /* sctp_connectx on non-blocking socket return EINPROGRESS */ - if (errno != EINPROGRESS) { - SCTP_ERROR("Connect failed: %s\n", strerror(errno)); - sctp_itti_send_association_resp( - requestor, instance, -1, sctp_new_association_req_p->ulp_cnx_id, - SCTP_STATE_UNREACHABLE, 0, 0); - /* Add the socket to list of fd monitored by ITTI */ - itti_unsubscribe_event_fd(TASK_SCTP, sd); + freeifaddrs(ifaddr); + + /* Mark the socket as non-blocking */ + if (fcntl(sd, F_SETFL, O_NONBLOCK) < 0) { + SCTP_ERROR("fcntl F_SETFL O_NONBLOCK failed: %s\n", + strerror(errno)); close(sd); return; - } else { - SCTP_DEBUG("connectx assoc_id %d in progress..., used %d addresses\n", - assoc_id, used_address); - } - } else { - SCTP_DEBUG("sctp_connectx SUCCESS, used %d addresses assoc_id %d\n", - used_address, - assoc_id); } - } else { - /* No remote address provided -> only bind the socket for now. - * Connection will be accepted in the main event loop + + /* SOCK_STREAM socket type requires an explicit connect to the remote host + * address and port. + * Only use IPv4 for the first connection attempt */ - struct sockaddr_in6 addr6; + if ((sctp_new_association_req_p->remote_address.ipv6 != 0) || + (sctp_new_association_req_p->remote_address.ipv4 != 0)) { + uint8_t address_index = 0; + uint8_t used_address = sctp_new_association_req_p->remote_address.ipv6 + + sctp_new_association_req_p->remote_address.ipv4; + struct sockaddr_in addr[used_address]; + + memset(addr, 0, used_address * sizeof(struct sockaddr_in)); + + if (sctp_new_association_req_p->remote_address.ipv6 == 1) { + if (inet_pton(AF_INET6, sctp_new_association_req_p->remote_address.ipv6_address, + &addr[address_index].sin_addr.s_addr) != 1) { + SCTP_ERROR("Failed to convert ipv6 address %*s to network type\n", + (int)strlen(sctp_new_association_req_p->remote_address.ipv6_address), + sctp_new_association_req_p->remote_address.ipv6_address); + close(sd); + return; + } + + SCTP_DEBUG("Converted ipv6 address %*s to network type\n", + (int)strlen(sctp_new_association_req_p->remote_address.ipv6_address), + sctp_new_association_req_p->remote_address.ipv6_address); + + addr[address_index].sin_family = AF_INET6; + addr[address_index].sin_port = htons(sctp_new_association_req_p->port); + address_index++; + } - connection_type = SCTP_TYPE_SERVER; + if (sctp_new_association_req_p->remote_address.ipv4 == 1) { + if (inet_pton(AF_INET, sctp_new_association_req_p->remote_address.ipv4_address, + &addr[address_index].sin_addr.s_addr) != 1) { + SCTP_ERROR("Failed to convert ipv4 address %*s to network type\n", + (int)strlen(sctp_new_association_req_p->remote_address.ipv4_address), + sctp_new_association_req_p->remote_address.ipv4_address); + close(sd); + return; + } + + SCTP_DEBUG("Converted ipv4 address %*s to network type\n", + (int)strlen(sctp_new_association_req_p->remote_address.ipv4_address), + sctp_new_association_req_p->remote_address.ipv4_address); + + addr[address_index].sin_family = AF_INET; + addr[address_index].sin_port = htons(sctp_new_association_req_p->port); + address_index++; + } - /* For now bind to any interface */ - addr6.sin6_family = AF_INET6; - addr6.sin6_addr = in6addr_any; - addr6.sin6_port = htons(sctp_new_association_req_p->port); + /* Connect to remote host and port */ + if (sctp_connectx(sd, (struct sockaddr *)addr, 1, &assoc_id) < 0) { + /* sctp_connectx on non-blocking socket return EINPROGRESS */ + if (errno != EINPROGRESS) { + SCTP_ERROR("Connect failed: %s\n", strerror(errno)); + sctp_itti_send_association_resp( + requestor, instance, -1, sctp_new_association_req_p->ulp_cnx_id, + SCTP_STATE_UNREACHABLE, 0, 0); + /* Add the socket to list of fd monitored by ITTI */ + itti_unsubscribe_event_fd(TASK_SCTP, sd); + close(sd); + return; + } else { + SCTP_DEBUG("connectx assoc_id %d in progress..., used %d addresses\n", + assoc_id, used_address); + } + } else { + SCTP_DEBUG("sctp_connectx SUCCESS, used %d addresses assoc_id %d\n", + used_address, + assoc_id); + } + } else { + /* No remote address provided -> only bind the socket for now. + * Connection will be accepted in the main event loop + */ + struct sockaddr_in6 addr6; - if (bind(sd, (struct sockaddr*)&addr6, sizeof(addr6)) < 0) { - SCTP_ERROR("Failed to bind the socket to address any (v4/v6): %s\n", - strerror(errno)); - close(sd); - return; + connection_type = SCTP_TYPE_SERVER; + + /* For now bind to any interface */ + addr6.sin6_family = AF_INET6; + addr6.sin6_addr = in6addr_any; + addr6.sin6_port = htons(sctp_new_association_req_p->port); + + if (bind(sd, (struct sockaddr*)&addr6, sizeof(addr6)) < 0) { + SCTP_ERROR("Failed to bind the socket to address any (v4/v6): %s\n", + strerror(errno)); + close(sd); + return; + } } - } - sctp_cnx = calloc(1, sizeof(*sctp_cnx)); + sctp_cnx = calloc(1, sizeof(*sctp_cnx)); - sctp_cnx->connection_type = connection_type; + sctp_cnx->connection_type = connection_type; - sctp_cnx->sd = sd; - sctp_cnx->task_id = requestor; - sctp_cnx->cnx_id = sctp_new_association_req_p->ulp_cnx_id; - sctp_cnx->ppid = sctp_new_association_req_p->ppid; - sctp_cnx->instance = instance; - sctp_cnx->assoc_id = assoc_id; + sctp_cnx->sd = sd; + sctp_cnx->task_id = requestor; + sctp_cnx->cnx_id = sctp_new_association_req_p->ulp_cnx_id; + sctp_cnx->ppid = sctp_new_association_req_p->ppid; + sctp_cnx->instance = instance; + sctp_cnx->assoc_id = assoc_id; - /* Insert new element at end of list */ - STAILQ_INSERT_TAIL(&sctp_cnx_list, sctp_cnx, entries); - sctp_nb_cnx++; + /* Insert new element at end of list */ + STAILQ_INSERT_TAIL(&sctp_cnx_list, sctp_cnx, entries); + sctp_nb_cnx++; - SCTP_DEBUG("Inserted new descriptor for sd %d in list, nb elements %u, assoc_id %d\n", - sd, sctp_nb_cnx, assoc_id); + SCTP_DEBUG("Inserted new descriptor for sd %d in list, nb elements %u, assoc_id %d\n", + sd, sctp_nb_cnx, assoc_id); } - //------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ void sctp_send_data( - instance_t instance, - task_id_t task_id, - sctp_data_req_t *sctp_data_req_p) + instance_t instance, + task_id_t task_id, + sctp_data_req_t *sctp_data_req_p) { - struct sctp_cnx_list_elm_s *sctp_cnx = NULL; - - DevAssert(sctp_data_req_p != NULL); - DevAssert(sctp_data_req_p->buffer != NULL); - DevAssert(sctp_data_req_p->buffer_length > 0); - - sctp_cnx = sctp_get_cnx(sctp_data_req_p->assoc_id, 0); - - if (sctp_cnx == NULL) { - SCTP_ERROR("Failed to find SCTP description for assoc_id %d\n", - sctp_data_req_p->assoc_id); - /* TODO: notify upper layer */ - return; - } - - if (sctp_data_req_p->stream >= sctp_cnx->out_streams) { - SCTP_ERROR("Requested stream (%"PRIu16") >= nb out streams (%"PRIu16")\n", - sctp_data_req_p->stream, sctp_cnx->out_streams); - return; - } - - /* Send message on specified stream of the sd association - * NOTE: PPID should be defined in network order - */ - if (sctp_sendmsg(sctp_cnx->sd, sctp_data_req_p->buffer, - sctp_data_req_p->buffer_length, NULL, 0, - htonl(sctp_cnx->ppid), 0, sctp_data_req_p->stream, 0, 0) < 0) { - SCTP_ERROR("Sctp_sendmsg failed: %s\n", strerror(errno)); - /* TODO: notify upper layer */ - return; - } - - SCTP_DEBUG("Successfully sent %u bytes on stream %d for assoc_id %u\n", - sctp_data_req_p->buffer_length, sctp_data_req_p->stream, - sctp_cnx->assoc_id); + struct sctp_cnx_list_elm_s *sctp_cnx = NULL; + + DevAssert(sctp_data_req_p != NULL); + DevAssert(sctp_data_req_p->buffer != NULL); + DevAssert(sctp_data_req_p->buffer_length > 0); + + sctp_cnx = sctp_get_cnx(sctp_data_req_p->assoc_id, 0); + + if (sctp_cnx == NULL) { + SCTP_ERROR("Failed to find SCTP description for assoc_id %d\n", + sctp_data_req_p->assoc_id); + /* TODO: notify upper layer */ + return; + } + + if (sctp_data_req_p->stream >= sctp_cnx->out_streams) { + SCTP_ERROR("Requested stream (%"PRIu16") >= nb out streams (%"PRIu16")\n", + sctp_data_req_p->stream, sctp_cnx->out_streams); + return; + } + + /* Send message on specified stream of the sd association + * NOTE: PPID should be defined in network order + */ + if (sctp_sendmsg(sctp_cnx->sd, sctp_data_req_p->buffer, + sctp_data_req_p->buffer_length, NULL, 0, + htonl(sctp_cnx->ppid), 0, sctp_data_req_p->stream, 0, 0) < 0) { + SCTP_ERROR("Sctp_sendmsg failed: %s\n", strerror(errno)); + /* TODO: notify upper layer */ + return; + } + + SCTP_DEBUG("Successfully sent %u bytes on stream %d for assoc_id %u\n", + sctp_data_req_p->buffer_length, sctp_data_req_p->stream, + sctp_cnx->assoc_id); } //------------------------------------------------------------------------------ static int sctp_close_association( - const instance_t instance, - const task_id_t requestor, - sctp_close_association_t *close_association_p) + const instance_t instance, + const task_id_t requestor, + sctp_close_association_t *close_association_p) { - struct sctp_cnx_list_elm_s *sctp_cnx = NULL; + struct sctp_cnx_list_elm_s *sctp_cnx = NULL; - DevAssert(close_association_p != NULL); - sctp_cnx = sctp_get_cnx(close_association_p->assoc_id, 0); + DevAssert(close_association_p != NULL); + sctp_cnx = sctp_get_cnx(close_association_p->assoc_id, 0); - if (sctp_cnx == NULL) { - SCTP_ERROR("Failed to find SCTP description for assoc_id %d\n", - close_association_p->assoc_id); - /* TODO: notify upper layer */ - return -1; - } else { - close(sctp_cnx->sd); - STAILQ_REMOVE(&sctp_cnx_list, sctp_cnx, sctp_cnx_list_elm_s, entries); - SCTP_DEBUG("Removed assoc_id %u (closed socket %u)\n", - sctp_cnx->assoc_id, sctp_cnx->sd); - } - - return 0; + if (sctp_cnx == NULL) { + SCTP_ERROR("Failed to find SCTP description for assoc_id %d\n", + close_association_p->assoc_id); + /* TODO: notify upper layer */ + return -1; + } else { + close(sctp_cnx->sd); + STAILQ_REMOVE(&sctp_cnx_list, sctp_cnx, sctp_cnx_list_elm_s, entries); + SCTP_DEBUG("Removed assoc_id %u (closed socket %u)\n", + sctp_cnx->assoc_id, (unsigned int)sctp_cnx->sd); + } + + return 0; } //------------------------------------------------------------------------------ static int sctp_create_new_listener( - const instance_t instance, - const task_id_t requestor, - sctp_init_t *init_p, - int server_type) + const instance_t instance, + const task_id_t requestor, + sctp_init_t *init_p, + int server_type) { - struct sctp_event_subscribe event; - struct sockaddr *addr = NULL; - struct sctp_cnx_list_elm_s *sctp_cnx = NULL; - uint16_t i = 0, j = 0; - int sd = 0; - int used_addresses = 0; - - DevAssert(init_p != NULL); - - if (init_p->ipv4 == 0 && init_p->ipv6 == 0) { - SCTP_ERROR("Illegal IP configuration upper layer should request at" - "least ipv4 and/or ipv6 config\n"); - return -1; - } + struct sctp_event_subscribe event; + struct sockaddr *addr = NULL; + struct sctp_cnx_list_elm_s *sctp_cnx = NULL; + uint16_t i = 0, j = 0; + int sd = 0; + int used_addresses = 0; + + DevAssert(init_p != NULL); + + if (init_p->ipv4 == 0 && init_p->ipv6 == 0) { + SCTP_ERROR("Illegal IP configuration upper layer should request at" + "least ipv4 and/or ipv6 config\n"); + return -1; + } - if ((used_addresses = init_p->nb_ipv4_addr + init_p->nb_ipv6_addr) == 0) { - SCTP_WARN("No address provided...\n"); - return -1; - } + if ((used_addresses = init_p->nb_ipv4_addr + init_p->nb_ipv6_addr) == 0) { + SCTP_WARN("No address provided...\n"); + return -1; + } - addr = calloc(used_addresses, sizeof(struct sockaddr)); + addr = calloc(used_addresses, sizeof(struct sockaddr)); - SCTP_DEBUG("Creating new listen socket on port %u with\n", init_p->port); + SCTP_DEBUG("Creating new listen socket on port %u with\n", init_p->port); - if (init_p->ipv4 == 1) { - struct sockaddr_in *ip4_addr; + if (init_p->ipv4 == 1) { + struct sockaddr_in *ip4_addr; - SCTP_DEBUG("ipv4 addresses:\n"); + SCTP_DEBUG("ipv4 addresses:\n"); - for (i = 0; i < init_p->nb_ipv4_addr; i++) { - SCTP_DEBUG("\t- "IPV4_ADDR"\n", - IPV4_ADDR_FORMAT(init_p->ipv4_address[i])); - ip4_addr = (struct sockaddr_in *)&addr[i]; - ip4_addr->sin_family = AF_INET; - ip4_addr->sin_port = htons(init_p->port); - ip4_addr->sin_addr.s_addr = init_p->ipv4_address[i]; + for (i = 0; i < init_p->nb_ipv4_addr; i++) { + SCTP_DEBUG("\t- "IPV4_ADDR"\n", + IPV4_ADDR_FORMAT(init_p->ipv4_address[i])); + ip4_addr = (struct sockaddr_in *)&addr[i]; + ip4_addr->sin_family = AF_INET; + ip4_addr->sin_port = htons(init_p->port); + ip4_addr->sin_addr.s_addr = init_p->ipv4_address[i]; + } } - } - if (init_p->ipv6 == 1) { - struct sockaddr_in6 *ip6_addr; + if (init_p->ipv6 == 1) { + struct sockaddr_in6 *ip6_addr; - SCTP_DEBUG("ipv6 addresses:\n"); + SCTP_DEBUG("ipv6 addresses:\n"); - for (j = 0; j < init_p->nb_ipv6_addr; j++) { - SCTP_DEBUG("\t- %s\n", init_p->ipv6_address[j]); - ip6_addr = (struct sockaddr_in6 *)&addr[i + j]; - ip6_addr->sin6_family = AF_INET6; - ip6_addr->sin6_port = htons(init_p->port); + for (j = 0; j < init_p->nb_ipv6_addr; j++) { + SCTP_DEBUG("\t- %s\n", init_p->ipv6_address[j]); + ip6_addr = (struct sockaddr_in6 *)&addr[i + j]; + ip6_addr->sin6_family = AF_INET6; + ip6_addr->sin6_port = htons(init_p->port); - if (inet_pton(AF_INET6, init_p->ipv6_address[j], - ip6_addr->sin6_addr.s6_addr) <= 0) { - SCTP_WARN("Provided ipv6 address %s is not valid\n", - init_p->ipv6_address[j]); - } + if (inet_pton(AF_INET6, init_p->ipv6_address[j], + ip6_addr->sin6_addr.s6_addr) <= 0) { + SCTP_WARN("Provided ipv6 address %s is not valid\n", + init_p->ipv6_address[j]); + } + } } - } - if (server_type) { - if ((sd = socket(PF_INET, SOCK_SEQPACKET, IPPROTO_SCTP)) < 0) { - SCTP_ERROR("socket: %s:%d\n", strerror(errno), errno); - return -1; + if (server_type) { + if ((sd = socket(PF_INET, SOCK_SEQPACKET, IPPROTO_SCTP)) < 0) { + SCTP_ERROR("socket: %s:%d\n", strerror(errno), errno); + free(addr); + return -1; + } } - } - else { - if ((sd = socket(AF_INET6, SOCK_STREAM, IPPROTO_SCTP)) < 0) { - SCTP_ERROR("socket: %s:%d\n", strerror(errno), errno); - return -1; + else { + if ((sd = socket(AF_INET6, SOCK_STREAM, IPPROTO_SCTP)) < 0) { + SCTP_ERROR("socket: %s:%d\n", strerror(errno), errno); + free(addr); + return -1; + } } - } - memset((void *)&event, 1, sizeof(struct sctp_event_subscribe)); + memset((void *)&event, 1, sizeof(struct sctp_event_subscribe)); - if (setsockopt(sd, IPPROTO_SCTP, SCTP_EVENTS, &event, - sizeof(struct sctp_event_subscribe)) < 0) { - SCTP_ERROR("setsockopt: %s:%d\n", strerror(errno), errno); - return -1; - } - - sctp_cnx = calloc(1, sizeof(*sctp_cnx)); - - if (server_type) { - sctp_cnx->connection_type = SCTP_TYPE_MULTI_SERVER; - } - else { - sctp_cnx->connection_type = SCTP_TYPE_SERVER; - } - - sctp_cnx->sd = sd; - sctp_cnx->local_port = init_p->port; - sctp_cnx->in_streams = 32; - sctp_cnx->out_streams = 32; - sctp_cnx->ppid = init_p->ppid; - sctp_cnx->task_id = requestor; - sctp_cnx->instance = instance; - - /* Some pre-bind socket configuration */ - if (sctp_set_init_opt(sd, - sctp_cnx->in_streams, - sctp_cnx->out_streams, - 0, - 0) < 0) { - goto err; - } - - if (sctp_bindx(sd, addr, used_addresses, SCTP_BINDX_ADD_ADDR) != 0) { - SCTP_ERROR("sctp_bindx: %s:%d\n", strerror(errno), errno); - return -1; - } + if (setsockopt(sd, IPPROTO_SCTP, SCTP_EVENTS, &event, + sizeof(struct sctp_event_subscribe)) < 0) { + SCTP_ERROR("setsockopt: %s:%d\n", strerror(errno), errno); + free(addr); + return -1; + } - if (listen(sd, 5) < 0) { - SCTP_ERROR("listen: %s:%d\n", strerror(errno), errno); - return -1; - } + sctp_cnx = calloc(1, sizeof(*sctp_cnx)); - /* Insert new element at end of list */ - STAILQ_INSERT_TAIL(&sctp_cnx_list, sctp_cnx, entries); - sctp_nb_cnx++; + if (server_type) { + sctp_cnx->connection_type = SCTP_TYPE_MULTI_SERVER; + } + else { + sctp_cnx->connection_type = SCTP_TYPE_SERVER; + } + + sctp_cnx->sd = sd; + sctp_cnx->local_port = init_p->port; + sctp_cnx->in_streams = 32; + sctp_cnx->out_streams = 32; + sctp_cnx->ppid = init_p->ppid; + sctp_cnx->task_id = requestor; + sctp_cnx->instance = instance; + + /* Some pre-bind socket configuration */ + if (sctp_set_init_opt(sd, + sctp_cnx->in_streams, + sctp_cnx->out_streams, + 0, + 0) < 0) { + goto err; + } - /* Add the socket to list of fd monitored by ITTI */ - itti_subscribe_event_fd(TASK_SCTP, sd); + if (sctp_bindx(sd, addr, used_addresses, SCTP_BINDX_ADD_ADDR) != 0) { + SCTP_ERROR("sctp_bindx: %s:%d\n", strerror(errno), errno); + return -1; + } + + if (listen(sd, 5) < 0) { + SCTP_ERROR("listen: %s:%d\n", strerror(errno), errno); + return -1; + } + + /* Insert new element at end of list */ + STAILQ_INSERT_TAIL(&sctp_cnx_list, sctp_cnx, entries); + sctp_nb_cnx++; + + /* Add the socket to list of fd monitored by ITTI */ + itti_subscribe_event_fd(TASK_SCTP, sd); - return sd; + return sd; err: - if (sd != -1) { - close(sd); - sd = -1; - } + if (sd != -1) { + close(sd); + sd = -1; + } - return -1; + return -1; } //------------------------------------------------------------------------------ static inline void sctp_eNB_accept_associations( - struct sctp_cnx_list_elm_s *sctp_cnx) + struct sctp_cnx_list_elm_s *sctp_cnx) { - int client_sd; - struct sockaddr saddr; - socklen_t saddr_size; - - DevAssert(sctp_cnx != NULL); - - saddr_size = sizeof(saddr); - - /* There is a new client connecting. Accept it... - */ - if ((client_sd = accept(sctp_cnx->sd, &saddr, &saddr_size)) < 0) { - SCTP_ERROR("[%d] accept failed: %s:%d\n", sctp_cnx->sd, strerror(errno), errno); - } else { - struct sctp_cnx_list_elm_s *new_cnx; - uint16_t port; - - /* This is an ipv6 socket */ - port = ((struct sockaddr_in6*)&saddr)->sin6_port; - - /* Contrary to BSD, client socket does not inherit O_NONBLOCK option */ - if (fcntl(client_sd, F_SETFL, O_NONBLOCK) < 0) { - SCTP_ERROR("fcntl F_SETFL O_NONBLOCK failed: %s\n", - strerror(errno)); - close(client_sd); - return; - } + int client_sd; + struct sockaddr saddr; + socklen_t saddr_size; - new_cnx = calloc(1, sizeof(*sctp_cnx)); + DevAssert(sctp_cnx != NULL); - DevAssert(new_cnx != NULL); + saddr_size = sizeof(saddr); - new_cnx->connection_type = SCTP_TYPE_CLIENT; + /* There is a new client connecting. Accept it... + */ + if ((client_sd = accept(sctp_cnx->sd, &saddr, &saddr_size)) < 0) { + SCTP_ERROR("[%d] accept failed: %s:%d\n", sctp_cnx->sd, strerror(errno), errno); + } else { + struct sctp_cnx_list_elm_s *new_cnx; + uint16_t port; - new_cnx->sd = client_sd; - new_cnx->task_id = sctp_cnx->task_id; - new_cnx->cnx_id = 0; - new_cnx->ppid = sctp_cnx->ppid; - new_cnx->instance = sctp_cnx->instance; - new_cnx->local_port = sctp_cnx->local_port; + /* This is an ipv6 socket */ + port = ((struct sockaddr_in6*)&saddr)->sin6_port; - if (sctp_get_sockinfo(client_sd, &new_cnx->in_streams, &new_cnx->out_streams, - &new_cnx->assoc_id) != 0) { - SCTP_ERROR("sctp_get_sockinfo failed\n"); - close(client_sd); - free(new_cnx); - return; - } + /* Contrary to BSD, client socket does not inherit O_NONBLOCK option */ + if (fcntl(client_sd, F_SETFL, O_NONBLOCK) < 0) { + SCTP_ERROR("fcntl F_SETFL O_NONBLOCK failed: %s\n", + strerror(errno)); + close(client_sd); + return; + } - /* Insert new element at end of list */ - STAILQ_INSERT_TAIL(&sctp_cnx_list, new_cnx, entries); - sctp_nb_cnx++; + new_cnx = calloc(1, sizeof(*sctp_cnx)); - /* Add the socket to list of fd monitored by ITTI */ - itti_subscribe_event_fd(TASK_SCTP, client_sd); + DevAssert(new_cnx != NULL); + + new_cnx->connection_type = SCTP_TYPE_CLIENT; + + new_cnx->sd = client_sd; + new_cnx->task_id = sctp_cnx->task_id; + new_cnx->cnx_id = 0; + new_cnx->ppid = sctp_cnx->ppid; + new_cnx->instance = sctp_cnx->instance; + new_cnx->local_port = sctp_cnx->local_port; + + if (sctp_get_sockinfo(client_sd, &new_cnx->in_streams, &new_cnx->out_streams, + &new_cnx->assoc_id) != 0) { + SCTP_ERROR("sctp_get_sockinfo failed\n"); + close(client_sd); + free(new_cnx); + return; + } + + /* Insert new element at end of list */ + STAILQ_INSERT_TAIL(&sctp_cnx_list, new_cnx, entries); + sctp_nb_cnx++; + + /* Add the socket to list of fd monitored by ITTI */ + itti_subscribe_event_fd(TASK_SCTP, client_sd); - sctp_itti_send_association_ind(new_cnx->task_id, new_cnx->instance, - new_cnx->assoc_id, port, - new_cnx->out_streams, new_cnx->in_streams); - } + sctp_itti_send_association_ind(new_cnx->task_id, new_cnx->instance, + new_cnx->assoc_id, port, + new_cnx->out_streams, new_cnx->in_streams); + } } //------------------------------------------------------------------------------ static inline void sctp_eNB_read_from_socket( - struct sctp_cnx_list_elm_s *sctp_cnx) + struct sctp_cnx_list_elm_s *sctp_cnx) { - int flags = 0, n; - socklen_t from_len; - struct sctp_sndrcvinfo sinfo; + int flags = 0, n; + socklen_t from_len; + struct sctp_sndrcvinfo sinfo; - struct sockaddr_in addr; - uint8_t buffer[SCTP_RECV_BUFFER_SIZE]; + struct sockaddr_in addr; + uint8_t buffer[SCTP_RECV_BUFFER_SIZE]; - DevAssert(sctp_cnx != NULL); + DevAssert(sctp_cnx != NULL); - memset((void *)&addr, 0, sizeof(struct sockaddr_in)); - from_len = (socklen_t)sizeof(struct sockaddr_in); - memset((void *)&sinfo, 0, sizeof(struct sctp_sndrcvinfo)); + memset((void *)&addr, 0, sizeof(struct sockaddr_in)); + from_len = (socklen_t)sizeof(struct sockaddr_in); + memset((void *)&sinfo, 0, sizeof(struct sctp_sndrcvinfo)); - n = sctp_recvmsg(sctp_cnx->sd, (void *)buffer, SCTP_RECV_BUFFER_SIZE, - (struct sockaddr *)&addr, &from_len, - &sinfo, &flags); + n = sctp_recvmsg(sctp_cnx->sd, (void *)buffer, SCTP_RECV_BUFFER_SIZE, + (struct sockaddr *)&addr, &from_len, + &sinfo, &flags); - if (n < 0) { - if (errno == ENOTCONN) { - itti_unsubscribe_event_fd(TASK_SCTP, sctp_cnx->sd); + if (n < 0) { + if (errno == ENOTCONN) { + itti_unsubscribe_event_fd(TASK_SCTP, sctp_cnx->sd); - SCTP_DEBUG("Received not connected for sd %d\n", sctp_cnx->sd); + SCTP_DEBUG("Received not connected for sd %d\n", sctp_cnx->sd); - sctp_itti_send_association_resp( - sctp_cnx->task_id, sctp_cnx->instance, -1, - sctp_cnx->cnx_id, SCTP_STATE_UNREACHABLE, 0, 0); + sctp_itti_send_association_resp( + sctp_cnx->task_id, sctp_cnx->instance, -1, + sctp_cnx->cnx_id, SCTP_STATE_UNREACHABLE, 0, 0); - close(sctp_cnx->sd); - STAILQ_REMOVE(&sctp_cnx_list, sctp_cnx, sctp_cnx_list_elm_s, entries); - sctp_nb_cnx--; - free(sctp_cnx); - } else { - SCTP_DEBUG("An error occured during read\n"); - SCTP_ERROR("sctp_recvmsg (fd %d, len %d ): %s:%d\n", sctp_cnx->sd, n, strerror(errno), errno); - } + close(sctp_cnx->sd); + STAILQ_REMOVE(&sctp_cnx_list, sctp_cnx, sctp_cnx_list_elm_s, entries); + sctp_nb_cnx--; + free(sctp_cnx); + } else { + SCTP_DEBUG("An error occured during read\n"); + SCTP_ERROR("sctp_recvmsg (fd %d, len %d ): %s:%d\n", sctp_cnx->sd, n, strerror(errno), errno); + } - return; - } else if (n == 0) { - SCTP_DEBUG("return of sctp_recvmsg is 0...\n"); - return; - } + return; + } else if (n == 0) { + SCTP_DEBUG("return of sctp_recvmsg is 0...\n"); + return; + } - if (flags & MSG_NOTIFICATION) { - union sctp_notification *snp; - snp = (union sctp_notification *)buffer; + if (flags & MSG_NOTIFICATION) { + union sctp_notification *snp; + snp = (union sctp_notification *)buffer; - SCTP_DEBUG("Received notification for sd %d, type %u\n", - sctp_cnx->sd, snp->sn_header.sn_type); + SCTP_DEBUG("Received notification for sd %d, type %u\n", + sctp_cnx->sd, snp->sn_header.sn_type); - /* Client deconnection */ - if (SCTP_SHUTDOWN_EVENT == snp->sn_header.sn_type) { - itti_unsubscribe_event_fd(TASK_SCTP, sctp_cnx->sd); + /* Client deconnection */ + if (SCTP_SHUTDOWN_EVENT == snp->sn_header.sn_type) { + itti_unsubscribe_event_fd(TASK_SCTP, sctp_cnx->sd); - close(sctp_cnx->sd); + close(sctp_cnx->sd); - sctp_itti_send_association_resp( - sctp_cnx->task_id, sctp_cnx->instance, sctp_cnx->assoc_id, - sctp_cnx->cnx_id, SCTP_STATE_SHUTDOWN, - 0, 0); + sctp_itti_send_association_resp( + sctp_cnx->task_id, sctp_cnx->instance, sctp_cnx->assoc_id, + sctp_cnx->cnx_id, SCTP_STATE_SHUTDOWN, + 0, 0); - STAILQ_REMOVE(&sctp_cnx_list, sctp_cnx, sctp_cnx_list_elm_s, entries); - sctp_nb_cnx--; + STAILQ_REMOVE(&sctp_cnx_list, sctp_cnx, sctp_cnx_list_elm_s, entries); + sctp_nb_cnx--; - free(sctp_cnx); - } - /* Association has changed. */ - else if (SCTP_ASSOC_CHANGE == snp->sn_header.sn_type) { - struct sctp_assoc_change *sctp_assoc_changed; - sctp_assoc_changed = &snp->sn_assoc_change; - - SCTP_DEBUG("Client association changed: %d\n", sctp_assoc_changed->sac_state); - - /* New physical association requested by a peer */ - switch (sctp_assoc_changed->sac_state) { - case SCTP_COMM_UP: { - if (sctp_get_peeraddresses(sctp_cnx->sd, NULL, NULL) != 0) { - /* TODO Failure -> notify upper layer */ - } else { - sctp_get_sockinfo(sctp_cnx->sd, &sctp_cnx->in_streams, - &sctp_cnx->out_streams, &sctp_cnx->assoc_id); + free(sctp_cnx); + } + /* Association has changed. */ + else if (SCTP_ASSOC_CHANGE == snp->sn_header.sn_type) { + struct sctp_assoc_change *sctp_assoc_changed; + sctp_assoc_changed = &snp->sn_assoc_change; + + SCTP_DEBUG("Client association changed: %d\n", sctp_assoc_changed->sac_state); + + /* New physical association requested by a peer */ + switch (sctp_assoc_changed->sac_state) { + case SCTP_COMM_UP: { + if (sctp_get_peeraddresses(sctp_cnx->sd, NULL, NULL) != 0) { + /* TODO Failure -> notify upper layer */ + } else { + sctp_get_sockinfo(sctp_cnx->sd, &sctp_cnx->in_streams, + &sctp_cnx->out_streams, &sctp_cnx->assoc_id); + } + + SCTP_DEBUG("Comm up notified for sd %d, assigned assoc_id %d\n", + sctp_cnx->sd, sctp_cnx->assoc_id); + + sctp_itti_send_association_resp( + sctp_cnx->task_id, sctp_cnx->instance, sctp_cnx->assoc_id, + sctp_cnx->cnx_id, SCTP_STATE_ESTABLISHED, + sctp_cnx->out_streams, sctp_cnx->in_streams); + + } + break; + + default: + SCTP_WARN("unhandled: SCTP_ASSOC_CHANGE to %d\n", sctp_assoc_changed->sac_state); + break; + } + } + } else { + sctp_cnx->messages_recv++; + + if (ntohl(sinfo.sinfo_ppid) != sctp_cnx->ppid) { + /* Mismatch in Payload Protocol Identifier, + * may be we received unsollicited traffic from stack other than S1AP. + */ + SCTP_ERROR("Received data from peer with unsollicited PPID %d, expecting %d\n", + ntohl(sinfo.sinfo_ppid), + sctp_cnx->ppid); } - SCTP_DEBUG("Comm up notified for sd %d, assigned assoc_id %d\n", - sctp_cnx->sd, sctp_cnx->assoc_id); - - sctp_itti_send_association_resp( - sctp_cnx->task_id, sctp_cnx->instance, sctp_cnx->assoc_id, - sctp_cnx->cnx_id, SCTP_STATE_ESTABLISHED, - sctp_cnx->out_streams, sctp_cnx->in_streams); - - } - break; + SCTP_DEBUG("[%d][%d] Msg of length %d received from port %u, on stream %d, PPID %d\n", + sinfo.sinfo_assoc_id, sctp_cnx->sd, n, ntohs(addr.sin_port), + sinfo.sinfo_stream, ntohl(sinfo.sinfo_ppid)); - default: - SCTP_WARN("unhandled: SCTP_ASSOC_CHANGE to %d\n", sctp_assoc_changed->sac_state); - break; - } - } - } else { - sctp_cnx->messages_recv++; - - if (ntohl(sinfo.sinfo_ppid) != sctp_cnx->ppid) { - /* Mismatch in Payload Protocol Identifier, - * may be we received unsollicited traffic from stack other than S1AP. - */ - SCTP_ERROR("Received data from peer with unsollicited PPID %d, expecting %d\n", - ntohl(sinfo.sinfo_ppid), - sctp_cnx->ppid); + sctp_itti_send_new_message_ind(sctp_cnx->task_id, + sinfo.sinfo_assoc_id, + buffer, n, sinfo.sinfo_stream); } - - SCTP_DEBUG("[%d][%d] Msg of length %d received from port %u, on stream %d, PPID %d\n", - sinfo.sinfo_assoc_id, sctp_cnx->sd, n, ntohs(addr.sin_port), - sinfo.sinfo_stream, ntohl(sinfo.sinfo_ppid)); - - sctp_itti_send_new_message_ind(sctp_cnx->task_id, - sinfo.sinfo_assoc_id, - buffer, n, sinfo.sinfo_stream); - } } //------------------------------------------------------------------------------ void sctp_eNB_flush_sockets( - struct epoll_event *events, int nb_events) + struct epoll_event *events, int nb_events) { - int i; - struct sctp_cnx_list_elm_s *sctp_cnx = NULL; + int i; + struct sctp_cnx_list_elm_s *sctp_cnx = NULL; - if (events == NULL) { - return; - } + if (events == NULL) { + return; + } - for (i = 0; i < nb_events; i++) { - sctp_cnx = sctp_get_cnx(-1, events[i].data.fd); + for (i = 0; i < nb_events; i++) { + sctp_cnx = sctp_get_cnx(-1, events[i].data.fd); - if (sctp_cnx == NULL) { - continue; - } + if (sctp_cnx == NULL) { + continue; + } - SCTP_DEBUG("Found data for descriptor %d\n", events[i].data.fd); + SCTP_DEBUG("Found data for descriptor %d\n", events[i].data.fd); - if (sctp_cnx->connection_type == SCTP_TYPE_CLIENT) { - sctp_eNB_read_from_socket(sctp_cnx); - } - else if (sctp_cnx->connection_type == SCTP_TYPE_MULTI_SERVER) { - sctp_eNB_accept_associations_multi(sctp_cnx); - } - else { - sctp_eNB_accept_associations(sctp_cnx); + if (sctp_cnx->connection_type == SCTP_TYPE_CLIENT) { + sctp_eNB_read_from_socket(sctp_cnx); + } + else if (sctp_cnx->connection_type == SCTP_TYPE_MULTI_SERVER) { + sctp_eNB_accept_associations_multi(sctp_cnx); + } + else { + sctp_eNB_accept_associations(sctp_cnx); + } } - } } //------------------------------------------------------------------------------ void sctp_eNB_init(void) { - SCTP_DEBUG("Starting SCTP layer\n"); + SCTP_DEBUG("Starting SCTP layer\n"); - STAILQ_INIT(&sctp_cnx_list); + STAILQ_INIT(&sctp_cnx_list); - itti_mark_task_ready(TASK_SCTP); - MSC_START_USE(); + itti_mark_task_ready(TASK_SCTP); + MSC_START_USE(); } - + //------------------------------------------------------------------------------ void *sctp_eNB_process_itti_msg(void *notUsed) { @@ -1058,88 +1061,88 @@ void *sctp_eNB_process_itti_msg(void *notUsed) struct epoll_event *events; MessageDef *received_msg = NULL; int result; - + itti_receive_msg(TASK_SCTP, &received_msg); /* Check if there is a packet to handle */ if (received_msg != NULL) { - switch (ITTI_MSG_ID(received_msg)) { - case SCTP_INIT_MSG: { - SCTP_DEBUG("Received SCTP_INIT_MSG\n"); - - /* We received a new connection request */ - if (sctp_create_new_listener( - ITTI_MESSAGE_GET_INSTANCE(received_msg), - ITTI_MSG_ORIGIN_ID(received_msg), - &received_msg->ittiMsg.sctp_init,0) < 0) { - /* SCTP socket creation or bind failed... */ - SCTP_ERROR("Failed to create new SCTP listener\n"); + switch (ITTI_MSG_ID(received_msg)) { + case SCTP_INIT_MSG: { + SCTP_DEBUG("Received SCTP_INIT_MSG\n"); + + /* We received a new connection request */ + if (sctp_create_new_listener( + ITTI_MESSAGE_GET_INSTANCE(received_msg), + ITTI_MSG_ORIGIN_ID(received_msg), + &received_msg->ittiMsg.sctp_init,0) < 0) { + /* SCTP socket creation or bind failed... */ + SCTP_ERROR("Failed to create new SCTP listener\n"); + } } - } - break; - - case SCTP_INIT_MSG_MULTI_REQ: { - int multi_sd; - - SCTP_DEBUG("Received SCTP_INIT_MSG_MULTI_REQ\n"); - - multi_sd = sctp_create_new_listener( - ITTI_MESSAGE_GET_INSTANCE(received_msg), - ITTI_MSG_ORIGIN_ID(received_msg), - &received_msg->ittiMsg.sctp_init_multi,1); - /* We received a new connection request */ - if (multi_sd < 0) { - /* SCTP socket creation or bind failed... */ - SCTP_ERROR("Failed to create new SCTP listener\n"); - } - sctp_itti_send_init_msg_multi_cnf( + break; + + case SCTP_INIT_MSG_MULTI_REQ: { + int multi_sd; + + SCTP_DEBUG("Received SCTP_INIT_MSG_MULTI_REQ\n"); + + multi_sd = sctp_create_new_listener( + ITTI_MESSAGE_GET_INSTANCE(received_msg), + ITTI_MSG_ORIGIN_ID(received_msg), + &received_msg->ittiMsg.sctp_init_multi,1); + /* We received a new connection request */ + if (multi_sd < 0) { + /* SCTP socket creation or bind failed... */ + SCTP_ERROR("Failed to create new SCTP listener\n"); + } + sctp_itti_send_init_msg_multi_cnf( ITTI_MSG_ORIGIN_ID(received_msg), ITTI_MESSAGE_GET_INSTANCE(received_msg), multi_sd); - } - break; - - case SCTP_NEW_ASSOCIATION_REQ: { - sctp_handle_new_association_req(ITTI_MESSAGE_GET_INSTANCE(received_msg), - ITTI_MSG_ORIGIN_ID(received_msg), - &received_msg->ittiMsg.sctp_new_association_req); - } - break; - - case SCTP_NEW_ASSOCIATION_REQ_MULTI: { - sctp_handle_new_association_req_multi(ITTI_MESSAGE_GET_INSTANCE(received_msg), - ITTI_MSG_ORIGIN_ID(received_msg), - &received_msg->ittiMsg.sctp_new_association_req_multi); - } - break; - - case SCTP_CLOSE_ASSOCIATION: - sctp_close_association(ITTI_MESSAGE_GET_INSTANCE(received_msg), - ITTI_MSG_ORIGIN_ID(received_msg), - &received_msg->ittiMsg.sctp_close_association); + } break; - case TERMINATE_MESSAGE: - SCTP_WARN("*** Exiting SCTP thread\n"); - itti_exit_task(); + case SCTP_NEW_ASSOCIATION_REQ: { + sctp_handle_new_association_req(ITTI_MESSAGE_GET_INSTANCE(received_msg), + ITTI_MSG_ORIGIN_ID(received_msg), + &received_msg->ittiMsg.sctp_new_association_req); + } break; - case SCTP_DATA_REQ: { - sctp_send_data(ITTI_MESSAGE_GET_INSTANCE(received_msg), - ITTI_MSG_ORIGIN_ID(received_msg), - &received_msg->ittiMsg.sctp_data_req); - } - break; + case SCTP_NEW_ASSOCIATION_REQ_MULTI: { + sctp_handle_new_association_req_multi(ITTI_MESSAGE_GET_INSTANCE(received_msg), + ITTI_MSG_ORIGIN_ID(received_msg), + &received_msg->ittiMsg.sctp_new_association_req_multi); + } + break; - default: - SCTP_ERROR("Received unhandled message %d:%s\n", - ITTI_MSG_ID(received_msg), ITTI_MSG_NAME(received_msg)); + case SCTP_CLOSE_ASSOCIATION: + sctp_close_association(ITTI_MESSAGE_GET_INSTANCE(received_msg), + ITTI_MSG_ORIGIN_ID(received_msg), + &received_msg->ittiMsg.sctp_close_association); + break; + + case TERMINATE_MESSAGE: + SCTP_WARN("*** Exiting SCTP thread\n"); + itti_exit_task(); + break; + + case SCTP_DATA_REQ: { + sctp_send_data(ITTI_MESSAGE_GET_INSTANCE(received_msg), + ITTI_MSG_ORIGIN_ID(received_msg), + &received_msg->ittiMsg.sctp_data_req); + } break; - } - result = itti_free(ITTI_MSG_ORIGIN_ID(received_msg), received_msg); - AssertFatal (result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result); - received_msg = NULL; + default: + SCTP_ERROR("Received unhandled message %d:%s\n", + ITTI_MSG_ID(received_msg), ITTI_MSG_NAME(received_msg)); + break; + } + + result = itti_free(ITTI_MSG_ORIGIN_ID(received_msg), received_msg); + AssertFatal (result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result); + received_msg = NULL; } nb_events = itti_get_events(TASK_SCTP, &events); @@ -1148,15 +1151,15 @@ void *sctp_eNB_process_itti_msg(void *notUsed) return NULL; } - + //------------------------------------------------------------------------------ void *sctp_eNB_task(void *arg) { - sctp_eNB_init(); + sctp_eNB_init(); - while (1) { - (void) sctp_eNB_process_itti_msg(NULL); - } + while (1) { + (void) sctp_eNB_process_itti_msg(NULL); + } - return NULL; + return NULL; } diff --git a/targets/ARCH/BLADERF/USERSPACE/LIB/bladerf_lib.c b/targets/ARCH/BLADERF/USERSPACE/LIB/bladerf_lib.c index e5966af267047b0285583bab64d2e75370b65385..3ced5ca833a972d1e8f021733dbf1c2ab71cdb16 100644 --- a/targets/ARCH/BLADERF/USERSPACE/LIB/bladerf_lib.c +++ b/targets/ARCH/BLADERF/USERSPACE/LIB/bladerf_lib.c @@ -35,18 +35,18 @@ * @{ */ -//! Number of BladeRF devices +//! Number of BladeRF devices #ifdef __SSE4_1__ # include <smmintrin.h> #endif - + #ifdef __AVX2__ # include <immintrin.h> #endif int num_devices=0; -/*These items configure the underlying asynch stream used by the the sync interface. +/*These items configure the underlying asynch stream used by the the sync interface. */ /*! \brief BladeRF Init function (not used at the moment) @@ -54,119 +54,119 @@ int num_devices=0; * \returns 0 on success */ int trx_brf_init(openair0_device *device) { - return 0; + return 0; } /*! \brief get current timestamp - *\param device the hardware to use + *\param device the hardware to use *\param module the bladeRf module *\returns timestamp of BladeRF */ - + openair0_timestamp trx_get_timestamp(openair0_device *device, bladerf_module module) { - int status; - struct bladerf_metadata meta; - brf_state_t *brf = (brf_state_t*)device->priv; - memset(&meta, 0, sizeof(meta)); - - if ((status=bladerf_get_timestamp(brf->dev, module, &meta.timestamp)) != 0) { - fprintf(stderr,"Failed to get current %s timestamp: %s\n",(module == BLADERF_MODULE_RX ) ? "RX" : "TX", bladerf_strerror(status)); - return -1; - } // else {printf("Current RX timestampe 0x%016"PRIx64"\n", meta.timestamp); } - - return meta.timestamp; + int status; + struct bladerf_metadata meta; + brf_state_t *brf = (brf_state_t*)device->priv; + memset(&meta, 0, sizeof(meta)); + + if ((status=bladerf_get_timestamp(brf->dev, module, &meta.timestamp)) != 0) { + fprintf(stderr,"Failed to get current %s timestamp: %s\n",(module == BLADERF_MODULE_RX ) ? "RX" : "TX", bladerf_strerror(status)); + return -1; + } // else {printf("Current RX timestampe 0x%016"PRIx64"\n", meta.timestamp); } + + return meta.timestamp; } /*! \brief Start BladeRF - * \param device the hardware to use + * \param device the hardware to use * \returns 0 on success */ int trx_brf_start(openair0_device *device) { - brf_state_t *brf = (brf_state_t*)device->priv; - int status; - - brf->meta_tx.flags = 0; - - if ((status = bladerf_sync_config(brf->dev, - BLADERF_MODULE_TX, - BLADERF_FORMAT_SC16_Q11_META, - brf->num_buffers, - brf->buffer_size, - brf->num_transfers, - 100/*brf->tx_timeout_ms*/)) != 0 ) { - fprintf(stderr,"Failed to configure TX sync interface: %s\n", bladerf_strerror(status)); - abort(); - } - if ((status = bladerf_sync_config(brf->dev, - BLADERF_MODULE_RX, - BLADERF_FORMAT_SC16_Q11_META, - brf->num_buffers, - brf->buffer_size, - brf->num_transfers, - 100/*brf->rx_timeout_ms*/)) != 0 ) { - fprintf(stderr,"Failed to configure RX sync interface: %s\n", bladerf_strerror(status)); - abort(); - } - if ((status=bladerf_enable_module(brf->dev, BLADERF_MODULE_TX, true)) != 0) { - fprintf(stderr,"Failed to enable TX module: %s\n", bladerf_strerror(status)); - abort(); - } - if ((status=bladerf_enable_module(brf->dev, BLADERF_MODULE_RX, true)) != 0) { - fprintf(stderr,"Failed to enable RX module: %s\n", bladerf_strerror(status)); - abort(); - } - - return 0; + brf_state_t *brf = (brf_state_t*)device->priv; + int status; + + brf->meta_tx.flags = 0; + + if ((status = bladerf_sync_config(brf->dev, + BLADERF_MODULE_TX, + BLADERF_FORMAT_SC16_Q11_META, + brf->num_buffers, + brf->buffer_size, + brf->num_transfers, + 100/*brf->tx_timeout_ms*/)) != 0 ) { + fprintf(stderr,"Failed to configure TX sync interface: %s\n", bladerf_strerror(status)); + abort(); + } + if ((status = bladerf_sync_config(brf->dev, + BLADERF_MODULE_RX, + BLADERF_FORMAT_SC16_Q11_META, + brf->num_buffers, + brf->buffer_size, + brf->num_transfers, + 100/*brf->rx_timeout_ms*/)) != 0 ) { + fprintf(stderr,"Failed to configure RX sync interface: %s\n", bladerf_strerror(status)); + abort(); + } + if ((status=bladerf_enable_module(brf->dev, BLADERF_MODULE_TX, true)) != 0) { + fprintf(stderr,"Failed to enable TX module: %s\n", bladerf_strerror(status)); + abort(); + } + if ((status=bladerf_enable_module(brf->dev, BLADERF_MODULE_RX, true)) != 0) { + fprintf(stderr,"Failed to enable RX module: %s\n", bladerf_strerror(status)); + abort(); + } + + return 0; } /*! \brief Called to send samples to the BladeRF RF target \param device pointer to the device structure specific to the RF hardware target - \param timestamp The timestamp at whicch the first sample MUST be sent + \param timestamp The timestamp at whicch the first sample MUST be sent \param buff Buffer which holds the samples \param nsamps number of samples to be sent \param cc index of the component carrier \param flags Ignored for the moment \returns 0 on success -*/ +*/ static int trx_brf_write(openair0_device *device,openair0_timestamp ptimestamp, void **buff, int nsamps, int cc, int flags) { - - int status; - brf_state_t *brf = (brf_state_t*)device->priv; - /* BRF has only 1 rx/tx chaine : is it correct? */ - int16_t *samples = (int16_t*)buff[0]; - - //memset(&brf->meta_tx, 0, sizeof(brf->meta_tx)); - // When BLADERF_META_FLAG_TX_NOW is used the timestamp is not used, so one can't schedule a tx - if (brf->meta_tx.flags == 0 ) - brf->meta_tx.flags = (BLADERF_META_FLAG_TX_BURST_START);// | BLADERF_META_FLAG_TX_BURST_END);// | BLADERF_META_FLAG_TX_NOW); - - - brf->meta_tx.timestamp= (uint64_t) (ptimestamp); - status = bladerf_sync_tx(brf->dev, samples, (unsigned int) nsamps, &brf->meta_tx, 2*brf->tx_timeout_ms); - - if (brf->meta_tx.flags == BLADERF_META_FLAG_TX_BURST_START) - brf->meta_tx.flags = BLADERF_META_FLAG_TX_UPDATE_TIMESTAMP; - - - if (status != 0) { - //fprintf(stderr,"Failed to TX sample: %s\n", bladerf_strerror(status)); - brf->num_tx_errors++; - brf_error(status); - } else if (brf->meta_tx.status & BLADERF_META_STATUS_UNDERRUN){ - /* libbladeRF does not report this status. It is here for future use. */ - fprintf(stderr, "TX Underrun detected. %u valid samples were read.\n", brf->meta_tx.actual_count); - brf->num_underflows++; - } - //printf("Provided TX timestampe %u, meta timestame %u\n", ptimestamp,brf->meta_tx.timestamp); - - // printf("tx status %d \n",brf->meta_tx.status); - brf->tx_current_ts=brf->meta_tx.timestamp; - brf->tx_actual_nsamps+=brf->meta_tx.actual_count; - brf->tx_nsamps+=nsamps; - brf->tx_count++; - - - return nsamps; //brf->meta_tx.actual_count; + + int status; + brf_state_t *brf = (brf_state_t*)device->priv; + /* BRF has only 1 rx/tx chaine : is it correct? */ + int16_t *samples = (int16_t*)buff[0]; + + //memset(&brf->meta_tx, 0, sizeof(brf->meta_tx)); + // When BLADERF_META_FLAG_TX_NOW is used the timestamp is not used, so one can't schedule a tx + if (brf->meta_tx.flags == 0 ) + brf->meta_tx.flags = (BLADERF_META_FLAG_TX_BURST_START);// | BLADERF_META_FLAG_TX_BURST_END);// | BLADERF_META_FLAG_TX_NOW); + + + brf->meta_tx.timestamp= (uint64_t) (ptimestamp); + status = bladerf_sync_tx(brf->dev, samples, (unsigned int) nsamps, &brf->meta_tx, 2*brf->tx_timeout_ms); + + if (brf->meta_tx.flags == BLADERF_META_FLAG_TX_BURST_START) + brf->meta_tx.flags = BLADERF_META_FLAG_TX_UPDATE_TIMESTAMP; + + + if (status != 0) { + //fprintf(stderr,"Failed to TX sample: %s\n", bladerf_strerror(status)); + brf->num_tx_errors++; + brf_error(status); + } else if (brf->meta_tx.status & BLADERF_META_STATUS_UNDERRUN) { + /* libbladeRF does not report this status. It is here for future use. */ + fprintf(stderr, "TX Underrun detected. %u valid samples were read.\n", brf->meta_tx.actual_count); + brf->num_underflows++; + } + //printf("Provided TX timestampe %u, meta timestame %u\n", ptimestamp,brf->meta_tx.timestamp); + + // printf("tx status %d \n",brf->meta_tx.status); + brf->tx_current_ts=brf->meta_tx.timestamp; + brf->tx_actual_nsamps+=brf->meta_tx.actual_count; + brf->tx_nsamps+=nsamps; + brf->tx_count++; + + + return nsamps; //brf->meta_tx.actual_count; } /*! \brief Receive samples from hardware. @@ -182,90 +182,90 @@ static int trx_brf_write(openair0_device *device,openair0_timestamp ptimestamp, */ static int trx_brf_read(openair0_device *device, openair0_timestamp *ptimestamp, void **buff, int nsamps, int cc) { - int status=0; - brf_state_t *brf = (brf_state_t*)device->priv; - - // BRF has only one rx/tx chain - int16_t *samples = (int16_t*)buff[0]; - - brf->meta_rx.actual_count = 0; - brf->meta_rx.flags = BLADERF_META_FLAG_RX_NOW; - status = bladerf_sync_rx(brf->dev, samples, (unsigned int) nsamps, &brf->meta_rx, 2*brf->rx_timeout_ms); - - // printf("Current RX timestampe %u, nsamps %u, actual %u, cc %d\n", brf->meta_rx.timestamp, nsamps, brf->meta_rx.actual_count, cc); - - if (status != 0) { - fprintf(stderr, "RX failed: %s\n", bladerf_strerror(status)); - // printf("RX failed: %s\n", bladerf_strerror(status)); - brf->num_rx_errors++; - } else if ( brf->meta_rx.status & BLADERF_META_STATUS_OVERRUN) { - brf->num_overflows++; - printf("RX overrun (%d) is detected. t=" "%" PRIu64 "Got %u samples. nsymps %d\n", - brf->num_overflows,brf->meta_rx.timestamp, brf->meta_rx.actual_count, nsamps); - } - - if (brf->meta_rx.actual_count != nsamps) { - printf("RX bad samples count, wanted %d, got %d\n", nsamps, brf->meta_rx.actual_count); - } - - //printf("Current RX timestampe %u\n", brf->meta_rx.timestamp); - //printf("[BRF] (buff %p) ts=0x%"PRIu64" %s\n",samples, brf->meta_rx.timestamp,bladerf_strerror(status)); - brf->rx_current_ts=brf->meta_rx.timestamp; - brf->rx_actual_nsamps+=brf->meta_rx.actual_count; - brf->rx_nsamps+=nsamps; - brf->rx_count++; - - - *ptimestamp = brf->meta_rx.timestamp; - - return nsamps; //brf->meta_rx.actual_count; + int status=0; + brf_state_t *brf = (brf_state_t*)device->priv; + + // BRF has only one rx/tx chain + int16_t *samples = (int16_t*)buff[0]; + + brf->meta_rx.actual_count = 0; + brf->meta_rx.flags = BLADERF_META_FLAG_RX_NOW; + status = bladerf_sync_rx(brf->dev, samples, (unsigned int) nsamps, &brf->meta_rx, 2*brf->rx_timeout_ms); + + // printf("Current RX timestampe %u, nsamps %u, actual %u, cc %d\n", brf->meta_rx.timestamp, nsamps, brf->meta_rx.actual_count, cc); + + if (status != 0) { + fprintf(stderr, "RX failed: %s\n", bladerf_strerror(status)); + // printf("RX failed: %s\n", bladerf_strerror(status)); + brf->num_rx_errors++; + } else if ( brf->meta_rx.status & BLADERF_META_STATUS_OVERRUN) { + brf->num_overflows++; + printf("RX overrun (%d) is detected. t=" "%" PRIu64 "Got %u samples. nsymps %d\n", + brf->num_overflows,brf->meta_rx.timestamp, brf->meta_rx.actual_count, nsamps); + } + + if (brf->meta_rx.actual_count != nsamps) { + printf("RX bad samples count, wanted %d, got %d\n", nsamps, brf->meta_rx.actual_count); + } + + //printf("Current RX timestampe %u\n", brf->meta_rx.timestamp); + //printf("[BRF] (buff %p) ts=0x%"PRIu64" %s\n",samples, brf->meta_rx.timestamp,bladerf_strerror(status)); + brf->rx_current_ts=brf->meta_rx.timestamp; + brf->rx_actual_nsamps+=brf->meta_rx.actual_count; + brf->rx_nsamps+=nsamps; + brf->rx_count++; + + + *ptimestamp = brf->meta_rx.timestamp; + + return nsamps; //brf->meta_rx.actual_count; } -/*! \brief Terminate operation of the BladeRF transceiver -- free all associated resources +/*! \brief Terminate operation of the BladeRF transceiver -- free all associated resources * \param device the hardware to use */ void trx_brf_end(openair0_device *device) { - int status; - brf_state_t *brf = (brf_state_t*)device->priv; - // Disable RX module, shutting down our underlying RX stream - if ((status=bladerf_enable_module(brf->dev, BLADERF_MODULE_RX, false)) != 0) { - fprintf(stderr, "Failed to disable RX module: %s\n", bladerf_strerror(status)); - } - if ((status=bladerf_enable_module(brf->dev, BLADERF_MODULE_TX, false)) != 0) { - fprintf(stderr, "Failed to disable TX module: %s\n", bladerf_strerror(status)); - } - bladerf_close(brf->dev); - exit(1); + int status; + brf_state_t *brf = (brf_state_t*)device->priv; + // Disable RX module, shutting down our underlying RX stream + if ((status=bladerf_enable_module(brf->dev, BLADERF_MODULE_RX, false)) != 0) { + fprintf(stderr, "Failed to disable RX module: %s\n", bladerf_strerror(status)); + } + if ((status=bladerf_enable_module(brf->dev, BLADERF_MODULE_TX, false)) != 0) { + fprintf(stderr, "Failed to disable TX module: %s\n", bladerf_strerror(status)); + } + bladerf_close(brf->dev); + exit(1); } -/*! \brief print the BladeRF statistics +/*! \brief print the BladeRF statistics * \param device the hardware to use * \returns 0 on success */ int trx_brf_get_stats(openair0_device* device) { - return(0); + return(0); } -/*! \brief Reset the BladeRF statistics +/*! \brief Reset the BladeRF statistics * \param device the hardware to use * \returns 0 on success */ int trx_brf_reset_stats(openair0_device* device) { - return(0); + return(0); } /*! \brief Stop BladeRF * \param card the hardware to use - * \returns 0 in success + * \returns 0 in success */ int trx_brf_stop(openair0_device* device) { - return(0); + return(0); } @@ -273,39 +273,39 @@ int trx_brf_stop(openair0_device* device) { * \param device the hardware to use * \param openair0_cfg1 openair0 Config structure (ignored. It is there to comply with RF common API) * \param exmimo_dump_config (ignored) - * \returns 0 in success + * \returns 0 in success */ int trx_brf_set_freq(openair0_device* device, openair0_config_t *openair0_cfg1,int exmimo_dump_config) { - int status; - brf_state_t *brf = (brf_state_t *)device->priv; - openair0_config_t *openair0_cfg = (openair0_config_t *)device->openair0_cfg; + int status; + brf_state_t *brf = (brf_state_t *)device->priv; + openair0_config_t *openair0_cfg = (openair0_config_t *)device->openair0_cfg; - if ((status=bladerf_set_frequency(brf->dev, BLADERF_MODULE_TX, (unsigned int) openair0_cfg->tx_freq[0])) != 0){ - fprintf(stderr,"Failed to set TX frequency: %s\n",bladerf_strerror(status)); - brf_error(status); - }else - printf("[BRF] set TX Frequency to %u\n", (unsigned int) openair0_cfg->tx_freq[0]); + if ((status=bladerf_set_frequency(brf->dev, BLADERF_MODULE_TX, (unsigned int) openair0_cfg->tx_freq[0])) != 0) { + fprintf(stderr,"Failed to set TX frequency: %s\n",bladerf_strerror(status)); + brf_error(status); + } else + printf("[BRF] set TX Frequency to %u\n", (unsigned int) openair0_cfg->tx_freq[0]); - if ((status=bladerf_set_frequency(brf->dev, BLADERF_MODULE_RX, (unsigned int) openair0_cfg->rx_freq[0])) != 0){ - fprintf(stderr,"Failed to set RX frequency: %s\n",bladerf_strerror(status)); - brf_error(status); - } else - printf("[BRF] set RX frequency to %u\n",(unsigned int)openair0_cfg->rx_freq[0]); + if ((status=bladerf_set_frequency(brf->dev, BLADERF_MODULE_RX, (unsigned int) openair0_cfg->rx_freq[0])) != 0) { + fprintf(stderr,"Failed to set RX frequency: %s\n",bladerf_strerror(status)); + brf_error(status); + } else + printf("[BRF] set RX frequency to %u\n",(unsigned int)openair0_cfg->rx_freq[0]); - return(0); + return(0); } /*! \brief Set Gains (TX/RX) * \param device the hardware to use * \param openair0_cfg openair0 Config structure - * \returns 0 in success + * \returns 0 in success */ int trx_brf_set_gains(openair0_device* device, openair0_config_t *openair0_cfg) { - return(0); + return(0); } @@ -317,10 +317,11 @@ int16_t cos_3fsover8[8] = {2047, -1448, 0, 1447, -2047, 1447, 0, /*! \brief calibration table for BladeRF */ rx_gain_calib_table_t calib_table_fx4[] = { - {2300000000.0,53.5}, - {1880000000.0,57.0}, - {816000000.0,73.0}, - {-1,0}}; + {2300000000.0,53.5}, + {1880000000.0,57.0}, + {816000000.0,73.0}, + {-1,0} +}; /*! \brief set RX gain offset from calibration table * \param openair0_cfg RF frontend parameters set by application @@ -328,822 +329,822 @@ rx_gain_calib_table_t calib_table_fx4[] = { */ void set_rx_gain_offset(openair0_config_t *openair0_cfg, int chain_index) { - int i=0; - // loop through calibration table to find best adjustment factor for RX frequency - double min_diff = 6e9,diff; - - while (openair0_cfg->rx_gain_calib_table[i].freq>0) { - diff = fabs(openair0_cfg->rx_freq[chain_index] - openair0_cfg->rx_gain_calib_table[i].freq); - printf("cal %d: freq %f, offset %f, diff %f\n", - i, - openair0_cfg->rx_gain_calib_table[i].freq, - openair0_cfg->rx_gain_calib_table[i].offset,diff); - if (min_diff > diff) { - min_diff = diff; - openair0_cfg->rx_gain_offset[chain_index] = openair0_cfg->rx_gain_calib_table[i].offset; + int i=0; + // loop through calibration table to find best adjustment factor for RX frequency + double min_diff = 6e9,diff; + + while (openair0_cfg->rx_gain_calib_table[i].freq>0) { + diff = fabs(openair0_cfg->rx_freq[chain_index] - openair0_cfg->rx_gain_calib_table[i].freq); + printf("cal %d: freq %f, offset %f, diff %f\n", + i, + openair0_cfg->rx_gain_calib_table[i].freq, + openair0_cfg->rx_gain_calib_table[i].offset,diff); + if (min_diff > diff) { + min_diff = diff; + openair0_cfg->rx_gain_offset[chain_index] = openair0_cfg->rx_gain_calib_table[i].offset; + } + i++; } - i++; - } - + } -/*! \brief Calibrate LMSSDR RF +/*! \brief Calibrate LMSSDR RF * \param device the hardware to use */ void calibrate_rf(openair0_device *device) { - /* TODO: this function does not seem to work. Disabled until fixed. */ - return; - - brf_state_t *brf = (brf_state_t *)device->priv; - openair0_timestamp ptimestamp; - int16_t *calib_buffp,*calib_tx_buffp; - int16_t calib_buff[2*RXDCLENGTH]; - int16_t calib_tx_buff[2*RXDCLENGTH]; - int i,j,offI,offQ,offIold,offQold,offInew,offQnew,offphase,offphaseold,offphasenew,offgain,offgainold,offgainnew; - int32_t meanI,meanQ,meanIold,meanQold; - int cnt=0,loop; - - // put TX on a far-away frequency to avoid interference in RX band - bladerf_set_frequency(brf->dev,BLADERF_MODULE_TX, (unsigned int) device->openair0_cfg->rx_freq[0] + 200e6); - // Set gains to close to max - bladerf_set_gain(brf->dev, BLADERF_MODULE_RX, 60); - bladerf_set_gain(brf->dev, BLADERF_MODULE_TX, 60); - - // fill TX buffer with fs/8 complex sinusoid - j=0; - for (i=0;i<RXDCLENGTH;i++) { - calib_tx_buff[j++] = cos_fsover8[i&7]; - calib_tx_buff[j++] = cos_fsover8[(i+6)&7]; // sin - } - calib_buffp = &calib_buff[0]; - calib_tx_buffp = &calib_tx_buff[0]; - // Calibrate RX DC offset - - offIold=offQold=2048; - bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_LMS_DCOFF_I,offIold); - bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_LMS_DCOFF_Q,offQold); - for (i=0;i<10;i++) - trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); - - for (meanIold=meanQold=i=j=0;i<RXDCLENGTH;i++) { - meanIold+=calib_buff[j++]; - meanQold+=calib_buff[j++]; - } - meanIold/=RXDCLENGTH; - meanQold/=RXDCLENGTH; - printf("[BRF] RX DC: (%d,%d) => (%d,%d)\n",offIold,offQold,meanIold,meanQold); - - offI=offQ=-2048; - bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_LMS_DCOFF_I,offI); - bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_LMS_DCOFF_Q,offQ); - for (i=0;i<10;i++) - trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); - - for (meanI=meanQ=i=j=0;i<RXDCLENGTH;i++) { - meanI+=calib_buff[j++]; - meanQ+=calib_buff[j++]; - } - meanI/=RXDCLENGTH; - meanQ/=RXDCLENGTH; - // printf("[BRF] RX DC: (%d,%d) => (%d,%d)\n",offI,offQ,meanI,meanQ); - - while (cnt++ < 12) { - - offInew=(offIold+offI)>>1; - offQnew=(offQold+offQ)>>1; - - if (meanI*meanI < meanIold*meanIold) { - meanIold = meanI; - offIold = offI; - printf("[BRF] *** RX DC: offI %d => %d\n",offIold,meanI); + /* TODO: this function does not seem to work. Disabled until fixed. */ + return; + + brf_state_t *brf = (brf_state_t *)device->priv; + openair0_timestamp ptimestamp; + int16_t *calib_buffp,*calib_tx_buffp; + int16_t calib_buff[2*RXDCLENGTH]; + int16_t calib_tx_buff[2*RXDCLENGTH]; + int i,j,offI,offQ,offIold,offQold,offInew,offQnew,offphase,offphaseold,offphasenew,offgain,offgainold,offgainnew; + int32_t meanI,meanQ,meanIold,meanQold; + int cnt=0,loop; + + // put TX on a far-away frequency to avoid interference in RX band + bladerf_set_frequency(brf->dev,BLADERF_MODULE_TX, (unsigned int) device->openair0_cfg->rx_freq[0] + 200e6); + // Set gains to close to max + bladerf_set_gain(brf->dev, BLADERF_MODULE_RX, 60); + bladerf_set_gain(brf->dev, BLADERF_MODULE_TX, 60); + + // fill TX buffer with fs/8 complex sinusoid + j=0; + for (i=0; i<RXDCLENGTH; i++) { + calib_tx_buff[j++] = cos_fsover8[i&7]; + calib_tx_buff[j++] = cos_fsover8[(i+6)&7]; // sin } - if (meanQ*meanQ < meanQold*meanQold) { - meanQold = meanQ; - offQold = offQ; - printf("[BRF] *** RX DC: offQ %d => %d\n",offQold,meanQ); + calib_buffp = &calib_buff[0]; + calib_tx_buffp = &calib_tx_buff[0]; + // Calibrate RX DC offset + + offIold=offQold=2048; + bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_LMS_DCOFF_I,offIold); + bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_LMS_DCOFF_Q,offQold); + for (i=0; i<10; i++) + trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); + + for (meanIold=meanQold=i=j=0; i<RXDCLENGTH; i++) { + meanIold+=calib_buff[j++]; + meanQold+=calib_buff[j++]; } - offI = offInew; - offQ = offQnew; + meanIold/=RXDCLENGTH; + meanQold/=RXDCLENGTH; + printf("[BRF] RX DC: (%d,%d) => (%d,%d)\n",offIold,offQold,meanIold,meanQold); + + offI=offQ=-2048; bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_LMS_DCOFF_I,offI); bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_LMS_DCOFF_Q,offQ); + for (i=0; i<10; i++) + trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); - for (i=0;i<10;i++) - trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); - - for (meanI=meanQ=i=j=0;i<RXDCLENGTH;i++) { - meanI+=calib_buff[j++]; - meanQ+=calib_buff[j++]; + for (meanI=meanQ=i=j=0; i<RXDCLENGTH; i++) { + meanI+=calib_buff[j++]; + meanQ+=calib_buff[j++]; } meanI/=RXDCLENGTH; meanQ/=RXDCLENGTH; - printf("[BRF] RX DC: (%d,%d) => (%d,%d)\n",offI,offQ,meanI,meanQ); - } - - printf("[BRF] RX DC: (%d,%d) => (%d,%d)\n",offIold,offQold,meanIold,meanQold); - bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_LMS_DCOFF_I,offIold); - bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_LMS_DCOFF_Q,offQold); - - // TX DC offset - // PUT TX as f_RX + fs/4 - // loop back BLADERF_LB_RF_LNA1 - bladerf_set_frequency(brf->dev,BLADERF_MODULE_TX, (unsigned int) device->openair0_cfg->rx_freq[0] + (unsigned int) device->openair0_cfg->sample_rate/4); - bladerf_set_loopback (brf->dev,BLADERF_LB_RF_LNA1); - - offIold=2048; - bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_LMS_DCOFF_I,offIold); - for (i=0;i<10;i++) { - trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); - trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); - } - for (meanIold=meanQold=i=j=0;i<RXDCLENGTH;i++) { - switch (i&3) { - case 0: - meanIold+=calib_buff[j++]; - break; - case 1: - meanQold+=calib_buff[j++]; - break; - case 2: - meanIold-=calib_buff[j++]; - break; - case 3: - meanQold-=calib_buff[j++]; - break; + // printf("[BRF] RX DC: (%d,%d) => (%d,%d)\n",offI,offQ,meanI,meanQ); + + while (cnt++ < 12) { + + offInew=(offIold+offI)>>1; + offQnew=(offQold+offQ)>>1; + + if (meanI*meanI < meanIold*meanIold) { + meanIold = meanI; + offIold = offI; + printf("[BRF] *** RX DC: offI %d => %d\n",offIold,meanI); + } + if (meanQ*meanQ < meanQold*meanQold) { + meanQold = meanQ; + offQold = offQ; + printf("[BRF] *** RX DC: offQ %d => %d\n",offQold,meanQ); + } + offI = offInew; + offQ = offQnew; + bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_LMS_DCOFF_I,offI); + bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_LMS_DCOFF_Q,offQ); + + for (i=0; i<10; i++) + trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); + + for (meanI=meanQ=i=j=0; i<RXDCLENGTH; i++) { + meanI+=calib_buff[j++]; + meanQ+=calib_buff[j++]; + } + meanI/=RXDCLENGTH; + meanQ/=RXDCLENGTH; + printf("[BRF] RX DC: (%d,%d) => (%d,%d)\n",offI,offQ,meanI,meanQ); } - } - // meanIold/=RXDCLENGTH; - // meanQold/=RXDCLENGTH; - printf("[BRF] TX DC (offI): %d => (%d,%d)\n",offIold,meanIold,meanQold); - - offI=-2048; - bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_LMS_DCOFF_I,offI); - for (i=0;i<10;i++) { - trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); - trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); - } - for (meanI=meanQ=i=j=0;i<RXDCLENGTH;i++) { - switch (i&3) { - case 0: - meanI+=calib_buff[j++]; - break; - case 1: - meanQ+=calib_buff[j++]; - break; - case 2: - meanI-=calib_buff[j++]; - break; - case 3: - meanQ-=calib_buff[j++]; - break; + + printf("[BRF] RX DC: (%d,%d) => (%d,%d)\n",offIold,offQold,meanIold,meanQold); + bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_LMS_DCOFF_I,offIold); + bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_LMS_DCOFF_Q,offQold); + + // TX DC offset + // PUT TX as f_RX + fs/4 + // loop back BLADERF_LB_RF_LNA1 + bladerf_set_frequency(brf->dev,BLADERF_MODULE_TX, (unsigned int) device->openair0_cfg->rx_freq[0] + (unsigned int) device->openair0_cfg->sample_rate/4); + bladerf_set_loopback (brf->dev,BLADERF_LB_RF_LNA1); + + offIold=2048; + bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_LMS_DCOFF_I,offIold); + for (i=0; i<10; i++) { + trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); + trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); } - } - // meanI/=RXDCLENGTH; - // meanQ/=RXDCLENGTH; - printf("[BRF] TX DC (offI): %d => (%d,%d)\n",offI,meanI,meanQ); - cnt = 0; - while (cnt++ < 12) { - - offInew=(offIold+offI)>>1; - if (meanI*meanI+meanQ*meanQ < meanIold*meanIold +meanQold*meanQold) { - printf("[BRF] TX DC (offI): ([%d,%d]) => %d : %d\n",offIold,offI,offInew,meanI*meanI+meanQ*meanQ); - meanIold = meanI; - meanQold = meanQ; - offIold = offI; + for (meanIold=meanQold=i=j=0; i<RXDCLENGTH; i++) { + switch (i&3) { + case 0: + meanIold+=calib_buff[j++]; + break; + case 1: + meanQold+=calib_buff[j++]; + break; + case 2: + meanIold-=calib_buff[j++]; + break; + case 3: + meanQold-=calib_buff[j++]; + break; + } } - offI = offInew; - bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_LMS_DCOFF_I,offI); + // meanIold/=RXDCLENGTH; + // meanQold/=RXDCLENGTH; + printf("[BRF] TX DC (offI): %d => (%d,%d)\n",offIold,meanIold,meanQold); - for (i=0;i<10;i++) { - trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); - trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); - } - for (meanI=meanQ=i=j=0;i<RXDCLENGTH;i++) { - switch (i&3) { - case 0: - meanI+=calib_buff[j++]; - break; - case 1: - meanQ+=calib_buff[j++]; - break; - case 2: - meanI-=calib_buff[j++]; - break; - case 3: - meanQ-=calib_buff[j++]; - break; - } + offI=-2048; + bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_LMS_DCOFF_I,offI); + for (i=0; i<10; i++) { + trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); + trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); } - // meanI/=RXDCLENGTH; - // meanQ/=RXDCLENGTH; - // printf("[BRF] TX DC (offI): %d => (%d,%d)\n",offI,meanI,meanQ); - } - - bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_LMS_DCOFF_I,offIold); - - offQold=2048; - bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_LMS_DCOFF_Q,offQold); - for (i=0;i<10;i++) { - trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); - trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); - } - // project on fs/4 - for (meanIold=meanQold=i=j=0;i<RXDCLENGTH;i++) { - switch (i&3) { - case 0: - meanIold+=calib_buff[j++]; - break; - case 1: - meanQold+=calib_buff[j++]; - break; - case 2: - meanIold-=calib_buff[j++]; - break; - case 3: - meanQold-=calib_buff[j++]; - break; + for (meanI=meanQ=i=j=0; i<RXDCLENGTH; i++) { + switch (i&3) { + case 0: + meanI+=calib_buff[j++]; + break; + case 1: + meanQ+=calib_buff[j++]; + break; + case 2: + meanI-=calib_buff[j++]; + break; + case 3: + meanQ-=calib_buff[j++]; + break; + } } - } - // meanIold/=RXDCLENGTH; - // meanQold/=RXDCLENGTH; - printf("[BRF] TX DC (offQ): %d => (%d,%d)\n",offQold,meanIold,meanQold); - - offQ=-2048; - bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_LMS_DCOFF_Q,offQ); - for (i=0;i<10;i++) { - trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); - trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); - } - for (meanI=meanQ=i=j=0;i<RXDCLENGTH;i++) { - switch (i&3) { - case 0: - meanI+=calib_buff[j++]; - break; - case 1: - meanQ+=calib_buff[j++]; - break; - case 2: - meanI-=calib_buff[j++]; - break; - case 3: - meanQ-=calib_buff[j++]; - break; + // meanI/=RXDCLENGTH; + // meanQ/=RXDCLENGTH; + printf("[BRF] TX DC (offI): %d => (%d,%d)\n",offI,meanI,meanQ); + cnt = 0; + while (cnt++ < 12) { + + offInew=(offIold+offI)>>1; + if (meanI*meanI+meanQ*meanQ < meanIold*meanIold +meanQold*meanQold) { + printf("[BRF] TX DC (offI): ([%d,%d]) => %d : %d\n",offIold,offI,offInew,meanI*meanI+meanQ*meanQ); + meanIold = meanI; + meanQold = meanQ; + offIold = offI; + } + offI = offInew; + bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_LMS_DCOFF_I,offI); + + for (i=0; i<10; i++) { + trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); + trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); + } + for (meanI=meanQ=i=j=0; i<RXDCLENGTH; i++) { + switch (i&3) { + case 0: + meanI+=calib_buff[j++]; + break; + case 1: + meanQ+=calib_buff[j++]; + break; + case 2: + meanI-=calib_buff[j++]; + break; + case 3: + meanQ-=calib_buff[j++]; + break; + } + } + // meanI/=RXDCLENGTH; + // meanQ/=RXDCLENGTH; + // printf("[BRF] TX DC (offI): %d => (%d,%d)\n",offI,meanI,meanQ); } - } - // meanI/=RXDCLENGTH; - // meanQ/=RXDCLENGTH; - printf("[BRF] TX DC (offQ): %d => (%d,%d)\n",offQ,meanI,meanQ); - - cnt=0; - while (cnt++ < 12) { - - offQnew=(offQold+offQ)>>1; - if (meanI*meanI+meanQ*meanQ < meanIold*meanIold +meanQold*meanQold) { - printf("[BRF] TX DC (offQ): ([%d,%d]) => %d : %d\n",offQold,offQ,offQnew,meanI*meanI+meanQ*meanQ); - meanIold = meanI; - meanQold = meanQ; - offQold = offQ; - } - offQ = offQnew; - bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_LMS_DCOFF_Q,offQ); + bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_LMS_DCOFF_I,offIold); - for (i=0;i<10;i++) { - trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); - trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); - } - for (meanI=meanQ=i=j=0;i<RXDCLENGTH;i++) { - switch (i&3) { - case 0: - meanI+=calib_buff[j++]; - break; - case 1: - meanQ+=calib_buff[j++]; - break; - case 2: - meanI-=calib_buff[j++]; - break; - case 3: - meanQ-=calib_buff[j++]; - break; - } + offQold=2048; + bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_LMS_DCOFF_Q,offQold); + for (i=0; i<10; i++) { + trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); + trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); } - // meanI/=RXDCLENGTH; - // meanQ/=RXDCLENGTH; - // printf("[BRF] TX DC (offQ): %d => (%d,%d)\n",offQ,meanI,meanQ); - } - - printf("[BRF] TX DC: (%d,%d) => (%d,%d)\n",offIold,offQold,meanIold,meanQold); - - bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_LMS_DCOFF_Q,offQold); - - // TX IQ imbalance - for (loop=0;loop<2;loop++) { - offphaseold=4096; - bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_FPGA_PHASE,offphaseold); - for (i=0;i<10;i++) { - trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); - trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); + // project on fs/4 + for (meanIold=meanQold=i=j=0; i<RXDCLENGTH; i++) { + switch (i&3) { + case 0: + meanIold+=calib_buff[j++]; + break; + case 1: + meanQold+=calib_buff[j++]; + break; + case 2: + meanIold-=calib_buff[j++]; + break; + case 3: + meanQold-=calib_buff[j++]; + break; + } } - // project on fs/8 (Image of TX signal in +ve frequencies) - for (meanIold=meanQold=i=j=0;i<RXDCLENGTH;i++) { - meanIold+= (calib_buff[j]*cos_fsover8[i&7] - calib_buff[j+1]*cos_fsover8[(i+2)&7])>>11; - meanQold+= (calib_buff[j]*cos_fsover8[(i+2)&7] + calib_buff[j+1]*cos_fsover8[i&7])>>11; - j+=2; - } - - meanIold/=RXDCLENGTH; - meanQold/=RXDCLENGTH; - printf("[BRF] TX IQ (offphase): %d => (%d,%d)\n",offphaseold,meanIold,meanQold); - - offphase=-4096; - bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_FPGA_PHASE,offphase); - for (i=0;i<10;i++) { - trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); - trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); - } - // project on fs/8 (Image of TX signal in +ve frequencies) - for (meanI=meanQ=i=j=0;i<RXDCLENGTH;i++) { - meanI+= (calib_buff[j]*cos_fsover8[i&7] - calib_buff[j+1]*cos_fsover8[(i+2)&7])>>11; - meanQ+= (calib_buff[j]*cos_fsover8[(i+2)&7] + calib_buff[j+1]*cos_fsover8[i&7])>>11; - j+=2; - } - - meanI/=RXDCLENGTH; - meanQ/=RXDCLENGTH; - printf("[BRF] TX IQ (offphase): %d => (%d,%d)\n",offphase,meanI,meanQ); - - cnt=0; - while (cnt++ < 13) { - - offphasenew=(offphaseold+offphase)>>1; - printf("[BRF] TX IQ (offphase): ([%d,%d]) => %d : %d\n",offphaseold,offphase,offphasenew,meanI*meanI+meanQ*meanQ); - if (meanI*meanI+meanQ*meanQ < meanIold*meanIold +meanQold*meanQold) { - - - meanIold = meanI; - meanQold = meanQ; - offphaseold = offphase; - } - offphase = offphasenew; - bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_FPGA_PHASE,offphase); - - for (i=0;i<10;i++) { - trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); - trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); - } - // project on fs/8 (Image of TX signal in +ve frequencies) - for (meanI=meanQ=i=j=0;i<RXDCLENGTH;i++) { - meanI+= (calib_buff[j]*cos_fsover8[i&7] - calib_buff[j+1]*cos_fsover8[(i+2)&7])>>11; - meanQ+= (calib_buff[j]*cos_fsover8[(i+2)&7] + calib_buff[j+1]*cos_fsover8[i&7])>>11; - j+=2; - } - meanI/=RXDCLENGTH; - meanQ/=RXDCLENGTH; - - // printf("[BRF] TX DC (offQ): %d => (%d,%d)\n",offQ,meanI,meanQ); - } - - printf("[BRF] TX IQ offphase: %d => (%d,%d)\n",offphaseold,meanIold,meanQold); - - bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_FPGA_PHASE,offphaseold); - - offgainold=4096; - bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_FPGA_GAIN,offgainold); - for (i=0;i<10;i++) { - trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); - trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); - } - // project on fs/8 (Image of TX signal in +ve frequencies) - for (meanIold=meanQold=i=j=0;i<RXDCLENGTH;i++) { - meanIold+= (calib_buff[j]*cos_fsover8[i&7] - calib_buff[j+1]*cos_fsover8[(i+2)&7])>>11; - meanQold+= (calib_buff[j]*cos_fsover8[(i+2)&7] + calib_buff[j+1]*cos_fsover8[i&7])>>11; - j+=2; - } - - meanIold/=RXDCLENGTH; - meanQold/=RXDCLENGTH; - printf("[BRF] TX IQ (offgain): %d => (%d,%d)\n",offgainold,meanIold,meanQold); - - offgain=-4096; - bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_FPGA_GAIN,offgain); - for (i=0;i<10;i++) { - trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); - trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); - } - // project on fs/8 (Image of TX signal in +ve frequencies) - for (meanI=meanQ=i=j=0;i<RXDCLENGTH;i++) { - meanI+= (calib_buff[j]*cos_fsover8[i&7] - calib_buff[j+1]*cos_fsover8[(i+2)&7])>>11; - meanQ+= (calib_buff[j]*cos_fsover8[(i+2)&7] + calib_buff[j+1]*cos_fsover8[i&7])>>11; - j+=2; - } - - meanI/=RXDCLENGTH; - meanQ/=RXDCLENGTH; - printf("[BRF] TX IQ (offgain): %d => (%d,%d)\n",offgain,meanI,meanQ); - - cnt=0; - while (cnt++ < 13) { - - offgainnew=(offgainold+offgain)>>1; - if (meanI*meanI+meanQ*meanQ < meanIold*meanIold +meanQold*meanQold) { - printf("[BRF] TX IQ (offgain): ([%d,%d]) => %d : %d\n",offgainold,offgain,offgainnew,meanI*meanI+meanQ*meanQ); - - meanIold = meanI; - meanQold = meanQ; - offgainold = offgain; - } - offgain = offgainnew; - bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_FPGA_GAIN,offgain); - - for (i=0;i<10;i++) { - trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); - trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); - } - // project on fs/8 (Image of TX signal in +ve frequencies) - for (meanI=meanQ=i=j=0;i<RXDCLENGTH;i++) { - meanI+= (calib_buff[j]*cos_fsover8[i&7] - calib_buff[j+1]*cos_fsover8[(i+2)&7])>>11; - meanQ+= (calib_buff[j]*cos_fsover8[(i+2)&7] + calib_buff[j+1]*cos_fsover8[i&7])>>11; - j+=2; - } - meanI/=RXDCLENGTH; - meanQ/=RXDCLENGTH; - - // printf("[BRF] TX DC (offQ): %d => (%d,%d)\n",offQ,meanI,meanQ); - } - - printf("[BRF] TX IQ offgain: %d => (%d,%d)\n",offgainold,meanIold,meanQold); - - bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_FPGA_GAIN,offgainold); - } - - // RX IQ imbalance - for (loop=0;loop<2;loop++) { - offphaseold=4096; - bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_FPGA_PHASE,offphaseold); - for (i=0;i<10;i++) { - trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); - trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); - } - // project on -3fs/8 (Image of TX signal in -ve frequencies) - for (meanIold=meanQold=i=j=0;i<RXDCLENGTH;i++) { - meanIold+= (calib_buff[j]*cos_3fsover8[i&7] - calib_buff[j+1]*cos_3fsover8[(i+2)&7])>>11; - meanQold+= (calib_buff[j]*cos_3fsover8[(i+2)&7] + calib_buff[j+1]*cos_3fsover8[i&7])>>11; - j+=2; - } - - meanIold/=RXDCLENGTH; - meanQold/=RXDCLENGTH; - printf("[BRF] RX IQ (offphase): %d => (%d,%d)\n",offphaseold,meanIold,meanQold); - - offphase=-4096; - bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_FPGA_PHASE,offphase); - for (i=0;i<10;i++) { - trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); - trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); + // meanIold/=RXDCLENGTH; + // meanQold/=RXDCLENGTH; + printf("[BRF] TX DC (offQ): %d => (%d,%d)\n",offQold,meanIold,meanQold); + + offQ=-2048; + bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_LMS_DCOFF_Q,offQ); + for (i=0; i<10; i++) { + trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); + trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); } - // project on -3fs/8 (Image of TX signal in -ve frequencies) - for (meanI=meanQ=i=j=0;i<RXDCLENGTH;i++) { - meanI+= (calib_buff[j]*cos_3fsover8[i&7] - calib_buff[j+1]*cos_3fsover8[(i+2)&7])>>11; - meanQ+= (calib_buff[j]*cos_3fsover8[(i+2)&7] + calib_buff[j+1]*cos_3fsover8[i&7])>>11; - j+=2; + for (meanI=meanQ=i=j=0; i<RXDCLENGTH; i++) { + switch (i&3) { + case 0: + meanI+=calib_buff[j++]; + break; + case 1: + meanQ+=calib_buff[j++]; + break; + case 2: + meanI-=calib_buff[j++]; + break; + case 3: + meanQ-=calib_buff[j++]; + break; + } } - - meanI/=RXDCLENGTH; - meanQ/=RXDCLENGTH; - printf("[BRF] RX IQ (offphase): %d => (%d,%d)\n",offphase,meanI,meanQ); - + // meanI/=RXDCLENGTH; + // meanQ/=RXDCLENGTH; + printf("[BRF] TX DC (offQ): %d => (%d,%d)\n",offQ,meanI,meanQ); + cnt=0; - while (cnt++ < 13) { - - offphasenew=(offphaseold+offphase)>>1; - printf("[BRF] RX IQ (offphase): ([%d,%d]) => %d : %d\n",offphaseold,offphase,offphasenew,meanI*meanI+meanQ*meanQ); - if (meanI*meanI+meanQ*meanQ < meanIold*meanIold +meanQold*meanQold) { - - - meanIold = meanI; - meanQold = meanQ; - offphaseold = offphase; - } - offphase = offphasenew; - bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_FPGA_PHASE,offphase); - - for (i=0;i<10;i++) { - trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); - trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); - } - // project on -3fs/8 (Image of TX signal in -ve frequencies) - for (meanI=meanQ=i=j=0;i<RXDCLENGTH;i++) { - meanI+= (calib_buff[j]*cos_3fsover8[i&7] - calib_buff[j+1]*cos_3fsover8[(i+2)&7])>>11; - meanQ+= (calib_buff[j]*cos_3fsover8[(i+2)&7] + calib_buff[j+1]*cos_3fsover8[i&7])>>11; - j+=2; - } - meanI/=RXDCLENGTH; - meanQ/=RXDCLENGTH; - - // printf("[BRF] TX DC (offQ): %d => (%d,%d)\n",offQ,meanI,meanQ); + while (cnt++ < 12) { + + offQnew=(offQold+offQ)>>1; + if (meanI*meanI+meanQ*meanQ < meanIold*meanIold +meanQold*meanQold) { + printf("[BRF] TX DC (offQ): ([%d,%d]) => %d : %d\n",offQold,offQ,offQnew,meanI*meanI+meanQ*meanQ); + + meanIold = meanI; + meanQold = meanQ; + offQold = offQ; + } + offQ = offQnew; + bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_LMS_DCOFF_Q,offQ); + + for (i=0; i<10; i++) { + trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); + trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); + } + for (meanI=meanQ=i=j=0; i<RXDCLENGTH; i++) { + switch (i&3) { + case 0: + meanI+=calib_buff[j++]; + break; + case 1: + meanQ+=calib_buff[j++]; + break; + case 2: + meanI-=calib_buff[j++]; + break; + case 3: + meanQ-=calib_buff[j++]; + break; + } + } + // meanI/=RXDCLENGTH; + // meanQ/=RXDCLENGTH; + // printf("[BRF] TX DC (offQ): %d => (%d,%d)\n",offQ,meanI,meanQ); } - - printf("[BRF] RX IQ offphase: %d => (%d,%d)\n",offphaseold,meanIold,meanQold); - - bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_FPGA_PHASE,offphaseold); - - offgainold=4096; - bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_FPGA_GAIN,offgainold); - for (i=0;i<10;i++) { - trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); - trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0,0); - } - // project on -3fs/8 (Image of TX signal in +ve frequencies) - for (meanIold=meanQold=i=j=0;i<RXDCLENGTH;i++) { - meanIold+= (calib_buff[j]*cos_3fsover8[i&7] - calib_buff[j+1]*cos_3fsover8[(i+2)&7])>>11; - meanQold+= (calib_buff[j]*cos_3fsover8[(i+2)&7] + calib_buff[j+1]*cos_3fsover8[i&7])>>11; - j+=2; - } - - meanIold/=RXDCLENGTH; - meanQold/=RXDCLENGTH; - printf("[BRF] RX IQ (offgain): %d => (%d,%d)\n",offgainold,meanIold,meanQold); - - offgain=-4096; - bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_FPGA_GAIN,offgain); - for (i=0;i<10;i++) { - trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); - trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); - } - // project on 3fs/8 (Image of TX signal in -ve frequencies) - for (meanI=meanQ=i=j=0;i<RXDCLENGTH;i++) { - meanI+= (calib_buff[j]*cos_3fsover8[i&7] - calib_buff[j+1]*cos_3fsover8[(i+2)&7])>>11; - meanQ+= (calib_buff[j]*cos_3fsover8[(i+2)&7] + calib_buff[j+1]*cos_3fsover8[i&7])>>11; - j+=2; + + printf("[BRF] TX DC: (%d,%d) => (%d,%d)\n",offIold,offQold,meanIold,meanQold); + + bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_LMS_DCOFF_Q,offQold); + + // TX IQ imbalance + for (loop=0; loop<2; loop++) { + offphaseold=4096; + bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_FPGA_PHASE,offphaseold); + for (i=0; i<10; i++) { + trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); + trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); + } + // project on fs/8 (Image of TX signal in +ve frequencies) + for (meanIold=meanQold=i=j=0; i<RXDCLENGTH; i++) { + meanIold+= (calib_buff[j]*cos_fsover8[i&7] - calib_buff[j+1]*cos_fsover8[(i+2)&7])>>11; + meanQold+= (calib_buff[j]*cos_fsover8[(i+2)&7] + calib_buff[j+1]*cos_fsover8[i&7])>>11; + j+=2; + } + + meanIold/=RXDCLENGTH; + meanQold/=RXDCLENGTH; + printf("[BRF] TX IQ (offphase): %d => (%d,%d)\n",offphaseold,meanIold,meanQold); + + offphase=-4096; + bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_FPGA_PHASE,offphase); + for (i=0; i<10; i++) { + trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); + trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); + } + // project on fs/8 (Image of TX signal in +ve frequencies) + for (meanI=meanQ=i=j=0; i<RXDCLENGTH; i++) { + meanI+= (calib_buff[j]*cos_fsover8[i&7] - calib_buff[j+1]*cos_fsover8[(i+2)&7])>>11; + meanQ+= (calib_buff[j]*cos_fsover8[(i+2)&7] + calib_buff[j+1]*cos_fsover8[i&7])>>11; + j+=2; + } + + meanI/=RXDCLENGTH; + meanQ/=RXDCLENGTH; + printf("[BRF] TX IQ (offphase): %d => (%d,%d)\n",offphase,meanI,meanQ); + + cnt=0; + while (cnt++ < 13) { + + offphasenew=(offphaseold+offphase)>>1; + printf("[BRF] TX IQ (offphase): ([%d,%d]) => %d : %d\n",offphaseold,offphase,offphasenew,meanI*meanI+meanQ*meanQ); + if (meanI*meanI+meanQ*meanQ < meanIold*meanIold +meanQold*meanQold) { + + + meanIold = meanI; + meanQold = meanQ; + offphaseold = offphase; + } + offphase = offphasenew; + bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_FPGA_PHASE,offphase); + + for (i=0; i<10; i++) { + trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); + trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); + } + // project on fs/8 (Image of TX signal in +ve frequencies) + for (meanI=meanQ=i=j=0; i<RXDCLENGTH; i++) { + meanI+= (calib_buff[j]*cos_fsover8[i&7] - calib_buff[j+1]*cos_fsover8[(i+2)&7])>>11; + meanQ+= (calib_buff[j]*cos_fsover8[(i+2)&7] + calib_buff[j+1]*cos_fsover8[i&7])>>11; + j+=2; + } + meanI/=RXDCLENGTH; + meanQ/=RXDCLENGTH; + + // printf("[BRF] TX DC (offQ): %d => (%d,%d)\n",offQ,meanI,meanQ); + } + + printf("[BRF] TX IQ offphase: %d => (%d,%d)\n",offphaseold,meanIold,meanQold); + + bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_FPGA_PHASE,offphaseold); + + offgainold=4096; + bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_FPGA_GAIN,offgainold); + for (i=0; i<10; i++) { + trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); + trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); + } + // project on fs/8 (Image of TX signal in +ve frequencies) + for (meanIold=meanQold=i=j=0; i<RXDCLENGTH; i++) { + meanIold+= (calib_buff[j]*cos_fsover8[i&7] - calib_buff[j+1]*cos_fsover8[(i+2)&7])>>11; + meanQold+= (calib_buff[j]*cos_fsover8[(i+2)&7] + calib_buff[j+1]*cos_fsover8[i&7])>>11; + j+=2; + } + + meanIold/=RXDCLENGTH; + meanQold/=RXDCLENGTH; + printf("[BRF] TX IQ (offgain): %d => (%d,%d)\n",offgainold,meanIold,meanQold); + + offgain=-4096; + bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_FPGA_GAIN,offgain); + for (i=0; i<10; i++) { + trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); + trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); + } + // project on fs/8 (Image of TX signal in +ve frequencies) + for (meanI=meanQ=i=j=0; i<RXDCLENGTH; i++) { + meanI+= (calib_buff[j]*cos_fsover8[i&7] - calib_buff[j+1]*cos_fsover8[(i+2)&7])>>11; + meanQ+= (calib_buff[j]*cos_fsover8[(i+2)&7] + calib_buff[j+1]*cos_fsover8[i&7])>>11; + j+=2; + } + + meanI/=RXDCLENGTH; + meanQ/=RXDCLENGTH; + printf("[BRF] TX IQ (offgain): %d => (%d,%d)\n",offgain,meanI,meanQ); + + cnt=0; + while (cnt++ < 13) { + + offgainnew=(offgainold+offgain)>>1; + if (meanI*meanI+meanQ*meanQ < meanIold*meanIold +meanQold*meanQold) { + printf("[BRF] TX IQ (offgain): ([%d,%d]) => %d : %d\n",offgainold,offgain,offgainnew,meanI*meanI+meanQ*meanQ); + + meanIold = meanI; + meanQold = meanQ; + offgainold = offgain; + } + offgain = offgainnew; + bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_FPGA_GAIN,offgain); + + for (i=0; i<10; i++) { + trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); + trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); + } + // project on fs/8 (Image of TX signal in +ve frequencies) + for (meanI=meanQ=i=j=0; i<RXDCLENGTH; i++) { + meanI+= (calib_buff[j]*cos_fsover8[i&7] - calib_buff[j+1]*cos_fsover8[(i+2)&7])>>11; + meanQ+= (calib_buff[j]*cos_fsover8[(i+2)&7] + calib_buff[j+1]*cos_fsover8[i&7])>>11; + j+=2; + } + meanI/=RXDCLENGTH; + meanQ/=RXDCLENGTH; + + // printf("[BRF] TX DC (offQ): %d => (%d,%d)\n",offQ,meanI,meanQ); + } + + printf("[BRF] TX IQ offgain: %d => (%d,%d)\n",offgainold,meanIold,meanQold); + + bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_FPGA_GAIN,offgainold); } - - meanI/=RXDCLENGTH; - meanQ/=RXDCLENGTH; - printf("[BRF] RX IQ (offgain): %d => (%d,%d)\n",offgain,meanI,meanQ); - - cnt=0; - while (cnt++ < 13) { - - offgainnew=(offgainold+offgain)>>1; - if (meanI*meanI+meanQ*meanQ < meanIold*meanIold +meanQold*meanQold) { - printf("[BRF] RX IQ (offgain): ([%d,%d]) => %d : %d\n",offgainold,offgain,offgainnew,meanI*meanI+meanQ*meanQ); - - meanIold = meanI; - meanQold = meanQ; - offgainold = offgain; - } - offgain = offgainnew; - bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_FPGA_GAIN,offgain); - - for (i=0;i<10;i++) { - trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); - trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); - } - // project on -3fs/8 (Image of TX signal in -ve frequencies) - for (meanI=meanQ=i=j=0;i<RXDCLENGTH;i++) { - meanI+= (calib_buff[j]*cos_3fsover8[i&7] - calib_buff[j+1]*cos_3fsover8[(i+2)&7])>>11; - meanQ+= (calib_buff[j]*cos_3fsover8[(i+2)&7] + calib_buff[j+1]*cos_3fsover8[i&7])>>11; - j+=2; - } - meanI/=RXDCLENGTH; - meanQ/=RXDCLENGTH; - - // printf("[BRF] TX DC (offQ): %d => (%d,%d)\n",offQ,meanI,meanQ); + + // RX IQ imbalance + for (loop=0; loop<2; loop++) { + offphaseold=4096; + bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_FPGA_PHASE,offphaseold); + for (i=0; i<10; i++) { + trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); + trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); + } + // project on -3fs/8 (Image of TX signal in -ve frequencies) + for (meanIold=meanQold=i=j=0; i<RXDCLENGTH; i++) { + meanIold+= (calib_buff[j]*cos_3fsover8[i&7] - calib_buff[j+1]*cos_3fsover8[(i+2)&7])>>11; + meanQold+= (calib_buff[j]*cos_3fsover8[(i+2)&7] + calib_buff[j+1]*cos_3fsover8[i&7])>>11; + j+=2; + } + + meanIold/=RXDCLENGTH; + meanQold/=RXDCLENGTH; + printf("[BRF] RX IQ (offphase): %d => (%d,%d)\n",offphaseold,meanIold,meanQold); + + offphase=-4096; + bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_FPGA_PHASE,offphase); + for (i=0; i<10; i++) { + trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); + trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); + } + // project on -3fs/8 (Image of TX signal in -ve frequencies) + for (meanI=meanQ=i=j=0; i<RXDCLENGTH; i++) { + meanI+= (calib_buff[j]*cos_3fsover8[i&7] - calib_buff[j+1]*cos_3fsover8[(i+2)&7])>>11; + meanQ+= (calib_buff[j]*cos_3fsover8[(i+2)&7] + calib_buff[j+1]*cos_3fsover8[i&7])>>11; + j+=2; + } + + meanI/=RXDCLENGTH; + meanQ/=RXDCLENGTH; + printf("[BRF] RX IQ (offphase): %d => (%d,%d)\n",offphase,meanI,meanQ); + + cnt=0; + while (cnt++ < 13) { + + offphasenew=(offphaseold+offphase)>>1; + printf("[BRF] RX IQ (offphase): ([%d,%d]) => %d : %d\n",offphaseold,offphase,offphasenew,meanI*meanI+meanQ*meanQ); + if (meanI*meanI+meanQ*meanQ < meanIold*meanIold +meanQold*meanQold) { + + + meanIold = meanI; + meanQold = meanQ; + offphaseold = offphase; + } + offphase = offphasenew; + bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_FPGA_PHASE,offphase); + + for (i=0; i<10; i++) { + trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); + trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); + } + // project on -3fs/8 (Image of TX signal in -ve frequencies) + for (meanI=meanQ=i=j=0; i<RXDCLENGTH; i++) { + meanI+= (calib_buff[j]*cos_3fsover8[i&7] - calib_buff[j+1]*cos_3fsover8[(i+2)&7])>>11; + meanQ+= (calib_buff[j]*cos_3fsover8[(i+2)&7] + calib_buff[j+1]*cos_3fsover8[i&7])>>11; + j+=2; + } + meanI/=RXDCLENGTH; + meanQ/=RXDCLENGTH; + + // printf("[BRF] TX DC (offQ): %d => (%d,%d)\n",offQ,meanI,meanQ); + } + + printf("[BRF] RX IQ offphase: %d => (%d,%d)\n",offphaseold,meanIold,meanQold); + + bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_FPGA_PHASE,offphaseold); + + offgainold=4096; + bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_FPGA_GAIN,offgainold); + for (i=0; i<10; i++) { + trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); + trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0,0); + } + // project on -3fs/8 (Image of TX signal in +ve frequencies) + for (meanIold=meanQold=i=j=0; i<RXDCLENGTH; i++) { + meanIold+= (calib_buff[j]*cos_3fsover8[i&7] - calib_buff[j+1]*cos_3fsover8[(i+2)&7])>>11; + meanQold+= (calib_buff[j]*cos_3fsover8[(i+2)&7] + calib_buff[j+1]*cos_3fsover8[i&7])>>11; + j+=2; + } + + meanIold/=RXDCLENGTH; + meanQold/=RXDCLENGTH; + printf("[BRF] RX IQ (offgain): %d => (%d,%d)\n",offgainold,meanIold,meanQold); + + offgain=-4096; + bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_FPGA_GAIN,offgain); + for (i=0; i<10; i++) { + trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); + trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); + } + // project on 3fs/8 (Image of TX signal in -ve frequencies) + for (meanI=meanQ=i=j=0; i<RXDCLENGTH; i++) { + meanI+= (calib_buff[j]*cos_3fsover8[i&7] - calib_buff[j+1]*cos_3fsover8[(i+2)&7])>>11; + meanQ+= (calib_buff[j]*cos_3fsover8[(i+2)&7] + calib_buff[j+1]*cos_3fsover8[i&7])>>11; + j+=2; + } + + meanI/=RXDCLENGTH; + meanQ/=RXDCLENGTH; + printf("[BRF] RX IQ (offgain): %d => (%d,%d)\n",offgain,meanI,meanQ); + + cnt=0; + while (cnt++ < 13) { + + offgainnew=(offgainold+offgain)>>1; + if (meanI*meanI+meanQ*meanQ < meanIold*meanIold +meanQold*meanQold) { + printf("[BRF] RX IQ (offgain): ([%d,%d]) => %d : %d\n",offgainold,offgain,offgainnew,meanI*meanI+meanQ*meanQ); + + meanIold = meanI; + meanQold = meanQ; + offgainold = offgain; + } + offgain = offgainnew; + bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_FPGA_GAIN,offgain); + + for (i=0; i<10; i++) { + trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); + trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); + } + // project on -3fs/8 (Image of TX signal in -ve frequencies) + for (meanI=meanQ=i=j=0; i<RXDCLENGTH; i++) { + meanI+= (calib_buff[j]*cos_3fsover8[i&7] - calib_buff[j+1]*cos_3fsover8[(i+2)&7])>>11; + meanQ+= (calib_buff[j]*cos_3fsover8[(i+2)&7] + calib_buff[j+1]*cos_3fsover8[i&7])>>11; + j+=2; + } + meanI/=RXDCLENGTH; + meanQ/=RXDCLENGTH; + + // printf("[BRF] TX DC (offQ): %d => (%d,%d)\n",offQ,meanI,meanQ); + } + + printf("[BRF] RX IQ offgain: %d => (%d,%d)\n",offgainold,meanIold,meanQold); + + bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_FPGA_GAIN,offgainold); } - - printf("[BRF] RX IQ offgain: %d => (%d,%d)\n",offgainold,meanIold,meanQold); - - bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_FPGA_GAIN,offgainold); - } - - bladerf_set_frequency(brf->dev,BLADERF_MODULE_TX, (unsigned int) device->openair0_cfg->tx_freq[0]); - bladerf_set_loopback(brf->dev,BLADERF_LB_NONE); - bladerf_set_gain(brf->dev, BLADERF_MODULE_RX, (unsigned int) device->openair0_cfg->rx_gain[0]-device->openair0_cfg[0].rx_gain_offset[0]); - bladerf_set_gain(brf->dev, BLADERF_MODULE_TX, (unsigned int) device->openair0_cfg->tx_gain[0]); - // LOG_M("blade_rf_test.m","rxs",calib_buff,RXDCLENGTH,1,1); + + bladerf_set_frequency(brf->dev,BLADERF_MODULE_TX, (unsigned int) device->openair0_cfg->tx_freq[0]); + bladerf_set_loopback(brf->dev,BLADERF_LB_NONE); + bladerf_set_gain(brf->dev, BLADERF_MODULE_RX, (unsigned int) device->openair0_cfg->rx_gain[0]-device->openair0_cfg[0].rx_gain_offset[0]); + bladerf_set_gain(brf->dev, BLADERF_MODULE_TX, (unsigned int) device->openair0_cfg->tx_gain[0]); + // LOG_M("blade_rf_test.m","rxs",calib_buff,RXDCLENGTH,1,1); } -/*! \brief Initialize Openair BLADERF target. It returns 0 if OK +/*! \brief Initialize Openair BLADERF target. It returns 0 if OK * \param device the hardware to use * \param openair0_cfg RF frontend parameters set by application * \returns 0 on success */ int device_init(openair0_device *device, openair0_config_t *openair0_cfg) { - int status; - brf_state_t *brf = (brf_state_t*)malloc(sizeof(brf_state_t)); - memset(brf, 0, sizeof(brf_state_t)); - /* device specific */ - //openair0_cfg->txlaunch_wait = 1;//manage when TX processing is triggered - //openair0_cfg->txlaunch_wait_slotcount = 1; //manage when TX processing is triggered - openair0_cfg->iq_txshift = 0;// shift - openair0_cfg->iq_rxrescale = 15;//rescale iqs - - // init required params - switch ((int)openair0_cfg->sample_rate) { - case 30720000: - openair0_cfg->samples_per_packet = 2048; - openair0_cfg->tx_sample_advance = 0; - break; - case 15360000: - openair0_cfg->samples_per_packet = 2048; - openair0_cfg->tx_sample_advance = 0; - break; - case 7680000: - openair0_cfg->samples_per_packet = 1024; - openair0_cfg->tx_sample_advance = 0; - break; - case 1920000: - openair0_cfg->samples_per_packet = 256; - openair0_cfg->tx_sample_advance = 50; - break; - default: - printf("Error: unknown sampling rate %f\n",openair0_cfg->sample_rate); - exit(-1); - break; - } - openair0_cfg->iq_txshift= 0; - openair0_cfg->iq_rxrescale = 15; /*not sure*/ - openair0_cfg->rx_gain_calib_table = calib_table_fx4; - - // The number of buffers to use in the underlying data stream - brf->num_buffers = 128; - // the size of the underlying stream buffers, in samples - brf->buffer_size = (unsigned int) openair0_cfg->samples_per_packet;//*sizeof(int32_t); // buffer size = 4096 for sample_len of 1024 - brf->num_transfers = 16; - brf->rx_timeout_ms = 0; - brf->tx_timeout_ms = 0; - brf->sample_rate=(unsigned int)openair0_cfg->sample_rate; - - memset(&brf->meta_rx, 0, sizeof(brf->meta_rx)); - memset(&brf->meta_tx, 0, sizeof(brf->meta_tx)); - - printf("\n[BRF] sampling_rate %d, num_buffers %d, buffer_size %d, num transfer %d, timeout_ms (rx %d, tx %d)\n", - brf->sample_rate, brf->num_buffers, brf->buffer_size,brf->num_transfers, brf->rx_timeout_ms, brf->tx_timeout_ms); - - if ((status=bladerf_open(&brf->dev, "")) != 0 ) { - fprintf(stderr,"Failed to open brf device: %s\n",bladerf_strerror(status)); - brf_error(status); - } - printf("[BRF] init dev %p\n", brf->dev); - switch(bladerf_device_speed(brf->dev)){ - case BLADERF_DEVICE_SPEED_SUPER: - printf("[BRF] Device operates at max speed\n"); - break; - default: - printf("[BRF] Device does not operates at max speed, change the USB port\n"); - brf_error(BLADERF_ERR_UNSUPPORTED); - } - // RX - // Example of CLI output: RX Frequency: 2539999999Hz - - - if ((status=bladerf_set_gain_mode(brf->dev, BLADERF_MODULE_RX, BLADERF_GAIN_MGC))) { - fprintf(stderr, "[BRF] Failed to disable AGC\n"); - brf_error(status); - } - - if ((status=bladerf_set_frequency(brf->dev, BLADERF_MODULE_RX, (unsigned int) openair0_cfg->rx_freq[0])) != 0){ - fprintf(stderr,"Failed to set RX frequency: %s\n",bladerf_strerror(status)); - brf_error(status); - } else - printf("[BRF] set RX frequency to %u\n",(unsigned int)openair0_cfg->rx_freq[0]); - - - - unsigned int actual_value=0; - if ((status=bladerf_set_sample_rate(brf->dev, BLADERF_MODULE_RX, (unsigned int) openair0_cfg->sample_rate, &actual_value)) != 0){ - fprintf(stderr,"Failed to set RX sample rate: %s\n", bladerf_strerror(status)); - brf_error(status); - }else - printf("[BRF] set RX sample rate to %u, %u\n", (unsigned int) openair0_cfg->sample_rate, actual_value); - - - if ((status=bladerf_set_bandwidth(brf->dev, BLADERF_MODULE_RX, (unsigned int) openair0_cfg->rx_bw*2, &actual_value)) != 0){ - fprintf(stderr,"Failed to set RX bandwidth: %s\n", bladerf_strerror(status)); - brf_error(status); - }else - printf("[BRF] set RX bandwidth to %u, %u\n",(unsigned int)openair0_cfg->rx_bw*2, actual_value); - - set_rx_gain_offset(&openair0_cfg[0],0); - if ((status=bladerf_set_gain(brf->dev, BLADERF_MODULE_RX, (int) openair0_cfg->rx_gain[0]-openair0_cfg[0].rx_gain_offset[0])) != 0) { - fprintf(stderr,"Failed to set RX gain: %s\n",bladerf_strerror(status)); - brf_error(status); - } else - printf("[BRF] set RX gain to %d (%d)\n",(int)(openair0_cfg->rx_gain[0]-openair0_cfg[0].rx_gain_offset[0]),(int)openair0_cfg[0].rx_gain_offset[0]); - - // TX - - if ((status=bladerf_set_frequency(brf->dev, BLADERF_MODULE_TX, (unsigned int) openair0_cfg->tx_freq[0])) != 0){ - fprintf(stderr,"Failed to set TX frequency: %s\n",bladerf_strerror(status)); - brf_error(status); - }else - printf("[BRF] set TX Frequency to %u\n", (unsigned int) openair0_cfg->tx_freq[0]); - - if ((status=bladerf_set_sample_rate(brf->dev, BLADERF_MODULE_TX, (unsigned int) openair0_cfg->sample_rate, NULL)) != 0){ - fprintf(stderr,"Failed to set TX sample rate: %s\n", bladerf_strerror(status)); - brf_error(status); - }else - printf("[BRF] set TX sampling rate to %u \n", (unsigned int) openair0_cfg->sample_rate); - - if ((status=bladerf_set_bandwidth(brf->dev, BLADERF_MODULE_TX,(unsigned int)openair0_cfg->tx_bw*2, NULL)) != 0){ - fprintf(stderr, "Failed to set TX bandwidth: %s\n", bladerf_strerror(status)); - brf_error(status); - }else - printf("[BRF] set TX bandwidth to %u \n", (unsigned int) openair0_cfg->tx_bw*2); - - if ((status=bladerf_set_gain(brf->dev, BLADERF_MODULE_TX, (int) openair0_cfg->tx_gain[0])) != 0) { - fprintf(stderr,"Failed to set TX gain: %s\n",bladerf_strerror(status)); - brf_error(status); - }else - printf("[BRF] set the TX gain to %d\n", (int)openair0_cfg->tx_gain[0]); - - - /* Configure the device's TX module for use with the sync interface. - * SC16 Q11 samples *with* metadata are used. */ - if ((status=bladerf_sync_config(brf->dev, BLADERF_MODULE_TX,BLADERF_FORMAT_SC16_Q11_META,brf->num_buffers,brf->buffer_size,brf->num_transfers,brf->tx_timeout_ms)) != 0 ) { - fprintf(stderr,"Failed to configure TX sync interface: %s\n", bladerf_strerror(status)); - brf_error(status); - }else - printf("[BRF] configured TX sync interface \n"); - -/* Configure the device's RX module for use with the sync interface. - * SC16 Q11 samples *with* metadata are used. */ - if ((status=bladerf_sync_config(brf->dev, BLADERF_MODULE_RX, BLADERF_FORMAT_SC16_Q11_META,brf->num_buffers,brf->buffer_size,brf->num_transfers,brf->rx_timeout_ms)) != 0 ) { - fprintf(stderr,"Failed to configure RX sync interface: %s\n", bladerf_strerror(status)); - brf_error(status); - }else - printf("[BRF] configured Rx sync interface \n"); - - - /* We must always enable the TX module after calling bladerf_sync_config(), and - * before attempting to TX samples via bladerf_sync_tx(). */ - if ((status=bladerf_enable_module(brf->dev, BLADERF_MODULE_TX, true)) != 0) { - fprintf(stderr,"Failed to enable TX module: %s\n", bladerf_strerror(status)); - brf_error(status); - } else - printf("[BRF] TX module enabled \n"); - - /* We must always enable the RX module after calling bladerf_sync_config(), and - * before attempting to RX samples via bladerf_sync_rx(). */ - if ((status=bladerf_enable_module(brf->dev, BLADERF_MODULE_RX, true)) != 0) { - fprintf(stderr,"Failed to enable RX module: %s\n", bladerf_strerror(status)); - brf_error(status); - }else - printf("[BRF] RX module enabled \n"); - - // calibrate - - if ((status=bladerf_calibrate_dc(brf->dev, BLADERF_DC_CAL_LPF_TUNING)) != 0 || - (status=bladerf_calibrate_dc(brf->dev, BLADERF_DC_CAL_TX_LPF)) != 0 || - (status=bladerf_calibrate_dc(brf->dev, BLADERF_DC_CAL_RX_LPF)) != 0 || - (status=bladerf_calibrate_dc(brf->dev, BLADERF_DC_CAL_RXVGA2)) != 0) { - fprintf(stderr, "[BRF] error calibrating\n"); - brf_error(status); - } else - printf("[BRF] calibration OK\n"); - - bladerf_log_set_verbosity(get_brf_log_level(openair0_cfg->log_level)); - - printf("BLADERF: Initializing openair0_device\n"); - device->Mod_id = num_devices++; - device->type = BLADERF_DEV; - device->trx_start_func = trx_brf_start; - device->trx_end_func = trx_brf_end; - device->trx_read_func = trx_brf_read; - device->trx_write_func = trx_brf_write; - device->trx_get_stats_func = trx_brf_get_stats; - device->trx_reset_stats_func = trx_brf_reset_stats; - device->trx_stop_func = trx_brf_stop; - device->trx_set_freq_func = trx_brf_set_freq; - device->trx_set_gains_func = trx_brf_set_gains; - device->openair0_cfg = openair0_cfg; - device->priv = (void *)brf; - - calibrate_rf(device); - - // memcpy((void*)&device->openair0_cfg,(void*)&openair0_cfg[0],sizeof(openair0_config_t)); - - if ((status=bladerf_enable_module(brf->dev, BLADERF_MODULE_TX, false)) != 0) { - fprintf(stderr,"Failed to enable TX module: %s\n", bladerf_strerror(status)); - abort(); - } - if ((status=bladerf_enable_module(brf->dev, BLADERF_MODULE_RX, false)) != 0) { - fprintf(stderr,"Failed to enable RX module: %s\n", bladerf_strerror(status)); - abort(); - } - - return 0; + int status; + brf_state_t *brf = (brf_state_t*)malloc(sizeof(brf_state_t)); + memset(brf, 0, sizeof(brf_state_t)); + /* device specific */ + //openair0_cfg->txlaunch_wait = 1;//manage when TX processing is triggered + //openair0_cfg->txlaunch_wait_slotcount = 1; //manage when TX processing is triggered + openair0_cfg->iq_txshift = 0;// shift + openair0_cfg->iq_rxrescale = 15;//rescale iqs + + // init required params + switch ((int)openair0_cfg->sample_rate) { + case 30720000: + openair0_cfg->samples_per_packet = 2048; + openair0_cfg->tx_sample_advance = 0; + break; + case 15360000: + openair0_cfg->samples_per_packet = 2048; + openair0_cfg->tx_sample_advance = 0; + break; + case 7680000: + openair0_cfg->samples_per_packet = 1024; + openair0_cfg->tx_sample_advance = 0; + break; + case 1920000: + openair0_cfg->samples_per_packet = 256; + openair0_cfg->tx_sample_advance = 50; + break; + default: + printf("Error: unknown sampling rate %f\n",openair0_cfg->sample_rate); + exit(-1); + break; + } + openair0_cfg->iq_txshift= 0; + openair0_cfg->iq_rxrescale = 15; /*not sure*/ + openair0_cfg->rx_gain_calib_table = calib_table_fx4; + + // The number of buffers to use in the underlying data stream + brf->num_buffers = 128; + // the size of the underlying stream buffers, in samples + brf->buffer_size = (unsigned int) openair0_cfg->samples_per_packet;//*sizeof(int32_t); // buffer size = 4096 for sample_len of 1024 + brf->num_transfers = 16; + brf->rx_timeout_ms = 0; + brf->tx_timeout_ms = 0; + brf->sample_rate=(unsigned int)openair0_cfg->sample_rate; + + memset(&brf->meta_rx, 0, sizeof(brf->meta_rx)); + memset(&brf->meta_tx, 0, sizeof(brf->meta_tx)); + + printf("\n[BRF] sampling_rate %u, num_buffers %u, buffer_size %u, num transfer %u, timeout_ms (rx %u, tx %u)\n", + brf->sample_rate, brf->num_buffers, brf->buffer_size,brf->num_transfers, brf->rx_timeout_ms, brf->tx_timeout_ms); + + if ((status=bladerf_open(&brf->dev, "")) != 0 ) { + fprintf(stderr,"Failed to open brf device: %s\n",bladerf_strerror(status)); + brf_error(status); + } + printf("[BRF] init dev %p\n", brf->dev); + switch(bladerf_device_speed(brf->dev)) { + case BLADERF_DEVICE_SPEED_SUPER: + printf("[BRF] Device operates at max speed\n"); + break; + default: + printf("[BRF] Device does not operates at max speed, change the USB port\n"); + brf_error(BLADERF_ERR_UNSUPPORTED); + } + // RX + // Example of CLI output: RX Frequency: 2539999999Hz + + + if ((status=bladerf_set_gain_mode(brf->dev, BLADERF_MODULE_RX, BLADERF_GAIN_MGC))) { + fprintf(stderr, "[BRF] Failed to disable AGC\n"); + brf_error(status); + } + + if ((status=bladerf_set_frequency(brf->dev, BLADERF_MODULE_RX, (unsigned int) openair0_cfg->rx_freq[0])) != 0) { + fprintf(stderr,"Failed to set RX frequency: %s\n",bladerf_strerror(status)); + brf_error(status); + } else + printf("[BRF] set RX frequency to %u\n",(unsigned int)openair0_cfg->rx_freq[0]); + + + + unsigned int actual_value=0; + if ((status=bladerf_set_sample_rate(brf->dev, BLADERF_MODULE_RX, (unsigned int) openair0_cfg->sample_rate, &actual_value)) != 0) { + fprintf(stderr,"Failed to set RX sample rate: %s\n", bladerf_strerror(status)); + brf_error(status); + } else + printf("[BRF] set RX sample rate to %u, %u\n", (unsigned int) openair0_cfg->sample_rate, actual_value); + + + if ((status=bladerf_set_bandwidth(brf->dev, BLADERF_MODULE_RX, (unsigned int) openair0_cfg->rx_bw*2, &actual_value)) != 0) { + fprintf(stderr,"Failed to set RX bandwidth: %s\n", bladerf_strerror(status)); + brf_error(status); + } else + printf("[BRF] set RX bandwidth to %u, %u\n",(unsigned int)openair0_cfg->rx_bw*2, actual_value); + + set_rx_gain_offset(&openair0_cfg[0],0); + if ((status=bladerf_set_gain(brf->dev, BLADERF_MODULE_RX, (int) openair0_cfg->rx_gain[0]-openair0_cfg[0].rx_gain_offset[0])) != 0) { + fprintf(stderr,"Failed to set RX gain: %s\n",bladerf_strerror(status)); + brf_error(status); + } else + printf("[BRF] set RX gain to %d (%d)\n",(int)(openair0_cfg->rx_gain[0]-openair0_cfg[0].rx_gain_offset[0]),(int)openair0_cfg[0].rx_gain_offset[0]); + + // TX + + if ((status=bladerf_set_frequency(brf->dev, BLADERF_MODULE_TX, (unsigned int) openair0_cfg->tx_freq[0])) != 0) { + fprintf(stderr,"Failed to set TX frequency: %s\n",bladerf_strerror(status)); + brf_error(status); + } else + printf("[BRF] set TX Frequency to %u\n", (unsigned int) openair0_cfg->tx_freq[0]); + + if ((status=bladerf_set_sample_rate(brf->dev, BLADERF_MODULE_TX, (unsigned int) openair0_cfg->sample_rate, NULL)) != 0) { + fprintf(stderr,"Failed to set TX sample rate: %s\n", bladerf_strerror(status)); + brf_error(status); + } else + printf("[BRF] set TX sampling rate to %u \n", (unsigned int) openair0_cfg->sample_rate); + + if ((status=bladerf_set_bandwidth(brf->dev, BLADERF_MODULE_TX,(unsigned int)openair0_cfg->tx_bw*2, NULL)) != 0) { + fprintf(stderr, "Failed to set TX bandwidth: %s\n", bladerf_strerror(status)); + brf_error(status); + } else + printf("[BRF] set TX bandwidth to %u \n", (unsigned int) openair0_cfg->tx_bw*2); + + if ((status=bladerf_set_gain(brf->dev, BLADERF_MODULE_TX, (int) openair0_cfg->tx_gain[0])) != 0) { + fprintf(stderr,"Failed to set TX gain: %s\n",bladerf_strerror(status)); + brf_error(status); + } else + printf("[BRF] set the TX gain to %d\n", (int)openair0_cfg->tx_gain[0]); + + + /* Configure the device's TX module for use with the sync interface. + * SC16 Q11 samples *with* metadata are used. */ + if ((status=bladerf_sync_config(brf->dev, BLADERF_MODULE_TX,BLADERF_FORMAT_SC16_Q11_META,brf->num_buffers,brf->buffer_size,brf->num_transfers,brf->tx_timeout_ms)) != 0 ) { + fprintf(stderr,"Failed to configure TX sync interface: %s\n", bladerf_strerror(status)); + brf_error(status); + } else + printf("[BRF] configured TX sync interface \n"); + + /* Configure the device's RX module for use with the sync interface. + * SC16 Q11 samples *with* metadata are used. */ + if ((status=bladerf_sync_config(brf->dev, BLADERF_MODULE_RX, BLADERF_FORMAT_SC16_Q11_META,brf->num_buffers,brf->buffer_size,brf->num_transfers,brf->rx_timeout_ms)) != 0 ) { + fprintf(stderr,"Failed to configure RX sync interface: %s\n", bladerf_strerror(status)); + brf_error(status); + } else + printf("[BRF] configured Rx sync interface \n"); + + + /* We must always enable the TX module after calling bladerf_sync_config(), and + * before attempting to TX samples via bladerf_sync_tx(). */ + if ((status=bladerf_enable_module(brf->dev, BLADERF_MODULE_TX, true)) != 0) { + fprintf(stderr,"Failed to enable TX module: %s\n", bladerf_strerror(status)); + brf_error(status); + } else + printf("[BRF] TX module enabled \n"); + + /* We must always enable the RX module after calling bladerf_sync_config(), and + * before attempting to RX samples via bladerf_sync_rx(). */ + if ((status=bladerf_enable_module(brf->dev, BLADERF_MODULE_RX, true)) != 0) { + fprintf(stderr,"Failed to enable RX module: %s\n", bladerf_strerror(status)); + brf_error(status); + } else + printf("[BRF] RX module enabled \n"); + + // calibrate + + if ((status=bladerf_calibrate_dc(brf->dev, BLADERF_DC_CAL_LPF_TUNING)) != 0 || + (status=bladerf_calibrate_dc(brf->dev, BLADERF_DC_CAL_TX_LPF)) != 0 || + (status=bladerf_calibrate_dc(brf->dev, BLADERF_DC_CAL_RX_LPF)) != 0 || + (status=bladerf_calibrate_dc(brf->dev, BLADERF_DC_CAL_RXVGA2)) != 0) { + fprintf(stderr, "[BRF] error calibrating\n"); + brf_error(status); + } else + printf("[BRF] calibration OK\n"); + + bladerf_log_set_verbosity(get_brf_log_level(openair0_cfg->log_level)); + + printf("BLADERF: Initializing openair0_device\n"); + device->Mod_id = num_devices++; + device->type = BLADERF_DEV; + device->trx_start_func = trx_brf_start; + device->trx_end_func = trx_brf_end; + device->trx_read_func = trx_brf_read; + device->trx_write_func = trx_brf_write; + device->trx_get_stats_func = trx_brf_get_stats; + device->trx_reset_stats_func = trx_brf_reset_stats; + device->trx_stop_func = trx_brf_stop; + device->trx_set_freq_func = trx_brf_set_freq; + device->trx_set_gains_func = trx_brf_set_gains; + device->openair0_cfg = openair0_cfg; + device->priv = (void *)brf; + + calibrate_rf(device); + + // memcpy((void*)&device->openair0_cfg,(void*)&openair0_cfg[0],sizeof(openair0_config_t)); + + if ((status=bladerf_enable_module(brf->dev, BLADERF_MODULE_TX, false)) != 0) { + fprintf(stderr,"Failed to enable TX module: %s\n", bladerf_strerror(status)); + abort(); + } + if ((status=bladerf_enable_module(brf->dev, BLADERF_MODULE_RX, false)) != 0) { + fprintf(stderr,"Failed to enable RX module: %s\n", bladerf_strerror(status)); + abort(); + } + + return 0; } -/*! \brief bladeRF error report - * \param status +/*! \brief bladeRF error report + * \param status * \returns 0 on success */ int brf_error(int status) { - fprintf(stderr, "[BRF] brf_error: %s\n", bladerf_strerror(status)); - exit(-1); - return status; // or status error code + fprintf(stderr, "[BRF] brf_error: %s\n", bladerf_strerror(status)); + exit(-1); + return status; // or status error code } @@ -1153,61 +1154,61 @@ int brf_error(int status) { */ struct bladerf * open_bladerf_from_serial(const char *serial) { - int status; - struct bladerf *dev; - struct bladerf_devinfo info; - /* Initialize all fields to "don't care" wildcard values. - * - * Immediately passing this to bladerf_open_with_devinfo() would cause - * libbladeRF to open any device on any available backend. */ - bladerf_init_devinfo(&info); - /* Specify the desired device's serial number, while leaving all other - * fields in the info structure wildcard values */ - strncpy(info.serial, serial, BLADERF_SERIAL_LENGTH - 1); - info.serial[BLADERF_SERIAL_LENGTH - 1] = '\0'; - status = bladerf_open_with_devinfo(&dev, &info); - - if (status == BLADERF_ERR_NODEV) { - printf("No devices available with serial=%s\n", serial); - return NULL; - } else if (status != 0) { - fprintf(stderr, "Failed to open device with serial=%s (%s)\n", serial, bladerf_strerror(status)); - return NULL; - } else { - return dev; - } + int status; + struct bladerf *dev; + struct bladerf_devinfo info; + /* Initialize all fields to "don't care" wildcard values. + * + * Immediately passing this to bladerf_open_with_devinfo() would cause + * libbladeRF to open any device on any available backend. */ + bladerf_init_devinfo(&info); + /* Specify the desired device's serial number, while leaving all other + * fields in the info structure wildcard values */ + strncpy(info.serial, serial, BLADERF_SERIAL_LENGTH - 1); + info.serial[BLADERF_SERIAL_LENGTH - 1] = '\0'; + status = bladerf_open_with_devinfo(&dev, &info); + + if (status == BLADERF_ERR_NODEV) { + printf("No devices available with serial=%s\n", serial); + return NULL; + } else if (status != 0) { + fprintf(stderr, "Failed to open device with serial=%s (%s)\n", serial, bladerf_strerror(status)); + return NULL; + } else { + return dev; + } } /*! \brief Get BladeRF log level * \param log_level log level * \returns log level of BLADERF device */ -int get_brf_log_level(int log_level){ - - int level=BLADERF_LOG_LEVEL_INFO; - return BLADERF_LOG_LEVEL_INFO; - switch(log_level) { - case LOG_DEBUG: - level=BLADERF_LOG_LEVEL_DEBUG; - break; - case LOG_INFO: - level= BLADERF_LOG_LEVEL_INFO; - break; - case LOG_WARNING: - level=BLADERF_LOG_LEVEL_WARNING; - break; - case LOG_ERR: - level=BLADERF_LOG_LEVEL_ERROR; - break; - case LOG_CRIT: - level=BLADERF_LOG_LEVEL_CRITICAL; - break; - case LOG_EMERG: - level = BLADERF_LOG_LEVEL_SILENT; - break; - default: - break; - } - return level; +int get_brf_log_level(int log_level) { + + int level=BLADERF_LOG_LEVEL_INFO; + return BLADERF_LOG_LEVEL_INFO; + switch(log_level) { + case LOG_DEBUG: + level=BLADERF_LOG_LEVEL_DEBUG; + break; + case LOG_INFO: + level= BLADERF_LOG_LEVEL_INFO; + break; + case LOG_WARNING: + level=BLADERF_LOG_LEVEL_WARNING; + break; + case LOG_ERR: + level=BLADERF_LOG_LEVEL_ERROR; + break; + case LOG_CRIT: + level=BLADERF_LOG_LEVEL_CRITICAL; + break; + case LOG_EMERG: + level = BLADERF_LOG_LEVEL_SILENT; + break; + default: + break; + } + return level; } /*@}*/ diff --git a/targets/ARCH/ETHERNET/USERSPACE/LIB/ethernet_lib.c b/targets/ARCH/ETHERNET/USERSPACE/LIB/ethernet_lib.c index 108c4ca069e07ee71c7b3625cb5b5b8f5c9740ad..392cad2ee7af364e0a4189d8c473c75d814fac37 100644 --- a/targets/ARCH/ETHERNET/USERSPACE/LIB/ethernet_lib.c +++ b/targets/ARCH/ETHERNET/USERSPACE/LIB/ethernet_lib.c @@ -19,7 +19,7 @@ * contact@openairinterface.org */ -/*! \file ethernet_lib.c +/*! \file ethernet_lib.c * \brief API to stream I/Q samples over standard ethernet * \author add alcatel Katerina Trilyraki, Navid Nikaein, Pedro Dinis, Lucio Ferreira, Raymond Knopp * \date 2015 @@ -55,113 +55,113 @@ int dest_addr_len[MAX_INST]; int trx_eth_start(openair0_device *device) { - eth_state_t *eth = (eth_state_t*)device->priv; - - /* initialize socket */ - if (eth->flags == ETH_RAW_MODE) { - printf("Setting ETHERNET to ETH_RAW_IF5_MODE\n"); - if (eth_socket_init_raw(device)!=0) return -1; - /* RRU gets device configuration - RAU sets device configuration*/ + eth_state_t *eth = (eth_state_t*)device->priv; - printf("Setting Timenout to 999999 usecs\n"); - if(ethernet_tune (device,RCV_TIMEOUT,999999)!=0) return -1; + /* initialize socket */ + if (eth->flags == ETH_RAW_MODE) { + printf("Setting ETHERNET to ETH_RAW_IF5_MODE\n"); + if (eth_socket_init_raw(device)!=0) return -1; + /* RRU gets device configuration - RAU sets device configuration*/ - /* - if (device->host_type == RAU_HOST) { - if(eth_set_dev_conf_raw(device)!=0) return -1; - } else { - if(eth_get_dev_conf_raw(device)!=0) return -1; - }*/ + printf("Setting Timenout to 999999 usecs\n"); + if(ethernet_tune (device,RCV_TIMEOUT,999999)!=0) return -1; - /* adjust MTU wrt number of samples per packet */ - if(eth->compression == ALAW_COMPRESS) { - if(ethernet_tune (device,MTU_SIZE,RAW_PACKET_SIZE_BYTES_ALAW(device->openair0_cfg->samples_per_packet))!=0) return -1; - } else { - if(ethernet_tune (device,MTU_SIZE,RAW_PACKET_SIZE_BYTES(device->openair0_cfg->samples_per_packet))!=0) return -1; - } - if(ethernet_tune (device,RCV_TIMEOUT,999999)!=0) return -1; - } else if (eth->flags == ETH_RAW_IF4p5_MODE) { + /* + if (device->host_type == RAU_HOST) { + if(eth_set_dev_conf_raw(device)!=0) return -1; + } else { + if(eth_get_dev_conf_raw(device)!=0) return -1; + }*/ - printf("Setting ETHERNET to ETH_RAW_IF4p5_MODE\n"); - if (eth_socket_init_raw(device)!=0) return -1; + /* adjust MTU wrt number of samples per packet */ + if(eth->compression == ALAW_COMPRESS) { + if(ethernet_tune (device,MTU_SIZE,RAW_PACKET_SIZE_BYTES_ALAW(device->openair0_cfg->samples_per_packet))!=0) return -1; + } else { + if(ethernet_tune (device,MTU_SIZE,RAW_PACKET_SIZE_BYTES(device->openair0_cfg->samples_per_packet))!=0) return -1; + } + if(ethernet_tune (device,RCV_TIMEOUT,999999)!=0) return -1; + } else if (eth->flags == ETH_RAW_IF4p5_MODE) { - printf("Setting Timenout to 999999 usecs\n"); - if(ethernet_tune (device,RCV_TIMEOUT,999999)!=0) return -1; + printf("Setting ETHERNET to ETH_RAW_IF4p5_MODE\n"); + if (eth_socket_init_raw(device)!=0) return -1; - /* - if (device->host_type == RAU_HOST) { - if(eth_set_dev_conf_raw_IF4p5(device)!=0) return -1; - } else { - if(eth_get_dev_conf_raw_IF4p5(device)!=0) return -1; - } - */ + printf("Setting Timenout to 999999 usecs\n"); + if(ethernet_tune (device,RCV_TIMEOUT,999999)!=0) return -1; - /* adjust MTU wrt number of samples per packet */ - if(ethernet_tune (device,MTU_SIZE,RAW_IF4p5_PRACH_SIZE_BYTES)!=0) return -1; + /* + if (device->host_type == RAU_HOST) { + if(eth_set_dev_conf_raw_IF4p5(device)!=0) return -1; + } else { + if(eth_get_dev_conf_raw_IF4p5(device)!=0) return -1; + } + */ - if(ethernet_tune (device,RCV_TIMEOUT,999999)!=0) return -1; - } else if (eth->flags == ETH_UDP_IF4p5_MODE) { - printf("Setting ETHERNET to UDP_IF4p5_MODE\n"); - if (eth_socket_init_udp(device)!=0) return -1; + /* adjust MTU wrt number of samples per packet */ + if(ethernet_tune (device,MTU_SIZE,RAW_IF4p5_PRACH_SIZE_BYTES)!=0) return -1; - printf("Setting Timeout to 999999 usecs\n"); - if(ethernet_tune (device,RCV_TIMEOUT,999999)!=0) return -1; + if(ethernet_tune (device,RCV_TIMEOUT,999999)!=0) return -1; + } else if (eth->flags == ETH_UDP_IF4p5_MODE) { + printf("Setting ETHERNET to UDP_IF4p5_MODE\n"); + if (eth_socket_init_udp(device)!=0) return -1; - /* - if (device->host_type == RAU_HOST) { - if(eth_set_dev_conf_udp(device)!=0) return -1; - } else { - if(eth_get_dev_conf_udp(device)!=0) return -1; - } - */ + printf("Setting Timeout to 999999 usecs\n"); + if(ethernet_tune (device,RCV_TIMEOUT,999999)!=0) return -1; - /* adjust MTU wrt number of samples per packet */ - if(ethernet_tune (device,MTU_SIZE,UDP_IF4p5_PRACH_SIZE_BYTES)!=0) return -1; - + /* + if (device->host_type == RAU_HOST) { + if(eth_set_dev_conf_udp(device)!=0) return -1; + } else { + if(eth_get_dev_conf_udp(device)!=0) return -1; + } + */ + /* adjust MTU wrt number of samples per packet */ + if(ethernet_tune (device,MTU_SIZE,UDP_IF4p5_PRACH_SIZE_BYTES)!=0) return -1; - - } else if (eth->flags == ETH_RAW_IF5_MOBIPASS) { - printf("Setting ETHERNET to RAW_IF5_MODE\n"); - if (eth_socket_init_raw(device)!=0) return -1; - if(ethernet_tune (device,RCV_TIMEOUT,999999)!=0) return -1; - } else { - printf("Setting ETHERNET to UDP_IF5_MODE\n"); - if (eth_socket_init_udp(device)!=0) return -1; - /* - if (device->host_type == RAU_HOST) { - if(eth_set_dev_conf_udp(device)!=0) return -1; + + } else if (eth->flags == ETH_RAW_IF5_MOBIPASS) { + printf("Setting ETHERNET to RAW_IF5_MODE\n"); + if (eth_socket_init_raw(device)!=0) return -1; + if(ethernet_tune (device,RCV_TIMEOUT,999999)!=0) return -1; + } else { - if(eth_get_dev_conf_udp(device)!=0) return -1; - }*/ + printf("Setting ETHERNET to UDP_IF5_MODE\n"); + if (eth_socket_init_udp(device)!=0) return -1; + + /* + if (device->host_type == RAU_HOST) { + if(eth_set_dev_conf_udp(device)!=0) return -1; + } else { + if(eth_get_dev_conf_udp(device)!=0) return -1; + }*/ + + /* adjust MTU wrt number of samples per packet */ + if(ethernet_tune (device,MTU_SIZE,UDP_IF4p5_PRACH_SIZE_BYTES)!=0) return -1; + + if(ethernet_tune (device,RCV_TIMEOUT,999999)!=0) return -1; + } + /* apply additional configuration */ + if(ethernet_tune (device, SND_BUF_SIZE,2000000000)!=0) return -1; + if(ethernet_tune (device, RCV_BUF_SIZE,2000000000)!=0) return -1; + if(ethernet_tune (device, KERNEL_SND_BUF_MAX_SIZE, 200000000)!=0) return -1; + if(ethernet_tune (device, KERNEL_RCV_BUF_MAX_SIZE, 200000000)!=0) return -1; - /* adjust MTU wrt number of samples per packet */ - if(ethernet_tune (device,MTU_SIZE,UDP_IF4p5_PRACH_SIZE_BYTES)!=0) return -1; - - if(ethernet_tune (device,RCV_TIMEOUT,999999)!=0) return -1; - } - /* apply additional configuration */ - if(ethernet_tune (device, SND_BUF_SIZE,2000000000)!=0) return -1; - if(ethernet_tune (device, RCV_BUF_SIZE,2000000000)!=0) return -1; - if(ethernet_tune (device, KERNEL_SND_BUF_MAX_SIZE, 200000000)!=0) return -1; - if(ethernet_tune (device, KERNEL_RCV_BUF_MAX_SIZE, 200000000)!=0) return -1; - - return 0; + return 0; } void trx_eth_end(openair0_device *device) { - eth_state_t *eth = (eth_state_t*)device->priv; - /* destroys socket only for the processes that call the eth_end fuction-- shutdown() for beaking the pipe */ - if ( close(eth->sockfdd) <0 ) { - perror("ETHERNET: Failed to close socket"); - exit(0); - } else { - printf("[%s] socket has been successfully closed.\n",(device->host_type == RAU_HOST)? "RAU":"RRU"); - } + eth_state_t *eth = (eth_state_t*)device->priv; + /* destroys socket only for the processes that call the eth_end fuction-- shutdown() for beaking the pipe */ + if ( close(eth->sockfdd) <0 ) { + perror("ETHERNET: Failed to close socket"); + exit(0); + } else { + printf("[%s] socket has been successfully closed.\n",(device->host_type == RAU_HOST)? "RAU":"RRU"); + } } @@ -187,282 +187,282 @@ int trx_eth_reset_stats(openair0_device* device) { int ethernet_tune(openair0_device *device, unsigned int option, int value) { - - eth_state_t *eth = (eth_state_t*)device->priv; - struct timeval timeout; - struct ifreq ifr; - char system_cmd[256]; - int rname[] = { CTL_NET, NET_CORE, NET_CORE_RMEM_MAX }; - int wname[] = { CTL_NET, NET_CORE, NET_CORE_WMEM_MAX }; - int namelen=3; - int newval[1]; - int newlen=sizeof(newval); - int ret=0; - // int i=0; - - /****************** socket level options ************************/ - switch(option) { - case SND_BUF_SIZE: /* transmit socket buffer size */ - if (setsockopt(eth->sockfdd, - SOL_SOCKET, - SO_SNDBUF, - &value,sizeof(value))) { - perror("[ETHERNET] setsockopt()"); - } else { - printf("send buffer size= %d bytes\n",value); - } - break; - - case RCV_BUF_SIZE: /* receive socket buffer size */ - if (setsockopt(eth->sockfdd, - SOL_SOCKET, - SO_RCVBUF, - &value,sizeof(value))) { - perror("[ETHERNET] setsockopt()"); - } else { - printf("receive bufffer size= %d bytes\n",value); - } - break; - - case RCV_TIMEOUT: - timeout.tv_sec = value/1000000; - timeout.tv_usec = value%1000000;//less than rt_period? - if (setsockopt(eth->sockfdc, - SOL_SOCKET, - SO_RCVTIMEO, - (char *)&timeout,sizeof(timeout))) { - perror("[ETHERNET] setsockopt()"); - } else { - printf( "receive timeout= %u usec\n",(unsigned int)timeout.tv_usec); - } - if (setsockopt(eth->sockfdd, - SOL_SOCKET, - SO_RCVTIMEO, - (char *)&timeout,sizeof(timeout))) { - perror("[ETHERNET] setsockopt()"); - } else { - printf( "receive timeout= %u usec\n",(unsigned int)timeout.tv_usec); - } - break; - - case SND_TIMEOUT: - timeout.tv_sec = value/1000000000; - timeout.tv_usec = value%1000000000;//less than rt_period? - if (setsockopt(eth->sockfdc, - SOL_SOCKET, - SO_SNDTIMEO, - (char *)&timeout,sizeof(timeout))) { - perror("[ETHERNET] setsockopt()"); - } else { - printf( "send timeout= %d,%d sec\n",(int)timeout.tv_sec,(int)timeout.tv_usec); - } - if (setsockopt(eth->sockfdd, - SOL_SOCKET, - SO_SNDTIMEO, - (char *)&timeout,sizeof(timeout))) { - perror("[ETHERNET] setsockopt()"); - } else { - printf( "send timeout= %d,%d sec\n",(int)timeout.tv_sec,(int)timeout.tv_usec); - } - break; - - + + eth_state_t *eth = (eth_state_t*)device->priv; + struct timeval timeout; + struct ifreq ifr; + char system_cmd[256]; + int rname[] = { CTL_NET, NET_CORE, NET_CORE_RMEM_MAX }; + int wname[] = { CTL_NET, NET_CORE, NET_CORE_WMEM_MAX }; + int namelen=3; + int newval[1]; + int newlen=sizeof(newval); + int ret=0; + // int i=0; + + /****************** socket level options ************************/ + switch(option) { + case SND_BUF_SIZE: /* transmit socket buffer size */ + if (setsockopt(eth->sockfdd, + SOL_SOCKET, + SO_SNDBUF, + &value,sizeof(value))) { + perror("[ETHERNET] setsockopt()"); + } else { + printf("send buffer size= %d bytes\n",value); + } + break; + + case RCV_BUF_SIZE: /* receive socket buffer size */ + if (setsockopt(eth->sockfdd, + SOL_SOCKET, + SO_RCVBUF, + &value,sizeof(value))) { + perror("[ETHERNET] setsockopt()"); + } else { + printf("receive bufffer size= %d bytes\n",value); + } + break; + + case RCV_TIMEOUT: + timeout.tv_sec = value/1000000; + timeout.tv_usec = value%1000000;//less than rt_period? + if (setsockopt(eth->sockfdc, + SOL_SOCKET, + SO_RCVTIMEO, + (char *)&timeout,sizeof(timeout))) { + perror("[ETHERNET] setsockopt()"); + } else { + printf( "receive timeout= %u usec\n",(unsigned int)timeout.tv_usec); + } + if (setsockopt(eth->sockfdd, + SOL_SOCKET, + SO_RCVTIMEO, + (char *)&timeout,sizeof(timeout))) { + perror("[ETHERNET] setsockopt()"); + } else { + printf( "receive timeout= %u usec\n",(unsigned int)timeout.tv_usec); + } + break; + + case SND_TIMEOUT: + timeout.tv_sec = value/1000000000; + timeout.tv_usec = value%1000000000;//less than rt_period? + if (setsockopt(eth->sockfdc, + SOL_SOCKET, + SO_SNDTIMEO, + (char *)&timeout,sizeof(timeout))) { + perror("[ETHERNET] setsockopt()"); + } else { + printf( "send timeout= %d,%d sec\n",(int)timeout.tv_sec,(int)timeout.tv_usec); + } + if (setsockopt(eth->sockfdd, + SOL_SOCKET, + SO_SNDTIMEO, + (char *)&timeout,sizeof(timeout))) { + perror("[ETHERNET] setsockopt()"); + } else { + printf( "send timeout= %d,%d sec\n",(int)timeout.tv_sec,(int)timeout.tv_usec); + } + break; + + /******************* interface level options *************************/ - case MTU_SIZE: /* change MTU of the eth interface */ - ifr.ifr_addr.sa_family = AF_INET; - strncpy(ifr.ifr_name,eth->if_name, sizeof(ifr.ifr_name)); - ifr.ifr_mtu =value; - if (ioctl(eth->sockfdd,SIOCSIFMTU,(caddr_t)&ifr) < 0 ) - perror ("[ETHERNET] Can't set the MTU"); - else - printf("[ETHERNET] %s MTU size has changed to %d\n",eth->if_name,ifr.ifr_mtu); - break; - - case TX_Q_LEN: /* change TX queue length of eth interface */ - ifr.ifr_addr.sa_family = AF_INET; - strncpy(ifr.ifr_name,eth->if_name, sizeof(ifr.ifr_name)); - ifr.ifr_qlen =value; - if (ioctl(eth->sockfdd,SIOCSIFTXQLEN,(caddr_t)&ifr) < 0 ) - perror ("[ETHERNET] Can't set the txqueuelen"); - else - printf("[ETHERNET] %s txqueuelen size has changed to %d\n",eth->if_name,ifr.ifr_qlen); - break; - + case MTU_SIZE: /* change MTU of the eth interface */ + ifr.ifr_addr.sa_family = AF_INET; + strncpy(ifr.ifr_name,eth->if_name, sizeof(ifr.ifr_name)); + ifr.ifr_mtu =value; + if (ioctl(eth->sockfdd,SIOCSIFMTU,(caddr_t)&ifr) < 0 ) + perror ("[ETHERNET] Can't set the MTU"); + else + printf("[ETHERNET] %s MTU size has changed to %d\n",eth->if_name,ifr.ifr_mtu); + break; + + case TX_Q_LEN: /* change TX queue length of eth interface */ + ifr.ifr_addr.sa_family = AF_INET; + strncpy(ifr.ifr_name,eth->if_name, sizeof(ifr.ifr_name)); + ifr.ifr_qlen =value; + if (ioctl(eth->sockfdd,SIOCSIFTXQLEN,(caddr_t)&ifr) < 0 ) + perror ("[ETHERNET] Can't set the txqueuelen"); + else + printf("[ETHERNET] %s txqueuelen size has changed to %d\n",eth->if_name,ifr.ifr_qlen); + break; + /******************* device level options *************************/ - case COALESCE_PAR: - ret=snprintf(system_cmd,sizeof(system_cmd),"ethtool -C %s rx-usecs %d",eth->if_name,value); - if (ret > 0) { - ret=system(system_cmd); - if (ret == -1) { - fprintf (stderr,"[ETHERNET] Can't start shell to execute %s %s",system_cmd, strerror(errno)); - } else { - printf ("[ETHERNET] status of %s is %d\n", system_cmd, WEXITSTATUS(ret)); - } - printf("[ETHERNET] Coalesce parameters %s\n",system_cmd); - } else { - perror("[ETHERNET] Can't set coalesce parameters\n"); + case COALESCE_PAR: + ret=snprintf(system_cmd,sizeof(system_cmd),"ethtool -C %s rx-usecs %d",eth->if_name,value); + if (ret > 0) { + ret=system(system_cmd); + if (ret == -1) { + fprintf (stderr,"[ETHERNET] Can't start shell to execute %s %s",system_cmd, strerror(errno)); + } else { + printf ("[ETHERNET] status of %s is %d\n", system_cmd, WEXITSTATUS(ret)); + } + printf("[ETHERNET] Coalesce parameters %s\n",system_cmd); + } else { + perror("[ETHERNET] Can't set coalesce parameters\n"); + } + break; + + case PAUSE_PAR: + if (value==1) ret=snprintf(system_cmd,sizeof(system_cmd),"ethtool -A %s autoneg off rx off tx off",eth->if_name); + else if (value==0) ret=snprintf(system_cmd,sizeof(system_cmd),"ethtool -A %s autoneg on rx on tx on",eth->if_name); + else break; + if (ret > 0) { + ret=system(system_cmd); + if (ret == -1) { + fprintf (stderr,"[ETHERNET] Can't start shell to execute %s %s",system_cmd, strerror(errno)); + } else { + printf ("[ETHERNET] status of %s is %d\n", system_cmd, WEXITSTATUS(ret)); + } + printf("[ETHERNET] Pause parameters %s\n",system_cmd); + } else { + perror("[ETHERNET] Can't set pause parameters\n"); + } + break; + + case RING_PAR: + ret=snprintf(system_cmd,sizeof(system_cmd),"ethtool -G %s val %d",eth->if_name,value); + if (ret > 0) { + ret=system(system_cmd); + if (ret == -1) { + fprintf (stderr,"[ETHERNET] Can't start shell to execute %s %s",system_cmd, strerror(errno)); + } else { + printf ("[ETHERNET] status of %s is %d\n", system_cmd, WEXITSTATUS(ret)); + } + printf("[ETHERNET] Ring parameters %s\n",system_cmd); + } else { + perror("[ETHERNET] Can't set ring parameters\n"); + } + break; + case KERNEL_RCV_BUF_MAX_SIZE: + newval[0] = value; + ret=sysctl(rname, namelen, NULL, 0, newval, newlen); + if (ret) { + fprintf(stderr,"[ETHERNET] Error using sysctl():%s\n",strerror(errno)); + } else { + printf("[ETHERNET] Kernel network receive buffer max size is set to %u\n",(unsigned int)newval[0]); + } + break; + case KERNEL_SND_BUF_MAX_SIZE: + newval[0] = value; + ret=sysctl(wname, namelen, NULL, 0, newval, newlen); + if (ret) { + fprintf(stderr,"[ETHERNET] Error using sysctl():%s\n",strerror(errno)); + } else { + printf("[ETHERNET] Kernel network send buffer max size is set to %u\n",(unsigned int)newval[0]); + } + break; + + default: + break; } - break; - - case PAUSE_PAR: - if (value==1) ret=snprintf(system_cmd,sizeof(system_cmd),"ethtool -A %s autoneg off rx off tx off",eth->if_name); - else if (value==0) ret=snprintf(system_cmd,sizeof(system_cmd),"ethtool -A %s autoneg on rx on tx on",eth->if_name); - else break; - if (ret > 0) { - ret=system(system_cmd); - if (ret == -1) { - fprintf (stderr,"[ETHERNET] Can't start shell to execute %s %s",system_cmd, strerror(errno)); - } else { - printf ("[ETHERNET] status of %s is %d\n", system_cmd, WEXITSTATUS(ret)); - } - printf("[ETHERNET] Pause parameters %s\n",system_cmd); + + return 0; +} + + +int transport_init(openair0_device *device, openair0_config_t *openair0_cfg, eth_params_t * eth_params ) { + + eth_state_t *eth = (eth_state_t*)malloc(sizeof(eth_state_t)); + memset(eth, 0, sizeof(eth_state_t)); + + if (eth_params->transp_preference == 1) { + eth->flags = ETH_RAW_MODE; + } else if (eth_params->transp_preference == 0) { + eth->flags = ETH_UDP_MODE; + } else if (eth_params->transp_preference == 3) { + eth->flags = ETH_RAW_IF4p5_MODE; + } else if (eth_params->transp_preference == 2) { + eth->flags = ETH_UDP_IF4p5_MODE; + } else if (eth_params->transp_preference == 4) { + eth->flags = ETH_RAW_IF5_MOBIPASS; } else { - perror("[ETHERNET] Can't set pause parameters\n"); + printf("transport_init: Unknown transport preference %d - default to RAW", eth_params->transp_preference); + eth->flags = ETH_RAW_MODE; } - break; - - case RING_PAR: - ret=snprintf(system_cmd,sizeof(system_cmd),"ethtool -G %s val %d",eth->if_name,value); - if (ret > 0) { - ret=system(system_cmd); - if (ret == -1) { - fprintf (stderr,"[ETHERNET] Can't start shell to execute %s %s",system_cmd, strerror(errno)); - } else { - printf ("[ETHERNET] status of %s is %d\n", system_cmd, WEXITSTATUS(ret)); - } - printf("[ETHERNET] Ring parameters %s\n",system_cmd); + + if (eth_params->if_compress == 0) { + eth->compression = NO_COMPRESS; + } else if (eth_params->if_compress == 1) { + eth->compression = ALAW_COMPRESS; } else { - perror("[ETHERNET] Can't set ring parameters\n"); - } - break; - case KERNEL_RCV_BUF_MAX_SIZE: - newval[0] = value; - ret=sysctl(rname, namelen, NULL, 0, newval, newlen); - if (ret) { - fprintf(stderr,"[ETHERNET] Error using sysctl():%s\n",strerror(errno)); - } else{ - printf("[ETHERNET] Kernel network receive buffer max size is set to %u\n",newval[0]); + printf("transport_init: Unknown compression scheme %d - default to ALAW", eth_params->if_compress); + eth->compression = ALAW_COMPRESS; } - break; - case KERNEL_SND_BUF_MAX_SIZE: - newval[0] = value; - ret=sysctl(wname, namelen, NULL, 0, newval, newlen); - if (ret) { - fprintf(stderr,"[ETHERNET] Error using sysctl():%s\n",strerror(errno)); - } else{ - printf("[ETHERNET] Kernel network send buffer max size is set to %u\n",newval[0]); + + printf("[ETHERNET]: Initializing openair0_device for %s ...\n", ((device->host_type == RAU_HOST) ? "RAU": "RRU")); + device->Mod_id = 0;//num_devices_eth++; + device->transp_type = ETHERNET_TP; + device->trx_start_func = trx_eth_start; + device->trx_get_stats_func = trx_eth_get_stats; + device->trx_reset_stats_func = trx_eth_reset_stats; + device->trx_end_func = trx_eth_end; + device->trx_stop_func = trx_eth_stop; + device->trx_set_freq_func = trx_eth_set_freq; + device->trx_set_gains_func = trx_eth_set_gains; + + if (eth->flags == ETH_RAW_MODE) { + device->trx_write_func = trx_eth_write_raw; + device->trx_read_func = trx_eth_read_raw; + } else if (eth->flags == ETH_UDP_MODE) { + device->trx_write_func = trx_eth_write_udp; + device->trx_read_func = trx_eth_read_udp; + device->trx_ctlsend_func = trx_eth_ctlsend_udp; + device->trx_ctlrecv_func = trx_eth_ctlrecv_udp; + } else if (eth->flags == ETH_RAW_IF4p5_MODE) { + device->trx_write_func = trx_eth_write_raw_IF4p5; + device->trx_read_func = trx_eth_read_raw_IF4p5; + } else if (eth->flags == ETH_UDP_IF4p5_MODE) { + device->trx_write_func = trx_eth_write_udp_IF4p5; + device->trx_read_func = trx_eth_read_udp_IF4p5; + device->trx_ctlsend_func = trx_eth_ctlsend_udp; + device->trx_ctlrecv_func = trx_eth_ctlrecv_udp; + } else if (eth->flags == ETH_RAW_IF5_MOBIPASS) { + device->trx_write_func = trx_eth_write_raw_IF4p5; + device->trx_read_func = trx_eth_read_raw_IF5_mobipass; + } else { + //device->trx_write_func = trx_eth_write_udp_IF4p5; + //device->trx_read_func = trx_eth_read_udp_IF4p5; } - break; - - default: - break; - } - - return 0; -} + eth->if_name = eth_params->local_if_name; + device->priv = eth; -int transport_init(openair0_device *device, openair0_config_t *openair0_cfg, eth_params_t * eth_params ) { + /* device specific */ + // openair0_cfg[0].iq_rxrescale = 15;//rescale iqs + // openair0_cfg[0].iq_txshift = eth_params->iq_txshift;// shift + // openair0_cfg[0].tx_sample_advance = eth_params->tx_sample_advance; - eth_state_t *eth = (eth_state_t*)malloc(sizeof(eth_state_t)); - memset(eth, 0, sizeof(eth_state_t)); - - if (eth_params->transp_preference == 1) { - eth->flags = ETH_RAW_MODE; - } else if (eth_params->transp_preference == 0) { - eth->flags = ETH_UDP_MODE; - } else if (eth_params->transp_preference == 3) { - eth->flags = ETH_RAW_IF4p5_MODE; - } else if (eth_params->transp_preference == 2) { - eth->flags = ETH_UDP_IF4p5_MODE; - } else if (eth_params->transp_preference == 4) { - eth->flags = ETH_RAW_IF5_MOBIPASS; - } else { - printf("transport_init: Unknown transport preference %d - default to RAW", eth_params->transp_preference); - eth->flags = ETH_RAW_MODE; - } - - if (eth_params->if_compress == 0) { - eth->compression = NO_COMPRESS; - } else if (eth_params->if_compress == 1) { - eth->compression = ALAW_COMPRESS; - } else { - printf("transport_init: Unknown compression scheme %d - default to ALAW", eth_params->if_compress); - eth->compression = ALAW_COMPRESS; - } - - printf("[ETHERNET]: Initializing openair0_device for %s ...\n", ((device->host_type == RAU_HOST) ? "RAU": "RRU")); - device->Mod_id = 0;//num_devices_eth++; - device->transp_type = ETHERNET_TP; - device->trx_start_func = trx_eth_start; - device->trx_get_stats_func = trx_eth_get_stats; - device->trx_reset_stats_func = trx_eth_reset_stats; - device->trx_end_func = trx_eth_end; - device->trx_stop_func = trx_eth_stop; - device->trx_set_freq_func = trx_eth_set_freq; - device->trx_set_gains_func = trx_eth_set_gains; - - if (eth->flags == ETH_RAW_MODE) { - device->trx_write_func = trx_eth_write_raw; - device->trx_read_func = trx_eth_read_raw; - } else if (eth->flags == ETH_UDP_MODE) { - device->trx_write_func = trx_eth_write_udp; - device->trx_read_func = trx_eth_read_udp; - device->trx_ctlsend_func = trx_eth_ctlsend_udp; - device->trx_ctlrecv_func = trx_eth_ctlrecv_udp; - } else if (eth->flags == ETH_RAW_IF4p5_MODE) { - device->trx_write_func = trx_eth_write_raw_IF4p5; - device->trx_read_func = trx_eth_read_raw_IF4p5; - } else if (eth->flags == ETH_UDP_IF4p5_MODE) { - device->trx_write_func = trx_eth_write_udp_IF4p5; - device->trx_read_func = trx_eth_read_udp_IF4p5; - device->trx_ctlsend_func = trx_eth_ctlsend_udp; - device->trx_ctlrecv_func = trx_eth_ctlrecv_udp; - } else if (eth->flags == ETH_RAW_IF5_MOBIPASS) { - device->trx_write_func = trx_eth_write_raw_IF4p5; - device->trx_read_func = trx_eth_read_raw_IF5_mobipass; - } else { - //device->trx_write_func = trx_eth_write_udp_IF4p5; - //device->trx_read_func = trx_eth_read_udp_IF4p5; - } - - eth->if_name = eth_params->local_if_name; - device->priv = eth; - - /* device specific */ - // openair0_cfg[0].iq_rxrescale = 15;//rescale iqs - // openair0_cfg[0].iq_txshift = eth_params->iq_txshift;// shift - // openair0_cfg[0].tx_sample_advance = eth_params->tx_sample_advance; - - /* RRU does not have any information to make this configuration atm */ - /* - if (device->host_type == RAU_HOST) { - - switch ((int)openair0_cfg[0].sample_rate) { - case 30720000: - openair0_cfg[0].samples_per_packet = 3840; - break; - case 23040000: - openair0_cfg[0].samples_per_packet = 2880; - break; - case 15360000: - openair0_cfg[0].samples_per_packet = 1920; - break; - case 7680000: - openair0_cfg[0].samples_per_packet = 960; - break; - case 1920000: - openair0_cfg[0].samples_per_packet = 240; - break; - default: - printf("Error: unknown sampling rate %f\n",openair0_cfg[0].sample_rate); - exit(-1); - break; - } - }*/ + /* RRU does not have any information to make this configuration atm */ + /* + if (device->host_type == RAU_HOST) { + + switch ((int)openair0_cfg[0].sample_rate) { + case 30720000: + openair0_cfg[0].samples_per_packet = 3840; + break; + case 23040000: + openair0_cfg[0].samples_per_packet = 2880; + break; + case 15360000: + openair0_cfg[0].samples_per_packet = 1920; + break; + case 7680000: + openair0_cfg[0].samples_per_packet = 960; + break; + case 1920000: + openair0_cfg[0].samples_per_packet = 240; + break; + default: + printf("Error: unknown sampling rate %f\n",openair0_cfg[0].sample_rate); + exit(-1); + break; + } + }*/ - device->openair0_cfg=&openair0_cfg[0]; - return 0; + device->openair0_cfg=&openair0_cfg[0]; + return 0; }