net/nanocoap: Move NANOCOAP_NOPTS_MAX to 'CONFIG_' namespace

This commit is contained in:
Leandro Lanzieri 2020-01-30 14:03:39 +01:00
parent dbacca18c1
commit c84576ef6e
No known key found for this signature in database
GPG Key ID: 39607DE6080007A3
3 changed files with 16 additions and 16 deletions

View File

@ -124,8 +124,8 @@ extern "C" {
* @{
*/
/** @brief Maximum number of Options in a message */
#ifndef NANOCOAP_NOPTS_MAX
#define NANOCOAP_NOPTS_MAX (16)
#ifndef CONFIG_NANOCOAP_NOPTS_MAX
#define CONFIG_NANOCOAP_NOPTS_MAX (16)
#endif
/**
@ -182,14 +182,14 @@ typedef struct {
* @brief CoAP PDU parsing context structure
*/
typedef struct {
coap_hdr_t *hdr; /**< pointer to raw packet */
uint8_t *token; /**< pointer to token */
uint8_t *payload; /**< pointer to payload */
uint16_t payload_len; /**< length of payload */
uint16_t options_len; /**< length of options array */
coap_optpos_t options[NANOCOAP_NOPTS_MAX]; /**< option offset array */
coap_hdr_t *hdr; /**< pointer to raw packet */
uint8_t *token; /**< pointer to token */
uint8_t *payload; /**< pointer to payload */
uint16_t payload_len; /**< length of payload */
uint16_t options_len; /**< length of options array */
coap_optpos_t options[CONFIG_NANOCOAP_NOPTS_MAX]; /**< option offset array */
#ifdef MODULE_GCOAP
uint32_t observe_value; /**< observe value */
uint32_t observe_value; /**< observe value */
#endif
} coap_pkt_t;

View File

@ -108,7 +108,7 @@ int coap_parse(coap_pkt_t *pkt, uint8_t *buf, size_t len)
DEBUG("option count=%u nr=%u len=%i\n", option_count, option_nr, option_len);
if (option_delta) {
if (option_count >= NANOCOAP_NOPTS_MAX) {
if (option_count >= CONFIG_NANOCOAP_NOPTS_MAX) {
DEBUG("nanocoap: max nr of options exceeded\n");
return -ENOMEM;
}
@ -783,7 +783,7 @@ size_t coap_opt_put_uint(uint8_t *buf, uint16_t lastonum, uint16_t onum,
static ssize_t _add_opt_pkt(coap_pkt_t *pkt, uint16_t optnum, const uint8_t *val,
size_t val_len)
{
if (pkt->options_len >= NANOCOAP_NOPTS_MAX) {
if (pkt->options_len >= CONFIG_NANOCOAP_NOPTS_MAX) {
return -ENOSPC;
}

View File

@ -535,7 +535,7 @@ static void test_nanocoap__server_option_count_overflow_check(void)
{
/* this test passes a forged CoAP packet containing 42 options (provided by
* @nmeum in #10753, 42 is a random number which just needs to be higher
* than NANOCOAP_NOPTS_MAX) to coap_parse(). The used coap_pkt_t is part
* than CONFIG_NANOCOAP_NOPTS_MAX) to coap_parse(). The used coap_pkt_t is part
* of a struct, followed by an array of 42 coap_option_t. The array is
* cleared before the call to coap_parse(). If the overflow protection is
* working, the array must still be clear after parsing the packet, and the
@ -553,8 +553,8 @@ static void test_nanocoap__server_option_count_overflow_check(void)
0x11, 0x17, 0x11, 0x17, 0x11, 0x17, 0x11, 0x17, 0x11, 0x17, 0x11, 0x17,
0x11, 0x17, 0x11, 0x17 };
/* ensure NANOCOAP_NOPTS_MAX is actually lower than 42 */
TEST_ASSERT(NANOCOAP_NOPTS_MAX < 42);
/* ensure CONFIG_NANOCOAP_NOPTS_MAX is actually lower than 42 */
TEST_ASSERT(CONFIG_NANOCOAP_NOPTS_MAX < 42);
struct {
coap_pkt_t pkt;
@ -588,7 +588,7 @@ static void test_nanocoap__server_option_count_overflow(void)
* path, but only 1 entry in the options array.
* Size buf to accept an extra 2-byte option */
unsigned base_len = 17;
uint8_t buf[17 + (2 * NANOCOAP_NOPTS_MAX)] = {
uint8_t buf[17 + (2 * CONFIG_NANOCOAP_NOPTS_MAX)] = {
0x42, 0x01, 0xbe, 0x16, 0x35, 0x61, 0xb4, 0x72,
0x69, 0x6f, 0x74, 0x05, 0x76, 0x61, 0x6c, 0x75,
0x65
@ -600,7 +600,7 @@ static void test_nanocoap__server_option_count_overflow(void)
/* fill pkt with maximum options; should succeed */
int i = 0;
for (; i < (2 * (NANOCOAP_NOPTS_MAX - 1)); i+=2) {
for (; i < (2 * (CONFIG_NANOCOAP_NOPTS_MAX - 1)); i+=2) {
memcpy(&buf[base_len+i], fill_opt, 2);
}