static smcp_status_t smcp_outbound_add_options_up_to_key_( coap_option_key_t key ) { smcp_status_t ret = SMCP_STATUS_OK; smcp_t const self = smcp_get_current_instance(); #if SMCP_CONF_TRANS_ENABLE_BLOCK2 if( (self->current_transaction && self->current_transaction->next_block2) && self->outbound.last_option_key<COAP_OPTION_BLOCK2 && key>COAP_OPTION_BLOCK2 ) { uint32_t block2 = htonl(self->current_transaction->next_block2); uint8_t size = 3; // TODO: calculate this properly ret = smcp_outbound_add_option_( COAP_OPTION_BLOCK2, (char*)&block2+sizeof(block2)-size, size ); } #endif #if SMCP_CONF_TRANS_ENABLE_OBSERVING if( (self->current_transaction && self->current_transaction->flags&SMCP_TRANSACTION_OBSERVE) && self->outbound.last_option_key<COAP_OPTION_OBSERVE && key>COAP_OPTION_OBSERVE ) { if(self->outbound.packet->code && self->outbound.packet->code<COAP_RESULT_100) { // For sending a request. ret = smcp_outbound_add_option_( COAP_OPTION_OBSERVE, (void*)NULL, 0 ); } } #endif if( self->outbound.last_option_key<COAP_OPTION_AUTHENTICATE && key>COAP_OPTION_AUTHENTICATE ) { ret = smcp_auth_add_options(); } #if SMCP_USE_CASCADE_COUNT if( self->outbound.last_option_key<COAP_OPTION_CASCADE_COUNT && key>COAP_OPTION_CASCADE_COUNT && self->has_cascade_count ) { ret = smcp_outbound_add_option_( COAP_OPTION_CASCADE_COUNT, (char*)&self->cascade_count, 1 ); } #endif return ret; }
static smcp_status_t smcp_outbound_add_options_up_to_key_( coap_option_key_t key ) { smcp_status_t ret = SMCP_STATUS_OK; smcp_t const self = smcp_get_current_instance(); (void)self; #if SMCP_CONF_TRANS_ENABLE_BLOCK2 if( (self->current_transaction && self->current_transaction->next_block2) && self->outbound.last_option_key<COAP_OPTION_BLOCK2 && key>COAP_OPTION_BLOCK2 ) { uint32_t block2 = htonl(self->current_transaction->next_block2); uint8_t size = smcp_calc_uint32_option_size(block2); ret = smcp_outbound_add_option_( COAP_OPTION_BLOCK2, (char*)&block2+4-size, size ); } #endif #if SMCP_CONF_TRANS_ENABLE_OBSERVING if( (self->current_transaction && self->current_transaction->flags&SMCP_TRANSACTION_OBSERVE) && self->outbound.last_option_key<COAP_OPTION_OBSERVE && key>COAP_OPTION_OBSERVE ) { if(self->outbound.packet->code && self->outbound.packet->code<COAP_RESULT_100) { // For sending a request. ret = smcp_outbound_add_option_( COAP_OPTION_OBSERVE, (void*)NULL, 0 ); } } #endif #if SMCP_USE_CASCADE_COUNT if( self->outbound.last_option_key<COAP_OPTION_CASCADE_COUNT && key>COAP_OPTION_CASCADE_COUNT && self->cascade_count ) { uint8_t cc = self->cascade_count-1; ret = smcp_outbound_add_option_( COAP_OPTION_CASCADE_COUNT, (char*)&cc, 1 ); } #endif return ret; }
smcp_status_t smcp_outbound_add_option( coap_option_key_t key, const char* value, size_t len ) { smcp_status_t ret = 0; ret = smcp_outbound_add_options_up_to_key_(key); require_noerr(ret, bail); #if SMCP_CONF_TRANS_ENABLE_BLOCK2 if(key==COAP_OPTION_BLOCK2 && smcp_get_current_instance()->current_transaction && smcp_get_current_instance()->current_transaction->next_block2 ) { goto bail; } #endif ret = smcp_outbound_add_option_(key,value,len); require_noerr(ret, bail); bail: return ret; }