通过在 Paket.c ~ line 234-263 中的函数 lwm2m_handle_packet 中进行以下更改来添加 Block1 支持:
/* 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) )