Skip to content

Commit 2ef037f

Browse files
committed
fix #41
1 parent 245b6ad commit 2ef037f

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

src/oscore/oscore2coap.c

+28-3
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,10 @@ STATIC enum err oscore_option_parser(const struct o_coap_option *opt,
110110
out->kid_context.len = *val_ptr;
111111
out->kid_context.ptr = ++val_ptr;
112112
val_ptr += out->kid_context.len;
113-
temp_kid_len = (uint8_t)(
114-
temp_kid_len -
115-
(out->kid_context.len + 1));
113+
temp_kid_len =
114+
(uint8_t)(temp_kid_len -
115+
(out->kid_context.len +
116+
1));
116117
}
117118

118119
/* Get KID */
@@ -285,6 +286,24 @@ decrypt_wrapper(struct byte_array *ciphertext, struct byte_array *plaintext,
285286
return ok;
286287
}
287288

289+
static inline void set_observe_val(struct o_coap_option *options,
290+
uint8_t options_cnt, struct byte_array *piv)
291+
{
292+
uint16_t len;
293+
if (piv->len > 3) {
294+
len = 3;
295+
} else {
296+
len = (uint16_t)piv->len;
297+
}
298+
299+
for (uint8_t i = 0; i < options_cnt; i++) {
300+
if (options[i].option_number == OBSERVE) {
301+
options[i].value = piv->ptr;
302+
options[i].len = len;
303+
}
304+
}
305+
}
306+
288307
enum err oscore2coap(uint8_t *buf_in, uint32_t buf_in_len, uint8_t *buf_out,
289308
uint32_t *buf_out_len, struct context *c)
290309
{
@@ -400,6 +419,12 @@ enum err oscore2coap(uint8_t *buf_in, uint32_t buf_in_len, uint8_t *buf_out,
400419
&c->rc.notification_num,
401420
&c->rc.notification_num_initialized,
402421
&oscore_option.piv));
422+
423+
/*set outer observe option value to the three
424+
least significant bytes of the PIV*/
425+
set_observe_val(oscore_packet.options,
426+
oscore_packet.options_cnt,
427+
&oscore_option.piv);
403428
} else {
404429
/*Notification without PIV received -- Currently not supported*/
405430
return not_supported_feature; //LCOV_EXCL_LINE

0 commit comments

Comments
 (0)