0
votes

I'm trying to code my own RDC layer in contiki, with the PW-MAC protocol. I was wondering how to send a broadcast in this layer because there will have no network and no transport layer. The function i have to use will be:

NETSTACK_RDC.send(mac_callback_t sent, void *ptr)

But I really don't know what mac_callback_t and ptr is... The examples in sources use udp for the broadcast so it will be very annoying if i have to implement a transport layer.

Thanks for your answers

2
You sound quite confused. Do you know how to send unicast packet and want to modify your code to send a broadcast packet, or you just want to send any packet? For RDC layer having broadcast vs. unicast packets may not make a large difference. - kfx

2 Answers

0
votes

You should check a bit the doc and the code, that could help you a lot. ptr is a data pointer (void*). So its your data to send. mac_call_back_t is clear : to trigger a callback to the mac layer. (a function pointer)
To send a broadcast, just send to FFF address. (you must change the address with packetbuf, check the doc of packetbuf. (a good link for packet_buf : http://anrg.usc.edu/contiki/index.php/Packetbuffer_Basics)
Check the broadcast_conn in Rime to understand how broadcast are done and to have an example.

0
votes

RDC stands for "radio duty cycling". The RDC layer uses radio functions directly, so sending a packet could be as simple as calling NETSTACK_RADIO.send(packetbuf_hdrptr(), packetbuf_totlen()).

The Contiki network stack has this layering structure:

NETWORK layer -> MAC layer -> RDC layer -> RADIO layer.

(In recent versions there's an additional LLSEC layer between NETWORK and MAC layers.)

So an implementation of RDC layer API uses the RADIO layer API and is called by / reports to MAC layer API. You can look at core/net/mac/nullrdc.c to see how to implement a simple RDC driver.

As you noted, NETSTACK_RDC.send(mac_callback_t sent, void *ptr) takes two parameters. The first is of callback type which you need to call after finishing the sending, the second is user data you need to pass to the to the callback.

The callback is typedef in net/mac/mac.h as:

typedef void (* mac_callback_t)(void *ptr, int status, int transmissions);
  • ptr is the user data pointer passed to NETSTACK_RDC.send;
  • status is MAC status code, such as MAC_TX_OK - the result of the transmission;
  • transmissions is the number of transmissions.