This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

can't send ipv6

i'm trying to send ipv6 packet over thread with function otIp6Send.
but otIp6Send doesn't work and return '6' which means  "Failed to parse message or arguments." as openthread errors says.
i don't know why !!

i'm using nrf52840.
this's part of my code

static void ip_packet_transmit(void)
{
      uint8_t err;
      uint8_t* header5;
      header5= (uint8_t*)contructip6add(source_addr,des_addr,4);
          uint8_t aData [4]={'p','l','a','y'};
        otMessage *amessage;
        amessage=otIp6NewMessage(thread_ot_instance_get(), true);
                err=otMessageAppend(amessage, header5, 40);
        if (amessage == NULL) {
         return 0;
    }  
        err=otMessageAppend(amessage, aData, 4);
             if (err!= OT_ERROR_NONE ) {
        return  0;
    }

        err=otIp6Send(thread_ot_instance_get(),amessage);
       if(err!= OT_ERROR_NONE)
       {
          NRF_LOG_INFO("fail to send with error =  %d",err);
       }
       else
      {
         NRF_LOG_INFO("sent");
       }
 
}

 uint32_t* contructip6add (uint32_t* src,uint32_t* dest,uint16_t pay_len)
{
   static uint32_t header [10];
    header[0]=(((uint32_t)ver)<<28)|(((uint32_t)TRAFFIC_CLASS)<<20)|FLOW_LABEL;
    header[1]=(((uint32_t)pay_len)<<16)|(((uint32_t)NEXT_HEADER)<<8)|HOP_LIMIT;
    header[2]=src[0];
    header[3]=src[1];
    header[4]=src[2];
    header[5]=src[3];
    header[6]=dest[0];
    header[7]=dest[1];
    header[8]=dest[2];
    header[9]=dest[3];
    return header;
}

Parents
  • Hi,

    Have you tried filling the message buffer with static data? The header array in contructip6add will be out of scope when you use the pointer to it (header5) in otMessageAppend().

    Best regards,
    Jørgen

  • the problem was that header constructed in wrong way.

    but now after editing the code
        header[0]=lwip_htonl((((uint32_t)ver)<<28)|(((uint32_t)TRAFFIC_CLASS)<<20)|FLOW_LABEL);
        header[1]=lwip_htonl((((uint32_t)pay_len)<<16)|(((uint32_t)NEXT_HEADER)<<8)|HOP_LIMIT);
        header[2]=(src[0]);
        header[3]=(src[1]);
        header[4]=(src[2]);
        header[5]=(src[3]);
        header[6]=(dest[0]);
        header[7]=(dest[1]);
        header[8]=(dest[2]);
        header[9]=(dest[3]);

    i got no error from function otIp6Send . but i still can't receive the data from receiver as the receiver code doesn't get into my callback receiver function although when sending over coap ,receiver code get into my callback receive function without any problems

Reply
  • the problem was that header constructed in wrong way.

    but now after editing the code
        header[0]=lwip_htonl((((uint32_t)ver)<<28)|(((uint32_t)TRAFFIC_CLASS)<<20)|FLOW_LABEL);
        header[1]=lwip_htonl((((uint32_t)pay_len)<<16)|(((uint32_t)NEXT_HEADER)<<8)|HOP_LIMIT);
        header[2]=(src[0]);
        header[3]=(src[1]);
        header[4]=(src[2]);
        header[5]=(src[3]);
        header[6]=(dest[0]);
        header[7]=(dest[1]);
        header[8]=(dest[2]);
        header[9]=(dest[3]);

    i got no error from function otIp6Send . but i still can't receive the data from receiver as the receiver code doesn't get into my callback receiver function although when sending over coap ,receiver code get into my callback receive function without any problems

Children
No Data
Related