Fixed some bugs that would lead to segfaults and modified to support changes in protocol
This commit is contained in:
@@ -64,7 +64,7 @@ int enb_agent_deserialize_message(void *data, int size, Protocol__ProgranMessage
|
|||||||
*msg = protocol__progran_message__unpack(NULL, size, data);
|
*msg = protocol__progran_message__unpack(NULL, size, data);
|
||||||
if (*msg == NULL)
|
if (*msg == NULL)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
@@ -118,6 +118,7 @@ int enb_agent_hello(uint32_t xid, Protocol__ProgranMessage **msg) {
|
|||||||
protocol__progran_message__init(*msg);
|
protocol__progran_message__init(*msg);
|
||||||
(*msg)->msg_case = PROTOCOL__PROGRAN_MESSAGE__MSG_HELLO_MSG;
|
(*msg)->msg_case = PROTOCOL__PROGRAN_MESSAGE__MSG_HELLO_MSG;
|
||||||
(*msg)->msg_dir = PROTOCOL__PROGRAN_DIRECTION__INITIATING_MESSAGE;
|
(*msg)->msg_dir = PROTOCOL__PROGRAN_DIRECTION__INITIATING_MESSAGE;
|
||||||
|
(*msg)->has_msg_dir = 1;
|
||||||
(*msg)->hello_msg = hello_msg;
|
(*msg)->hello_msg = hello_msg;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@@ -216,6 +217,7 @@ int enb_agent_echo_reply(uint32_t xid, Protocol__ProgranMessage **msg) {
|
|||||||
protocol__progran_message__init(*msg);
|
protocol__progran_message__init(*msg);
|
||||||
(*msg)->msg_case = PROTOCOL__PROGRAN_MESSAGE__MSG_ECHO_REPLY_MSG;
|
(*msg)->msg_case = PROTOCOL__PROGRAN_MESSAGE__MSG_ECHO_REPLY_MSG;
|
||||||
(*msg)->msg_dir = PROTOCOL__PROGRAN_DIRECTION__SUCCESSFUL_OUTCOME;
|
(*msg)->msg_dir = PROTOCOL__PROGRAN_DIRECTION__SUCCESSFUL_OUTCOME;
|
||||||
|
(*msg)->has_msg_dir = 1;
|
||||||
(*msg)->echo_reply_msg = echo_reply_msg;
|
(*msg)->echo_reply_msg = echo_reply_msg;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
|||||||
@@ -42,10 +42,11 @@
|
|||||||
#include "assertions.h"
|
#include "assertions.h"
|
||||||
|
|
||||||
enb_agent_message_decoded_callback messages_callback[][3] = {
|
enb_agent_message_decoded_callback messages_callback[][3] = {
|
||||||
{enb_agent_hello, enb_agent_hello,0}, /*PROTOCOL__PROGRAN_MESSAGE__MSG_HELLO_MSG*/
|
{enb_agent_hello, 0, 0}, /*PROTOCOL__PROGRAN_MESSAGE__MSG_HELLO_MSG*/
|
||||||
{enb_agent_echo_request, enb_agent_echo_reply,0}, /**/
|
{enb_agent_echo_reply, 0, 0}, /*PROTOCOL__PROGRAN_MESSAGE__MSG_ECHO_REQUEST_MSG*/
|
||||||
{0, enb_agent_mac_reply,0}, /*stats*/
|
{0, 0, 0}, /*PROTOCOL__PROGRAN_MESSAGE__MSG_ECHO_REPLY_MSG*/ //Must add handler when receiving echo reply
|
||||||
{0,0,0},
|
{enb_agent_mac_reply, 0, 0}, /*PROTOCOL__PROGRAN_MESSAGE__MSG_STATS_REQUEST_MSG*/
|
||||||
|
{0,0,0}, /*PROTOCOL__PROGRAN_MESSAGE__MSG_STATS_REPLY_MSG*/
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -61,33 +62,35 @@ Protocol__ProgranMessage* enb_agent_handle_message (uint32_t xid,
|
|||||||
uint8_t *data,
|
uint8_t *data,
|
||||||
uint32_t size){
|
uint32_t size){
|
||||||
|
|
||||||
Protocol__ProgranMessage *message;
|
Protocol__ProgranMessage *decoded_message, *reply_message;
|
||||||
err_code_t err_code;
|
err_code_t err_code;
|
||||||
DevAssert(data != NULL);
|
DevAssert(data != NULL);
|
||||||
|
|
||||||
if (enb_agent_deserialize_message(data, size, &message) < 0) {
|
if (enb_agent_deserialize_message(data, size, &decoded_message) < 0) {
|
||||||
err_code= PROTOCOL__PROGRAN_ERR__MSG_DECODING;
|
err_code= PROTOCOL__PROGRAN_ERR__MSG_DECODING;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((message->msg_case > sizeof(messages_callback) / (3*sizeof(enb_agent_message_decoded_callback))) ||
|
if ((decoded_message->msg_case > sizeof(messages_callback) / (3*sizeof(enb_agent_message_decoded_callback))) ||
|
||||||
(message->msg_dir > PROTOCOL__PROGRAN_DIRECTION__UNSUCCESSFUL_OUTCOME)){
|
(decoded_message->msg_dir > PROTOCOL__PROGRAN_DIRECTION__UNSUCCESSFUL_OUTCOME)){
|
||||||
err_code= PROTOCOL__PROGRAN_ERR__MSG_NOT_HANDLED;
|
err_code= PROTOCOL__PROGRAN_ERR__MSG_NOT_HANDLED;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (messages_callback[message->msg_case][message->msg_dir] == NULL) {
|
if (messages_callback[decoded_message->msg_case-1][decoded_message->msg_dir-1] == NULL) {
|
||||||
err_code= PROTOCOL__PROGRAN_ERR__MSG_NOT_SUPPORTED;
|
err_code= PROTOCOL__PROGRAN_ERR__MSG_NOT_SUPPORTED;
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err_code= ((*messages_callback[message->msg_case-1][message->msg_dir-1])(xid, &message));
|
err_code= ((*messages_callback[decoded_message->msg_case-1][decoded_message->msg_dir-1])(xid, &reply_message));
|
||||||
if ( err_code < 0 ){
|
if ( err_code < 0 ){
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
return message;
|
protocol__progran_message__free_unpacked(decoded_message, NULL);
|
||||||
|
|
||||||
|
return reply_message;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
LOG_E(ENB_APP,"errno %d occured\n",err_code);
|
LOG_E(ENB_APP,"errno %d occured\n",err_code);
|
||||||
@@ -110,11 +113,12 @@ void * enb_agent_send_message(uint32_t xid,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// free the msg --> later keep this in the data struct and just update the values
|
// free the msg --> later keep this in the data struct and just update the values
|
||||||
enb_agent_mac_destroy_stats_reply(msg);
|
//TODO call proper destroy function
|
||||||
|
// enb_agent_mac_destroy_stats_reply(msg);
|
||||||
|
|
||||||
DevAssert(buffer !=NULL);
|
DevAssert(buffer !=NULL);
|
||||||
|
|
||||||
LOG_D(ENB_APP,"Serilized the enb mac stats reply (size %d)\n", size);
|
LOG_D(ENB_APP,"Serilized the enb mac stats reply (size %d)\n", *size);
|
||||||
|
|
||||||
return buffer;
|
return buffer;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user