37 #include "contiki-conf.h"
39 #if defined(linux) && NETSTACK_CONF_WITH_IPV6
41 #include "linuxradio-drv.h"
48 #include <sys/ioctl.h>
50 #include <sys/types.h>
51 #include <sys/socket.h>
52 #include <netinet/in.h>
54 #include <netinet/if_ether.h>
55 #include <netpacket/packet.h>
57 #include <linux/sockios.h>
62 #define PRINTF(...) printf(__VA_ARGS__)
67 static int sockfd = -1;
71 #define MAX_PACKET_SIZE 256
76 sockbuf = malloc(MAX_PACKET_SIZE);
83 prepare(
const void *payload,
unsigned short payload_len)
85 if(payload_len > MAX_PACKET_SIZE) {
88 memcpy(sockbuf, payload, payload_len);
94 transmit(
unsigned short transmit_len)
97 sent = send(sockfd, sockbuf, buflen, 0);
99 perror(
"linuxradio send()");
106 my_send(
const void *payload,
unsigned short payload_len)
110 if(prepare(payload, payload_len)) {
114 ret = transmit(payload_len);
119 my_read(
void *buf,
unsigned short buf_len)
129 receiving_packet(
void)
139 set_fd(fd_set *rset, fd_set *wset)
141 FD_SET(sockfd, rset);
145 handle_fd(fd_set *rset, fd_set *wset)
147 if(FD_ISSET(sockfd, rset)) {
148 int bytes = read(sockfd, sockbuf, MAX_PACKET_SIZE);
152 NETSTACK_RDC.input();
156 static const struct select_callback linuxradio_sock_callback = { set_fd, handle_fd };
163 struct sockaddr_ll sll;
165 sockfd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_IEEE802154));
167 perror(
"linuxradio socket()");
170 strncpy((
char *)ifr.ifr_name, NETSTACK_CONF_LINUXRADIO_DEV, IFNAMSIZ);
171 err = ioctl(sockfd, SIOCGIFINDEX, &ifr);
173 perror(
"linuxradio ioctl()");
176 sll.sll_family = AF_PACKET;
177 sll.sll_ifindex = ifr.ifr_ifindex;
178 sll.sll_protocol = htons(ETH_P_IEEE802154);
180 if(bind(sockfd, (
struct sockaddr *)&sll,
sizeof(sll)) < 0) {
181 perror(
"linuxradio bind()");
185 select_set_callback(sockfd, &linuxradio_sock_callback);
void * packetbuf_dataptr(void)
Get a pointer to the data in the packetbuf.
int(* channel_clear)(void)
Perform a Clear-Channel Assessment (CCA) to find out if there is a packet in the air or not...
int(* prepare)(const void *payload, unsigned short payload_len)
Prepare the radio with a packet to be sent.
int(* receiving_packet)(void)
Check if the radio driver is currently receiving a packet.
The structure of a device driver for a radio in Contiki.
int(* pending_packet)(void)
Check if the radio driver has just received a packet.
Header file for the Rime buffer (packetbuf) management
int(* off)(void)
Turn the radio off.
int(* on)(void)
Turn the radio on.
void packetbuf_set_datalen(uint16_t len)
Set the length of the data in the packetbuf.
int(* transmit)(unsigned short transmit_len)
Send the packet that has previously been prepared.
Include file for the Contiki low-layer network stack (NETSTACK)