szaszm commented on a change in pull request #674: Minificpp 1007 - ECU C2 
integration.
URL: https://github.com/apache/nifi-minifi-cpp/pull/674#discussion_r371750620
 
 

 ##########
 File path: extensions/coap/nanofi/coap_functions.c
 ##########
 @@ -146,29 +209,80 @@ void no_acknowledgement(struct coap_context_t *ctx, 
coap_session_t *session, coa
   }
 }
 
-void response_handler(struct coap_context_t *ctx, struct coap_session_t 
*session, coap_pdu_t *sent, coap_pdu_t *received, const coap_tid_t id) {
-  unsigned char* data;
-  size_t data_len;
-  coap_opt_iterator_t opt_iter;
-  coap_opt_t * block_opt = coap_check_option(received, COAP_OPTION_BLOCK1, 
&opt_iter);
-  if (block_opt) {
-    printf("Block option not currently supported");
-  } else {
-    if (!global_ptrs.data_received) {
-      return;
+void get_pdu_optlist(coap_pdu_t * pdu, coap_optlist_t ** optlist) {
+    coap_opt_t *option;
+    coap_opt_iterator_t opt_iter;
+    coap_option_iterator_init(pdu, &opt_iter, COAP_OPT_ALL);
+    while ((option = coap_option_next(&opt_iter))) {
+        //while iterating create a coap_optlist_t
+        if (opt_iter.type != COAP_OPTION_BLOCK1 && opt_iter.type != 
COAP_OPTION_SIZE1)
+            coap_insert_optlist(optlist, coap_new_optlist(opt_iter.type, 
coap_opt_length(option), coap_opt_value(option)));
     }
+}
+
+void handle_block_response(coap_opt_t * block_opt, struct coap_context_t *ctx, 
struct coap_session_t *session, coap_pdu_t *sent) {
+    unsigned int szx = COAP_OPT_BLOCK_SZX(block_opt);
+    unsigned int num = coap_opt_block_num(block_opt);
+    coap_block_t block;
+    block.num = num;
+    block.szx = szx;
+    //We are handling a response to POST request. Server never uses BLOCK1 
option in the response
+    //unless client initiated BLOCK1 blockwise transfer request. Therefore, it 
is safe to consider
+    //that the recently sent pdu within this session has the BLOCK1 option
+    coap_opt_iterator_t opt_iter;
+    block_opt = coap_check_option(sent, COAP_OPTION_BLOCK1, &opt_iter);
+    if (szx != COAP_OPT_BLOCK_SZX(block_opt)) {
+        block.num = coap_opt_block_num(block_opt);
+        block.szx = COAP_OPT_BLOCK_SZX(block_opt);
+        //Server negotiated a different block size
+        //client will follow the server, but we have to adjust block number
+        unsigned int bytes_sent = ((block.num + 1) << (block.szx + 4));
+        if (bytes_sent % (1 << (szx + 4)) == 0) {
+            num = block.num = (bytes_sent >> (szx + 4)) - 1;
 
 Review comment:
   `szx + 4` looks like a magic number that deserves a name. Could you give it 
a name?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to