//----------------------------------------------------------------------------- struct mac_data_req rlc_am_mac_data_request (void *rlcP) { //----------------------------------------------------------------------------- struct mac_data_req data_req; mem_block_t *pdu; signed int nb_pdu_to_transmit = ((struct rlc_am_entity *) rlcP)->nb_pdu_requested_by_mac_on_ch1 ; //rlc_am_get_pdus (rlcP, RLC_AM_TRAFFIC_ALLOWED_FOR_STATUS | RLC_AM_TRAFFIC_ALLOWED_FOR_DATA); rlc_am_get_pdus (rlcP, RLC_AM_TRAFFIC_ALLOWED_FOR_DATA); list_init (&data_req.data, NULL); //list_add_list (&((struct rlc_am_entity *) rlcP)->pdus_to_mac_layer_ch1, &data_req.data); while (nb_pdu_to_transmit > 0 ) { pdu = list_remove_head (&((struct rlc_am_entity *) rlcP)->pdus_to_mac_layer_ch1); if (pdu != null) { list_add_tail_eurecom (pdu, &data_req.data); } else { //msg ("[RLC_AM][RB %d] WARNING MAC_DATA_REQUEST CANNOT GIVE A PDU REQUESTED BY MAC\n", ((struct rlc_am_entity *) rlcP)->rb_id); } nb_pdu_to_transmit = nb_pdu_to_transmit - 1; } //list_add_list (&((struct rlc_am_entity *) rlcP)->pdus_to_mac_layer_ch2, &data_req.data); #ifdef DEBUG_RLC_AM_TX msg ("[RLC_AM][RB %d] MAC_DATA_REQUEST %d TBs (REQUESTED %d) Frame %d\n", ((struct rlc_am_entity *) rlcP)->rb_id, data_req.data.nb_elements, ((struct rlc_am_entity *) rlcP)->nb_pdu_requested_by_mac_on_ch1 , Mac_rlc_xface->frame); #endif data_req.buffer_occupancy_in_pdus = rlc_am_get_buffer_occupancy_in_pdus_ch1 ((struct rlc_am_entity *) rlcP); data_req.buffer_occupancy_in_pdus += rlc_am_get_buffer_occupancy_in_pdus_ch2 ((struct rlc_am_entity *) rlcP); data_req.buffer_occupancy_in_bytes = data_req.buffer_occupancy_in_pdus * ((struct rlc_am_entity *) rlcP)->pdu_size; data_req.rlc_info.rlc_protocol_state = ((struct rlc_am_entity *) rlcP)->protocol_state; return data_req; }
//----------------------------------------------------------------------------- struct mac_data_ind mac_rlc_deserialize_tb ( char *buffer_pP, const tb_size_t tb_sizeP, num_tb_t num_tbP, crc_t *crcs_pP) { //----------------------------------------------------------------------------- struct mac_data_ind data_ind; mem_block_t* tb_p; num_tb_t nb_tb_read; tbs_size_t tbs_size; nb_tb_read = 0; tbs_size = 0; list_init(&data_ind.data, NULL); while (num_tbP > 0) { tb_p = get_free_mem_block(sizeof (mac_rlc_max_rx_header_size_t) + tb_sizeP); if (tb_p != NULL) { ((struct mac_tb_ind *) (tb_p->data))->first_bit = 0; ((struct mac_tb_ind *) (tb_p->data))->data_ptr = (uint8_t*)&tb_p->data[sizeof (mac_rlc_max_rx_header_size_t)]; ((struct mac_tb_ind *) (tb_p->data))->size = tb_sizeP; if (crcs_pP) { ((struct mac_tb_ind *) (tb_p->data))->error_indication = crcs_pP[nb_tb_read]; } else { ((struct mac_tb_ind *) (tb_p->data))->error_indication = 0; } memcpy(((struct mac_tb_ind *) (tb_p->data))->data_ptr, &buffer_pP[tbs_size], tb_sizeP); #ifdef DEBUG_MAC_INTERFACE #if defined(TRACE_RLC_PAYLOAD) LOG_T(RLC, "[MAC-RLC] DUMP RX PDU(%d bytes):\n", tb_sizeP); rlc_util_print_hex_octets(RLC, ((struct mac_tb_ind *) (tb_p->data))->data_ptr, tb_sizeP); #endif #endif nb_tb_read = nb_tb_read + 1; tbs_size = tbs_size + tb_sizeP; list_add_tail_eurecom(tb_p, &data_ind.data); } num_tbP = num_tbP - 1; } data_ind.no_tb = nb_tb_read; data_ind.tb_size = tb_sizeP << 3; return data_ind; }
BOOL test_pdcp_data_req(void) { unsigned char* pdcp_test_pdu_buffer = NULL; unsigned char pdcp_test_pdu_buffer_size = DUMMY_BUFFER_SIZE + PDCP_USER_PLANE_DATA_PDU_LONG_SN_HEADER_SIZE; unsigned int index = 0; /* * Create an unsigned char buffer out of mem_block_t */ pdcp_test_pdu_buffer = (unsigned char*) calloc(1, pdcp_test_pdu_buffer_size); if (pdcp_test_pdu_buffer == NULL) { msg("Cannot allocate a buffer for test!\n"); return FALSE; } /* * Ask PDCP to handle a number of data requests */ for (index = 0; index < NUMBER_OF_TEST_PACKETS; ++index) { msg("\n\nAsking PDCP to send %d/%d SDU...\n", index+1, NUMBER_OF_TEST_PACKETS); /* * Reset test pdu buffer for every run */ memset(pdcp_test_pdu_buffer, 0x00, pdcp_test_pdu_buffer_size); /* * Ask PDCP to create a PDU with given buffer and enqueue it to `test_pdu_tx_list` */ if (pdcp_data_req(0, 0, 10, DUMMY_BUFFER, &pdcp_array[0], &test_pdu_tx_list) == TRUE) { msg("[TEST] Starting to dissect PDU created by PDCP...\n"); /* * XXX mem_block_t doesn't hold buffer size, how do we keep the size * information if we pass mem_block_ts via a linked list? */ #if 0 if (pdcp_test_pdu_buffer_size == 0 || pdcp_test_pdu_buffer == NULL) { msg("[TEST] PDU created by pdcp_data_req() is invalid!\n"); return FALSE; } #endif /* * Serialize incoming mem_block_t into an unsigned character array * and add removed PDU to RX list in order to use it in the next test * (test_pdcp_data_ind()) */ mem_block_t* pdcp_test_pdu = list_remove_head(&test_pdu_tx_list); memcpy(pdcp_test_pdu_buffer, pdcp_test_pdu->data, pdcp_test_pdu_buffer_size); list_add_tail_eurecom(pdcp_test_pdu, &test_pdu_rx_list); /* * Verify that this is a data packet by checking * if the first bit is 0x00 (PDCP_DATA_PDU) */ if (pdcp_test_pdu_buffer[0] & 0x80) { msg("[TEST] First bit is not 0, which means this is not a Data PDU!\n"); return FALSE; } else { msg("[TEST] First bit is 0 so this is a Data PDU, OK\n"); } /* * Verify that all three reserved bits are 0 */ if ((pdcp_test_pdu_buffer[0] & 0x70) != 0) { msg("[TEST] Reserved bits are not 0!\n"); return FALSE; } else { msg("[TEST] Reserved bits are all 0, OK\n"); } /* * Parse and verify sequence number */ u16 sequence_number = pdcp_get_sequence_number_of_pdu_with_long_sn(pdcp_test_pdu_buffer); msg("[TEST] Parsed sequence number is %04d\n", sequence_number); if (sequence_number != index % WINDOW_SIZE) { msg("[TEST] Sequence numbers are out-of-order!\n"); return FALSE; } else { msg("[TEST] Sequence number is correct\n"); } } else { msg("[TEST] pdcp_data_req() returned FALSE!\n"); return FALSE; } } return TRUE; }
BOOL pdcp_data_req(module_id_t module_id, u32_t frame, u8_t eNB_flag, rb_id_t rab_id, sdu_size_t sdu_buffer_size, \ unsigned char* sdu_buffer) #endif { //----------------------------------------------------------------------------- #ifdef PDCP_UNIT_TEST pdcp_t* pdcp = test_pdcp_entity; #else pdcp_t* pdcp = &pdcp_array[module_id][rab_id]; #endif mem_block_t* pdcp_pdu = NULL; u16 pdcp_pdu_size = sdu_buffer_size + PDCP_USER_PLANE_DATA_PDU_LONG_SN_HEADER_SIZE; LOG_I(PDCP, "Data request notification for PDCP entity with module ID %d and radio bearer ID %d pdu size %d\n", module_id, rab_id,pdcp_pdu_size); if (sdu_buffer_size == 0) { LOG_W(PDCP, "Handed SDU is of size 0! Ignoring...\n"); return FALSE; } /* * XXX MAX_IP_PACKET_SIZE is 4096, shouldn't this be MAX SDU size, which is 8188 bytes? */ if (sdu_buffer_size > MAX_IP_PACKET_SIZE) { LOG_W(PDCP, "Requested SDU size (%d) is bigger than that can be handled by PDCP!\n", sdu_buffer_size); // XXX What does following call do? mac_xface->macphy_exit(""); } /* * Allocate a new block for the new PDU (i.e. PDU header and SDU payload) */ LOG_D(PDCP, "Asking for a new mem_block of size %d\n", pdcp_pdu_size); pdcp_pdu = get_free_mem_block(pdcp_pdu_size); if (pdcp_pdu != NULL) { /* * Create a Data PDU with header and append data * * Place User Plane PDCP Data PDU header first */ pdcp_user_plane_data_pdu_header_with_long_sn pdu_header; pdu_header.dc = PDCP_DATA_PDU; pdu_header.sn = pdcp_get_next_tx_seq_number(pdcp); /* * Validate incoming sequence number, there might be a problem with PDCP initialization */ if (pdu_header.sn > pdcp_calculate_max_seq_num_for_given_size(pdcp->seq_num_size)) { LOG_E(PDCP, "Generated sequence number (%lu) is greater than a sequence number could ever be!\n", pdu_header.sn); LOG_E(PDCP, "There must be a problem with PDCP initialization, ignoring this PDU...\n"); free_mem_block(pdcp_pdu); return FALSE; } LOG_I(PDCP, "Sequence number %d is assigned to current PDU\n", pdu_header.sn); /* * Fill PDU buffer with the struct's fields */ if (pdcp_serialize_user_plane_data_pdu_with_long_sn_buffer((unsigned char*)pdcp_pdu->data, &pdu_header) == FALSE) { LOG_W(PDCP, "Cannot fill PDU buffer with relevant header fields!\n"); return FALSE; } /* Then append data... */ memcpy(&pdcp_pdu->data[PDCP_USER_PLANE_DATA_PDU_LONG_SN_HEADER_SIZE], sdu_buffer, sdu_buffer_size); /* Print octets of outgoing data in hexadecimal form */ LOG_D(PDCP, "Following content will be sent over RLC (PDCP PDU header is the first two bytes)\n"); util_print_hex_octets(PDCP, (unsigned char*)pdcp_pdu->data, pdcp_pdu_size); #ifdef PDCP_UNIT_TEST /* * Here we add PDU to the list and return to test code without * handing it off to RLC */ list_add_tail_eurecom(pdcp_pdu, test_list); return TRUE; #else /* * Ask sublayer to transmit data and check return value * to see if RLC succeeded */ rlc_op_status_t rlc_status = rlc_data_req(module_id, frame, eNB_flag, rab_id, RLC_MUI_UNDEFINED, RLC_SDU_CONFIRM_NO, pdcp_pdu_size, pdcp_pdu); switch (rlc_status) { case RLC_OP_STATUS_OK: LOG_I(PDCP, "Data sending request over RLC succeeded!\n"); break; case RLC_OP_STATUS_BAD_PARAMETER: LOG_W(PDCP, "Data sending request over RLC failed with 'Bad Parameter' reason!\n"); return FALSE; case RLC_OP_STATUS_INTERNAL_ERROR: LOG_W(PDCP, "Data sending request over RLC failed with 'Internal Error' reason!\n"); return FALSE; case RLC_OP_STATUS_OUT_OF_RESSOURCES: LOG_W(PDCP, "Data sending request over RLC failed with 'Out of Resources' reason!\n"); return FALSE; default: LOG_W(PDCP, "RLC returned an unknown status code after PDCP placed the order to send some data (Status Code:%d)\n", rlc_status); return FALSE; } /* * Control arrives here only if rlc_data_req() returns RLC_OP_STATUS_OK * so we return TRUE afterwards */ if (eNB_flag == 1) { Pdcp_stats_tx[module_id][(rab_id & RAB_OFFSET2 )>> RAB_SHIFT2][(rab_id & RAB_OFFSET)-DTCH]++; Pdcp_stats_tx_bytes[module_id][(rab_id & RAB_OFFSET2 )>> RAB_SHIFT2][(rab_id & RAB_OFFSET)-DTCH] += sdu_buffer_size; } else {