* @brief Creates Common Packet Format structure out of data. * @param data Pointer to data which need to be structured. * @param data_length Length of data in pa_Data. * @param common_packet_format_data Pointer to structure of CPF data item. * * @return kEipStatusOk .. success * kEipStatusError .. error */
| 202 | * kEipStatusError .. error |
| 203 | */ |
| 204 | EipStatus CreateCommonPacketFormatStructure( |
| 205 | const EipUint8 *data, |
| 206 | size_t data_length, |
| 207 | CipCommonPacketFormatData *common_packet_format_data) { |
| 208 | |
| 209 | common_packet_format_data->address_info_item[0].type_id = 0; |
| 210 | common_packet_format_data->address_info_item[1].type_id = 0; |
| 211 | |
| 212 | int length_count = 0; |
| 213 | CipUint item_count = GetIntFromMessage(&data); |
| 214 | OPENER_ASSERT(4U >= item_count) /* Sanitizing data - probably needs to be changed for productive code */ |
| 215 | common_packet_format_data->item_count = item_count; |
| 216 | length_count += 2; |
| 217 | if (common_packet_format_data->item_count >= 1U) { |
| 218 | common_packet_format_data->address_item.type_id = GetIntFromMessage(&data); |
| 219 | common_packet_format_data->address_item.length = GetIntFromMessage(&data); |
| 220 | length_count += 4; |
| 221 | if (common_packet_format_data->address_item.length >= 4) { |
| 222 | common_packet_format_data->address_item.data.connection_identifier = |
| 223 | GetDintFromMessage(&data); |
| 224 | length_count += 4; |
| 225 | } |
| 226 | if (common_packet_format_data->address_item.length == 8) { |
| 227 | common_packet_format_data->address_item.data.sequence_number = |
| 228 | GetDintFromMessage(&data); |
| 229 | length_count += 4; |
| 230 | } |
| 231 | } |
| 232 | if (common_packet_format_data->item_count >= 2) { |
| 233 | common_packet_format_data->data_item.type_id = GetIntFromMessage(&data); |
| 234 | common_packet_format_data->data_item.length = GetIntFromMessage(&data); |
| 235 | common_packet_format_data->data_item.data = (EipUint8 *)data; |
| 236 | data += common_packet_format_data->data_item.length; |
| 237 | length_count += (4 + common_packet_format_data->data_item.length); |
| 238 | |
| 239 | for (size_t j = 0; j < (common_packet_format_data->item_count - 2); j++) /* TODO there needs to be a limit check here???*/ |
| 240 | { |
| 241 | common_packet_format_data->address_info_item[j].type_id = |
| 242 | GetIntFromMessage( |
| 243 | &data); |
| 244 | OPENER_TRACE_INFO("Sockaddr type id: %x\n", |
| 245 | common_packet_format_data->address_info_item[j].type_id); |
| 246 | length_count += 2; |
| 247 | if ( (common_packet_format_data->address_info_item[j].type_id |
| 248 | == kCipItemIdSocketAddressInfoOriginatorToTarget) |
| 249 | || (common_packet_format_data->address_info_item[j].type_id |
| 250 | == kCipItemIdSocketAddressInfoTargetToOriginator) ) { |
| 251 | common_packet_format_data->address_info_item[j].length = |
| 252 | GetIntFromMessage(&data); |
| 253 | common_packet_format_data->address_info_item[j].sin_family = |
| 254 | GetIntFromMessage(&data); |
| 255 | common_packet_format_data->address_info_item[j].sin_port = |
| 256 | GetIntFromMessage(&data); |
| 257 | common_packet_format_data->address_info_item[j].sin_addr = |
| 258 | GetDintFromMessage(&data); |
| 259 | for (size_t i = 0; i < 8; i++) { |
| 260 | common_packet_format_data->address_info_item[j].nasin_zero[i] = *data; |
| 261 | data++; |
no test coverage detected