Search code examples
iotcoaplwm2m

How to send firmware package from LWM2M Leshan server to LWM2M Wakaama client?


I have a LwM2M Wakaama client working with a Leshan server. When I try to send a huge hexbinary string via the write option on Package resource for Firmware update object 5, I get the following error message on the client side:

"Block1 NOT IMPLEMENTED".

I understand that block1 was not implemented on the wakaama client and only block2 was implemented, does anyone know why?

Also, How can I make firmware update with package resource work with the Leshan Server and Wakaama Client?

I believe I can either change the Leshan Server to send a request of type BLOCK2 (which I dont know how to do from the limited UI?) or add support for BLOCK1 on Wakaama LWM2M client.

Has anyone tried this?


Solution

  • Added Block1 support by doing the following changes in the function lwm2m_handle_packet in Paket.c ~ line 234-263:

           /* get offset for blockwise transfers */
            if (coap_get_header_block2(message, &block_num, NULL, &block_size, &block_offset))
            {
                LOG("Blockwise2: block request %u (%u/%u) @ %u bytes\n", block_num, block_size, REST_MAX_CHUNK_SIZE, block_offset);
                block_size = MIN(block_size, REST_MAX_CHUNK_SIZE);
                new_offset = block_offset;
            }
            ++else if (coap_get_header_block1(message, &block_num, NULL, &block_size, &block_offset))
            ++{
                ++LOG("Blockwise1: block request %u (%u/%u) @ %u bytes\n", block_num, block_size, REST_MAX_CHUNK_SIZE, block_offset);
                ++block_size = MIN(block_size, REST_MAX_CHUNK_SIZE);
                ++new_offset = block_offset;
            ++}
            coap_error_code = handle_request(contextP, fromSessionH, message, response);
            if (coap_error_code==NO_ERROR)
            {
                /* Apply blockwise transfers. */
                if ( IS_OPTION(message, COAP_OPTION_BLOCK1) && response->code<BAD_REQUEST_4_00 && !IS_OPTION(response, COAP_OPTION_BLOCK1) )
                {
                    ++//LOG("Block1 NOT IMPLEMENTED\n");
    
                    ++//coap_error_code = NOT_IMPLEMENTED_5_01;
                    ++//coap_error_message = "NoBlock1Support";
                    ++LOG("Block1 IMPLEMENTED\n");
                    ++coap_set_header_block1(response, block_num, 0, block_size);
    
                }
                else if ( IS_OPTION(message, COAP_OPTION_BLOCK2) )