TODO this needs to check for buffer overflow*/
| 389 | |
| 390 | /* TODO this needs to check for buffer overflow*/ |
| 391 | EipStatus GetAttributeSingle(CipInstance *RESTRICT const instance, |
| 392 | CipMessageRouterRequest *const message_router_request, |
| 393 | CipMessageRouterResponse *const message_router_response, |
| 394 | struct sockaddr *originator_address, |
| 395 | const int encapsulation_session) { |
| 396 | /* Mask for filtering get-ability */ |
| 397 | |
| 398 | CipAttributeStruct *attribute = GetCipAttribute(instance, |
| 399 | message_router_request->request_path.attribute_number); |
| 400 | EipByte *message = message_router_response->data; |
| 401 | |
| 402 | message_router_response->data_length = 0; |
| 403 | message_router_response->reply_service = (0x80 |
| 404 | | message_router_request->service); |
| 405 | message_router_response->general_status = kCipErrorAttributeNotSupported; |
| 406 | message_router_response->size_of_additional_status = 0; |
| 407 | |
| 408 | EipUint16 attribute_number = |
| 409 | message_router_request->request_path.attribute_number; |
| 410 | |
| 411 | if ( (NULL != attribute) && (NULL != attribute->data) ) { |
| 412 | uint8_t get_bit_mask = 0; |
| 413 | if (kGetAttributeAll == message_router_request->service) { |
| 414 | get_bit_mask = |
| 415 | (instance->cip_class->get_all_bit_mask[CalculateIndex( |
| 416 | attribute_number)]); |
| 417 | message_router_response->general_status = kCipErrorSuccess; |
| 418 | } else { |
| 419 | get_bit_mask = |
| 420 | (instance->cip_class->get_single_bit_mask[CalculateIndex( |
| 421 | attribute_number)]); |
| 422 | } |
| 423 | if (0 != (get_bit_mask & (1 << (attribute_number % 8) ) ) ) { |
| 424 | OPENER_TRACE_INFO("getAttribute %d\n", |
| 425 | message_router_request->request_path.attribute_number); /* create a reply message containing the data*/ |
| 426 | |
| 427 | /*TODO think if it is better to put this code in an own |
| 428 | * getAssemblyAttributeSingle functions which will call get attribute |
| 429 | * single. |
| 430 | */ |
| 431 | |
| 432 | if (attribute->type == kCipByteArray |
| 433 | && instance->cip_class->class_id == kCipAssemblyClassCode) { |
| 434 | /* we are getting a byte array of a assembly object, kick out to the app callback */ |
| 435 | OPENER_TRACE_INFO(" -> getAttributeSingle CIP_BYTE_ARRAY\r\n"); |
| 436 | BeforeAssemblyDataSend(instance); |
| 437 | } |
| 438 | |
| 439 | OPENER_ASSERT(NULL != attribute) |
| 440 | message_router_response->data_length = EncodeData(attribute->type, |
| 441 | attribute->data, |
| 442 | &message); |
| 443 | message_router_response->general_status = kCipErrorSuccess; |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | return kEipStatusOkSend; |
| 448 | } |
no test coverage detected