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 Reply Children
  • 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

  • Can you post the code for the receiver? Have you checked with a sniffer is the packets are transmitted on-air?

  • i'm working on thread_simple_coap example with some changes
    in server side : we added case for button 2 to set new receiving callback function when receiving  an ipv6 packet. and at this function we print received packet.
    in client side : we added case for button 2 to send ipv6 with otIp6Send function after we getting addresses from provisioning_response_handler function and construct header as mentioned before

    main at server side (receiver)

    /**
     * Copyright (c) 2017 - 2017, Nordic Semiconductor ASA
     * 
     * All rights reserved.
     * 
     * Redistribution and use in source and binary forms, with or without modification,
     * are permitted provided that the following conditions are met:
     * 
     * 1. Redistributions of source code must retain the above copyright notice, this
     *    list of conditions and the following disclaimer.
     * 
     * 2. Redistributions in binary form, except as embedded into a Nordic
     *    Semiconductor ASA integrated circuit in a product or a software update for
     *    such product, must reproduce the above copyright notice, this list of
     *    conditions and the following disclaimer in the documentation and/or other
     *    materials provided with the distribution.
     * 
     * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
     *    contributors may be used to endorse or promote products derived from this
     *    software without specific prior written permission.
     * 
     * 4. This software, with or without modification, must only be used with a
     *    Nordic Semiconductor ASA integrated circuit.
     * 
     * 5. Any software provided in binary form under this license must not be reverse
     *    engineered, decompiled, modified and/or disassembled.
     * 
     * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
     * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
     * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
     * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
     * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
     * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     * 
     */
    /** @file
     *
     * @defgroup simple_coap_server_example_main main.c
     * @{
     * @ingroup simple_coap_server_example_example
     * @brief Simple CoAP Server Example Application main file.
     *
     * @details This example demonstrates a CoAP server application that provides resources to control BSP_LED_3
     *          via CoAP messages. It can be controlled by a board with related Simple CoAP Server application.
     */
    
    #include <stdint.h>
    
    #include "app_timer.h"
    #include "bsp_thread.h"
    #include "nrf_log_ctrl.h"
    #include "nrf_log.h"
    #include "nrf_log_default_backends.h"
    
    #include "thread_coap_utils.h"
    #include "thread_utils.h"
    
    #include <openthread/openthread.h>
    
    void ot_receive_handler(otMessage *aMessage, void *aContext)
    {
        
          NRF_LOG_INFO("packet received");
    }
    
    void change_rec(void)
    {
           
            otIp6SetReceiveFilterEnabled(thread_ot_instance_get(), true);
    	otIp6SetReceiveCallback(thread_ot_instance_get(),ot_receive_handler, NULL);
    }
    
    
    
    /***************************************************************************************************
     * @section Buttons
     **************************************************************************************************/
    
    static void bsp_event_handler(bsp_event_t event)
    {
        switch(event)
        {
    
             case BSP_EVENT_KEY_2:
                change_rec();
                break;
    
            case BSP_EVENT_KEY_3:
                thread_coap_utils_provisioning_enable(true);
                break;
    
            default:
                return;
        }
    }
    
    /***************************************************************************************************
     * @section Callbacks
     **************************************************************************************************/
    
    static void thread_state_changed_callback(uint32_t flags, void * p_context)
    {
        if (flags & OT_CHANGED_THREAD_ROLE)
        {
            switch (otThreadGetDeviceRole(p_context))
            {
                case OT_DEVICE_ROLE_CHILD:
                case OT_DEVICE_ROLE_ROUTER:
                case OT_DEVICE_ROLE_LEADER:
                    break;
    
                case OT_DEVICE_ROLE_DISABLED:
                case OT_DEVICE_ROLE_DETACHED:
                default:
                    thread_coap_utils_provisioning_enable(false);
                    break;
            }
        }
        NRF_LOG_INFO("State changed! Flags: 0x%08x Current role: %d\r\n",
                     flags,
                     otThreadGetDeviceRole(p_context));
    
    }
    
    /***************************************************************************************************
     * @section Initialization
     **************************************************************************************************/
    
    /**@brief Function for initializing the Application Timer Module.
     */
    static void timer_init(void)
    {
        uint32_t error_code = app_timer_init();
        APP_ERROR_CHECK(error_code);
    }
    
    
    /**@brief Function for initializing the nrf log module.
     */
    static void log_init(void)
    {
        ret_code_t err_code = NRF_LOG_INIT(NULL);
        APP_ERROR_CHECK(err_code);
    
        NRF_LOG_DEFAULT_BACKENDS_INIT();
    }
    
    
    /**@brief Function for initializing the Thread Board Support Package.
     */
    static void thread_bsp_init(void)
    {
        uint32_t error_code = bsp_init(BSP_INIT_LED | BSP_INIT_BUTTONS, bsp_event_handler);
        APP_ERROR_CHECK(error_code);
    
        error_code = bsp_thread_init(thread_ot_instance_get());
        APP_ERROR_CHECK(error_code);
    }
    
    
    /**@brief Function for initializing the Thread Stack.
     */
    static void thread_instance_init(void)
    {
        thread_configuration_t thread_configuration =
        {
            .role                  = RX_ON_WHEN_IDLE,
            .autocommissioning     = true,
            .poll_period           = 2500,
            .default_child_timeout = 10,
        };
    
        thread_init(&thread_configuration);
        thread_cli_init();
        thread_state_changed_callback_set(thread_state_changed_callback);
    }
    
    
    /**@brief Function for initializing the Constrained Application Protocol Module.
     */
    static void thread_coap_init(void)
    {
        thread_coap_configuration_t thread_coap_configuration =
        {
            .coap_server_enabled               = true,
            .coap_client_enabled               = false,
            .coap_cloud_enabled                = false,
            .configurable_led_blinking_enabled = false,
        };
    
        thread_coap_utils_init(&thread_coap_configuration);
    }
    
    /***************************************************************************************************
     * @section Main
     **************************************************************************************************/
    
    int main(int argc, char * argv[])
    {
          
      
        log_init();
        timer_init();
    
        // Initialize Thread CoAP utils.
        thread_coap_utils_led_timer_init();
        thread_coap_utils_provisioning_timer_init();
        thread_coap_utils_led_timer_start();
    
        // Initialize the Thread stack.
        thread_instance_init();
        thread_coap_init();
        thread_bsp_init();
    
        while (true)
        {
            thread_process();
        if (NRF_LOG_PROCESS() == false)
            {
                thread_sleep();
    
            }
        }
    }
    
    /**
     *@}
     **/
    

  • Are you sure that the destination address is assigned correctly in the packet? If you could provide a sniffer trace of on-air traffic (you can use our nRF 802.15.4 sniffer solution), that would help determine what is happening. If you are not able to do this, please provide full projects for transmitter and receiver side.

  • i don't have sniffer so i couldn't trace packets on air.

    i got destination address from coap functions and used it to send in otip6send and it we can't receive as  callback receive function doesn't be called.

    is there a clear way to determine the destination address ?

    i'll try to upload examples.

Related