I am developing a CoAP client on the nRF9160 DK, running Zephyr RTOS. I am having trouble with longer Proxy-URI's; short URIs (268 characters and below) work fine and the coap message reaches the server as expected. However, messages with longer Proxy-URIs (269 characters and above) fail to go through for some reason. For example, with the following initialisation:
uint8_t tx_coap_buf[2048];
err = coap_packet_init(&request, tx_coap_buf, sizeof(tx_coap_buf), APP_COAP_VERSION, COAP_TYPE_CON, sizeof(next_token), (uint8_t *) &next_token, COAP_METHOD_POST, next_id);
if (err < 0) {
LOG_DBG("Failed to create CoAP request, %d", err);
return err;
}
The below (short) works fine
char * proxy_uri = "http://127.0.0.1:3000/abc/europe-xyz1/coap-abc/abc-device/publishEvent?jwt=eyJ0eXAiO";
ssize_t proxy_uri_len = strlen(proxy_uri);
err = coap_packet_append_option(&request, COAP_OPTION_PROXY_URI, proxy_uri, proxy_uri_len);
if (err < 0) {
LOG_DBG("Failed to create CoAP request, %d", err);
return err;
}
But this one (longer) doesn't, even though err returns as 0.
char * proxy_uri = "http://127.0.0.1:3000/abc/europe-xyz1/coap-abc/abc-device/publishEvent?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NiJ9.eyJhdWQiOiJhaXPocmlzIiwiaXNzJjoiYXV0aDAiLCJleHTiOjE2MDk0Nzc1NTUsImlhdCI6MTYwOTQ2Njc1MX2.RBs-SSa8x9VpyvBRw_EA2CUihgle5yGDJa8f2DUoGXe8d1Vah6bABILZuuyFQXcEg0Mh1BLn1p6qmbwb8BnsNg";
ssize_t proxy_uri_len = strlen(proxy_uri);
err = coap_packet_append_option(&request, COAP_OPTION_PROXY_URI, proxy_uri, proxy_uri_len);
if (err < 0) {
LOG_DBG("Failed to create CoAP request, %d", err);
return err;
}
...and when I inspect the CoAP message using Wireshark, the Proxy-URI option has the warning: Expert Info (Warning/Malformed): option longer than the package
I tried setting the additional Zephyr CoAP config as follows
CONFIG_COAP_EXTENDED_OPTIONS_LEN=y
CONFIG_COAP_EXTENDED_OPTIONS_LEN_VALUE=800
...but had no luck.
Would anyone know what I could be missing? Is there some CoAP config whose default value I need to override so as to accommodate longer Proxy-URI options?
Thanks.
Got it! Version 1.4.1, coap.c, line 221, uses "delta_size" instead of "len_size".
if (len_size == 1U) {
res = append_u8(cpkt, (uint8_t)len_ext);
if (!res) {
return -EINVAL;
}
} else if (delta_size == 2U) {
res = append_be16(cpkt, len_ext);
if (!res) {
return -EINVAL;
}
}
I add this to your question in the forum.
And https://github.com/zephyrproject-rtos/zephyr/issues/31206