@@ -191,15 +191,43 @@ options_reorder(struct o_coap_option *U_options, uint8_t U_options_cnt,
191
191
return ok ;
192
192
}
193
193
194
+ /**
195
+ * @brief Set the value of the inner observe option to the three least
196
+ * significant bytes of the partial IV, see RFC8613 4.1.3.5.2
197
+ *
198
+ * @param options array of all inner options
199
+ * @param options_cnt number of options
200
+ * @param piv PIV
201
+ */
202
+ STATIC void set_observe_val (struct o_coap_option * options ,
203
+ uint8_t options_cnt , struct byte_array * piv )
204
+ {
205
+ uint16_t len ;
206
+ if (piv -> len > 3 ) {
207
+ len = 3 ;
208
+ } else {
209
+ len = (uint16_t )piv -> len ;
210
+ }
211
+
212
+ for (uint8_t i = 0 ; i < options_cnt ; i ++ ) {
213
+ if (options [i ].option_number == OBSERVE ) {
214
+ options [i ].value = piv -> ptr ;
215
+ options [i ].len = len ;
216
+ }
217
+ }
218
+ }
219
+
194
220
/**
195
221
* @brief Generate CoAP packet from OSCORE packet
196
222
* @param decrypted_payload: decrypted OSCORE payload, which contains code, E-options and original unprotected CoAP payload
197
223
* @param oscore_pkt: input OSCORE packet
224
+ * @param piv: PIV to be used only in the case of observe notification
198
225
* @param out: pointer to output CoAP packet
199
226
* @return
200
227
*/
201
228
static inline enum err o_coap_pkg_generate (struct byte_array * decrypted_payload ,
202
229
struct o_coap_packet * oscore_pkt ,
230
+ struct byte_array * piv ,
203
231
struct o_coap_packet * out )
204
232
{
205
233
uint8_t code = 0 ;
@@ -212,6 +240,10 @@ static inline enum err o_coap_pkg_generate(struct byte_array *decrypted_payload,
212
240
& E_options_cnt ,
213
241
& unprotected_o_coap_payload ));
214
242
243
+ /*set inner observe option value to the three least significant bytes
244
+ of the PIV*/
245
+ set_observe_val (& E_options , E_options_cnt , piv );
246
+
215
247
/* Copy each items from OSCORE packet to CoAP packet */
216
248
/* Header */
217
249
out -> header .ver = oscore_pkt -> header .ver ;
@@ -286,24 +318,6 @@ decrypt_wrapper(struct byte_array *ciphertext, struct byte_array *plaintext,
286
318
return ok ;
287
319
}
288
320
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
-
307
321
enum err oscore2coap (uint8_t * buf_in , uint32_t buf_in_len , uint8_t * buf_out ,
308
322
uint32_t * buf_out_len , struct context * c )
309
323
{
@@ -419,12 +433,6 @@ enum err oscore2coap(uint8_t *buf_in, uint32_t buf_in_len, uint8_t *buf_out,
419
433
& c -> rc .notification_num ,
420
434
& c -> rc .notification_num_initialized ,
421
435
& 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 );
428
436
} else {
429
437
/*Notification without PIV received -- Currently not supported*/
430
438
return not_supported_feature ; //LCOV_EXCL_LINE
@@ -445,7 +453,8 @@ enum err oscore2coap(uint8_t *buf_in, uint32_t buf_in_len, uint8_t *buf_out,
445
453
446
454
/* Generate corresponding CoAP packet */
447
455
struct o_coap_packet o_coap_packet ;
448
- TRY (o_coap_pkg_generate (& plaintext , & oscore_packet , & o_coap_packet ));
456
+ TRY (o_coap_pkg_generate (& plaintext , & oscore_packet , & oscore_option .piv ,
457
+ & o_coap_packet ));
449
458
450
459
/*Convert to byte string*/
451
460
return coap_serialize (& o_coap_packet , buf_out , buf_out_len );
0 commit comments