Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of d7a_1x by
Diff: src/d7a_alp.cpp
- Revision:
- 88:dcebea09aac7
- Parent:
- 87:9b885d12dbb4
- Parent:
- 86:420918edb079
diff -r 9b885d12dbb4 -r dcebea09aac7 src/d7a_alp.cpp --- a/src/d7a_alp.cpp Mon Mar 13 11:56:35 2017 +0000 +++ b/src/d7a_alp.cpp Mon Mar 13 11:58:38 2017 +0000 @@ -11,9 +11,9 @@ #include "sha.h" #include "d7a_typedefs.h" -#if 0 +#if 1 #define ALP_DPRINT(...) DPRINT(__VA_ARGS__) - #define ALP_DPRINT_DATA(...) ALP_DPRINT_DATA(__VA_ARGS__) + #define ALP_DPRINT_DATA(...) DPRINT_DATA(__VA_ARGS__) #define ALP_FPRINT(...) FPRINT(__VA_ARGS__) #else #define ALP_DPRINT(...); @@ -22,6 +22,7 @@ #endif #define ALP_CMD_MAX_LENGHT (256) +#define MAX_RESPONSES (32) static uint8_t g_alp_tag; static uint8_t g_alp_root_key_size; @@ -366,7 +367,7 @@ return (uint32_t)(p - t); } -static void d7a_alp_construct_resp(d7a_msg_t** ret, uint8_t current_tag, uint32_t max_responses) +static void d7a_alp_construct_resp(d7a_msg_t** ret, uint8_t current_tag) { ALP_FPRINT("\r\n"); @@ -442,33 +443,33 @@ else { ALP_DPRINT("next response (err %d)\r\n", pl->msg->err); - ret[i] = pl->msg; + + if (i > MAX_RESPONSES) + { + WARNING(false, "Too much responses! max: %d\r\n", MAX_RESPONSES); + FREE(pl->msg); + } + else + { + ret[i] = pl->msg; + i++; + } + FREE(pl); - i++; - ASSERT(i <= max_responses, "Too much responses! max: %d\r\n", max_responses); } } while (1); } -uint32_t d7a_alp_construct_itf(uint8_t* p, d7a_addressee_t* addressee, uint8_t retry, bool resp) +static uint32_t d7a_alp_construct_itf(uint8_t* p, d7a_addressee_t* addressee, uint8_t retry, bool resp) { bool broadcast = false; - uint32_t max_responses = 2; if (addressee) { - if (addressee->ctrl.bf.idf == D7A_ID_NBID) + if (addressee->ctrl.bf.idf == D7A_ID_NBID || addressee->ctrl.bf.idf == D7A_ID_NOID) { broadcast = true; - d7a_ctf_t ctf; - ctf.byte = addressee->id[0]; - max_responses = ((1 << (2*ctf.bf.exp)) * ctf.bf.mant) + 1; - } - else if (addressee->ctrl.bf.idf == D7A_ID_NOID) - { - broadcast = true; - max_responses = 33; } // Construct interface @@ -486,16 +487,16 @@ memcpy(&itf.cfg.addressee, addressee, sizeof(d7a_addressee_t)); // Forward action - p += d7a_alp_forward_action(p, &itf, true); + return d7a_alp_forward_action(p, &itf, true); } - return max_responses; + return 0; } -d7a_msg_t** d7a_alp_init_ret(uint32_t max_responses) +d7a_msg_t** d7a_alp_init_ret(void) { - d7a_msg_t** ret = (d7a_msg_t**)MALLOC(sizeof(d7a_msg_t*) * (max_responses + 1)); - for (uint32_t i = 0; i < (max_responses + 1); i++) + d7a_msg_t** ret = (d7a_msg_t**)MALLOC(sizeof(d7a_msg_t*) * (MAX_RESPONSES + 1)); + for (uint32_t i = 0; i < (MAX_RESPONSES + 1); i++) { ret[i] = NULL; } @@ -514,17 +515,16 @@ uint8_t current_tag; d7a_msg_t** ret = NULL; - uint32_t max_responses; - - max_responses = d7a_alp_construct_itf(p, addressee, retry, resp); // malloc and init pointer array - ret = d7a_alp_init_ret(max_responses); - + ret = d7a_alp_init_ret(); // Tag action p += d7a_alp_tag(p, true); + // Eventual forward + p += d7a_alp_construct_itf(p, addressee, retry, resp); + // get tag current_tag = g_alp_tag; @@ -543,7 +543,7 @@ d7a_com_dump(&g_alp_buffer[0], (uint8_t)(p - t), KAL_COM_FLOW_AT_CMD); // Parse responses - d7a_alp_construct_resp(ret, current_tag, max_responses); + d7a_alp_construct_resp(ret, current_tag); return ret; } @@ -559,16 +559,16 @@ uint8_t current_tag; d7a_msg_t** ret = NULL; - uint32_t max_responses; - - max_responses = d7a_alp_construct_itf(p, addressee, retry, true); // malloc and init pointer array - ret = d7a_alp_init_ret(max_responses); + ret = d7a_alp_init_ret(); // Tag action p += d7a_alp_tag(p, true); + // Eventual forward + p += d7a_alp_construct_itf(p, addressee, retry, true); + // get tag current_tag = g_alp_tag; @@ -587,7 +587,7 @@ d7a_com_dump(&g_alp_buffer[0], (uint8_t)(p - t), KAL_COM_FLOW_AT_CMD); // Parse responses - d7a_alp_construct_resp(ret, current_tag, max_responses); + d7a_alp_construct_resp(ret, current_tag); return ret; } @@ -604,16 +604,16 @@ uint8_t current_tag; d7a_msg_t** ret = NULL; - uint32_t max_responses; - - max_responses = d7a_alp_construct_itf(p, addressee, retry, resp); // malloc and init pointer array - ret = d7a_alp_init_ret(max_responses); + ret = d7a_alp_init_ret(); // Tag action p += d7a_alp_tag(p, true); + // Eventual forward + p += d7a_alp_construct_itf(p, addressee, retry, resp); + // get tag current_tag = g_alp_tag; @@ -632,7 +632,7 @@ d7a_com_dump(&g_alp_buffer[0], (uint8_t)(p - t), KAL_COM_FLOW_AT_CMD); // Parse responses - d7a_alp_construct_resp(ret, current_tag, max_responses); + d7a_alp_construct_resp(ret, current_tag); return ret; }