本文整理汇总了C++中packetbuf_hdrptr函数的典型用法代码示例。如果您正苦于以下问题:C++ packetbuf_hdrptr函数的具体用法?C++ packetbuf_hdrptr怎么用?C++ packetbuf_hdrptr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了packetbuf_hdrptr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: handle_beacon_send_timer
/*---------------------------------------------------------------------------*/
static void
handle_beacon_send_timer(struct net_buf *buf, void *p)
{
struct net_buf *mbuf;
frame802154_t params;
uint8_t len;
mbuf = l2_buf_get_reserve(0);
if(!mbuf) {
return;
}
/* init to zeros */
memset(¶ms, 0, sizeof(params));
/* use packetbuf for sending ?? */
packetbuf_clear(mbuf);
/* Build the FCF. */
params.fcf.frame_type = FRAME802154_BEACONFRAME;
/* Insert IEEE 802.15.4 (2006) version bits. */
params.fcf.frame_version = FRAME802154_IEEE802154_2006;
/* assume long for now */
params.fcf.src_addr_mode = FRAME802154_LONGADDRMODE;
linkaddr_copy((linkaddr_t *)¶ms.src_addr, &linkaddr_node_addr);
/* Set the source PAN ID to the global variable. */
params.src_pid = panid;
params.fcf.dest_addr_mode = FRAME802154_SHORTADDRMODE;
params.dest_addr[0] = 0xFF;
params.dest_addr[1] = 0xFF;
params.dest_pid = 0xffff;
params.seq = framer_802154_next_seqno();
/* Calculate beacon length and copy it to packetbuf */
beacon_payload_len = handler_802154_calculate_beacon_payload_length(beacon_payload, BEACON_PAYLOAD_BUFFER_SIZE);
packetbuf_copyfrom(mbuf, beacon_payload, beacon_payload_len);
/* Set payload and payload length */
params.payload = packetbuf_dataptr(mbuf);
params.payload_len = packetbuf_datalen(mbuf);
len = frame802154_hdrlen(¶ms);
if(packetbuf_hdralloc(mbuf, len)) {
frame802154_create(¶ms, packetbuf_hdrptr(mbuf), len);
if(NETSTACK_RADIO.send(mbuf, packetbuf_hdrptr(mbuf),
packetbuf_totlen(mbuf)) != RADIO_TX_OK) {
l2_buf_unref(mbuf);
return;
}
HANDLER_802154_STAT(handler_802154_stats.beacons_sent++);
}
}
示例2: output
/*---------------------------------------------------------------------------*/
static int
output(struct channel *c)
{
const struct packetbuf_attrlist *a;
int byteptr, len;
uint8_t *hdrptr;
struct raw_hdr *hdr;
/* Compute the total size of the final header by summing the size of
all attributes that are used on this channel. */
if(packetbuf_hdralloc(c->hdrsize + sizeof(struct raw_hdr)) == 0) {
PRINTF("chameleon-raw: insufficient space for headers\n");
return 0;
}
hdr = (struct raw_hdr *)packetbuf_hdrptr();
hdr->channel[0] = c->channelno & 0xff;
hdr->channel[1] = (c->channelno >> 8) & 0xff;
hdrptr = ((uint8_t *)packetbuf_hdrptr()) + sizeof(struct raw_hdr);
byteptr = 0;
for(a = c->attrlist; a->type != PACKETBUF_ATTR_NONE; ++a) {
#if CHAMELEON_WITH_MAC_LINK_ADDRESSES
if(a->type == PACKETBUF_ADDR_SENDER ||
a->type == PACKETBUF_ADDR_RECEIVER) {
/* Let the link layer handle sender and receiver */
PRINTF("%d.%d: pack_header leaving sender/receiver to link layer\n");
continue;
}
#endif /* CHAMELEON_WITH_MAC_LINK_ADDRESSES */
PRINTF("%d.%d: pack_header type %d, len %d\n",
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
a->type, a->len);
len = (a->len & 0xf8) + ((a->len & 7) ? 8: 0);
if(PACKETBUF_IS_ADDR(a->type)) {
const rimeaddr_t *rimeaddr;
/* memcpy(&hdrptr[byteptr], (uint8_t *)packetbuf_attr_aget(a->type), len / 8);*/
rimeaddr = packetbuf_addr(a->type);
hdrptr[byteptr] = rimeaddr->u8[0];
hdrptr[byteptr + 1] = rimeaddr->u8[1];
PRINTF("%d.%d: address %d.%d\n",
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
((uint8_t *)packetbuf_addr(a->type))[0],
((uint8_t *)packetbuf_addr(a->type))[1]);
} else {
packetbuf_attr_t val;
val = packetbuf_attr(a->type);
memcpy(&hdrptr[byteptr], &val, len / 8);
PRINTF("%d.%d: value %d\n",
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
val);
}
byteptr += len / 8;
}
return 1; /* Send out packet */
}
示例3: packet_input
/*---------------------------------------------------------------------------*/
static void
packet_input(void)
{
#if NETSTACK_CONF_WITH_IP64
/* If NAT64 is enabled, IPv4 & ARP packets are sent to the IP64 module */
ethernet_header_t *hdr = (ethernet_header_t *)packetbuf_hdrptr();
if (hdr->et_protlen == UIP_HTONS(ETH_PROT_IP) ||
hdr->et_protlen == UIP_HTONS(ETH_PROT_ARP)) {
IP64_INPUT(packetbuf_hdrptr(), packetbuf_totlen());
return;
}
#endif /* NETSTACK_CONF_WITH_IP64 */
if(NETSTACK_0_FRAMER.parse() < 0) {
PRINTF("ieee8023_mac: failed to parse %u\n", (unsigned int)packetbuf_datalen());
#if IEEE8023_MAC_ADDRESS_FILTER
} else if(!linkaddr6_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER),
&linkaddr6_node_addr) &&
!linkaddr6_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER),
&linkaddr6_null)) {
/*\note The framer should have done the multicast address
* translation from 0x33 0x33 0xXX... to the 802.3xx null
*/
PRINTF("ieee8023_mac: not for us\n");
#endif /* IEEE8023_MAC_ADDRESS_FILTER */
} else {
int duplicate = 0;
duplicate = mac_sequence_is_duplicate();
if(duplicate && ETH_SUPPORT_DUPLICATE_DETECTION) {
/* Drop the packet. */
PRINTF("ieee8023_mac: drop duplicate link layer packet %u\n",
packetbuf_attr(PACKETBUF_ATTR_PACKET_ID));
} else {
mac_sequence_register_seqno();
}
#if DEBUG
int i;
uint16_t original_datalen = packetbuf_totlen();
uint8_t *original_dataptr = packetbuf_hdrptr();
PRINTF("PKT[%u]:",original_datalen);
for (i=0; i<original_datalen; i++) {
PRINTF("%02x ",original_dataptr[i]);
}
PRINTF("\n");
#endif
if(!(duplicate && ETH_SUPPORT_DUPLICATE_DETECTION)) {
link_if_in(NETSTACK_8023);
NETSTACK_0_NETWORK.input();
link_if_in(NETSTACK_NULL);
} else {
PRINTF("IEEE8023_MAC: drop duplicate\n");
}
}
}
示例4: handler_802154_send_beacon_request
/* called to send a beacon request */
void
handler_802154_send_beacon_request(void)
{
struct net_buf *mbuf;
frame802154_t params;
uint8_t len;
mbuf = l2_buf_get_reserve(0);
if(!mbuf) {
return;
}
/* init to zeros */
memset(¶ms, 0, sizeof(params));
/* use packetbuf for sending ?? */
packetbuf_clear(mbuf);
/* Build the FCF. */
params.fcf.frame_type = FRAME802154_CMDFRAME;
/* Insert IEEE 802.15.4 (2006) version bits. */
params.fcf.frame_version = FRAME802154_IEEE802154_2006;
params.fcf.src_addr_mode = FRAME802154_NOADDR;
params.fcf.dest_addr_mode = FRAME802154_SHORTADDRMODE;
params.dest_addr[0] = 0xFF;
params.dest_addr[1] = 0xFF;
params.dest_pid = 0xffff;
params.seq = chseqno;
packetbuf_set_datalen(mbuf, 1);
params.payload = packetbuf_dataptr(mbuf);
/* set the type in the payload */
params.payload[0] = FRAME802154_BEACONREQ;
params.payload_len = packetbuf_datalen(mbuf);
len = frame802154_hdrlen(¶ms);
if(packetbuf_hdralloc(mbuf, len)) {
frame802154_create(¶ms, packetbuf_hdrptr(mbuf), len);
if(NETSTACK_RADIO.send(mbuf, packetbuf_hdrptr(mbuf),
packetbuf_totlen(mbuf)) != RADIO_TX_OK) {
l2_buf_unref(mbuf);
return;
}
HANDLER_802154_STAT(handler_802154_stats.beacons_reqs_sent++);
}
}
示例5: output
/*---------------------------------------------------------------------------*/
static int
output(struct channel *c)
{
const struct packetbuf_attrlist *a;
int byteptr, len;
uint8_t *hdrptr;
struct raw_hdr *hdr;
/* Compute the total size of the final header by summing the size of
all attributes that are used on this channel. */
packetbuf_hdralloc(c->hdrsize);
hdrptr = packetbuf_hdrptr();
byteptr = 0;
for(a = c->attrlist; a->type != PACKETBUF_ATTR_NONE; ++a) {
PRINTF("%d.%d: pack_header type %s, len %d\n",
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
packetbuf_attr_strings[a->type], a->len);
len = (a->len & 0xf8) + ((a->len & 7) ? 8: 0);
if(a->type == PACKETBUF_ADDR_SENDER ||
a->type == PACKETBUF_ADDR_RECEIVER ||
a->type == PACKETBUF_ADDR_ESENDER ||
a->type == PACKETBUF_ADDR_ERECEIVER) {
const rimeaddr_t *rimeaddr;
/* memcpy(&hdrptr[byteptr], (uint8_t *)packetbuf_attr_aget(a->type), len / 8);*/
rimeaddr = packetbuf_addr(a->type);
hdrptr[byteptr] = rimeaddr->u8[0];
hdrptr[byteptr + 1] = rimeaddr->u8[1];
PRINTF("%d.%d: address %d.%d\n",
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
((uint8_t *)packetbuf_addr(a->type))[0],
((uint8_t *)packetbuf_addr(a->type))[1]);
} else {
packetbuf_attr_t val;
val = packetbuf_attr(a->type);
memcpy(&hdrptr[byteptr], &val, len / 8);
PRINTF("%d.%d: value %d\n",
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
val);
}
byteptr += len / 8;
}
packetbuf_hdralloc(sizeof(struct raw_hdr));
hdr = (struct raw_hdr *)packetbuf_hdrptr();
hdr->channel = c->channelno;
return 1; /* Send out packet */
}
示例6: PROCESS_THREAD
PROCESS_THREAD(rime_udp_process, ev, data)
{
static uip_ipaddr_t ipaddr;
PROCESS_BEGIN();
broadcast_conn = udp_broadcast_new(HTONS(RIME_UDP_PORT), NULL);
if(broadcast_conn == NULL) {
PRINTF("rime-udp: Failed to allocate a broadcast connection!\n");
}
uip_create_unspecified(&ipaddr);
unicast_conn = udp_new(&ipaddr, HTONS(RIME_UDP_PORT), NULL);
if(unicast_conn == NULL) {
PRINTF("rime-udp: Failed to allocate a unicast connection!\n");
}
udp_bind(unicast_conn, HTONS(RIME_UDP_PORT));
while(1) {
PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event);
if(uip_newdata()) {
packetbuf_clear();
memmove(packetbuf_hdrptr(), uip_appdata, uip_datalen());
PRINTF("rime-udp: received %d bytes\n", uip_datalen());
receiver_callback(&rime_udp_driver);
}
}
PROCESS_END();
}
示例7: rmh_send
/*---------------------------------------------------------------------------*/
int
rmh_send(struct rmh_conn *c, rimeaddr_t *to, uint8_t num_rexmit, uint8_t max_hops)
{
rimeaddr_t *nexthop;
struct data_hdr *hdr;
c->num_rexmit = num_rexmit;
if(c->cb->forward == NULL) {
return 0;
}
nexthop = c->cb->forward(c, &rimeaddr_node_addr, to, NULL, 0);
if(nexthop == NULL) {
PRINTF("rmh_send: no route\n");
return 0;
} else {
PRINTF("rmh_send: sending data\n");
if(packetbuf_hdralloc(sizeof(struct data_hdr))) {
hdr = packetbuf_hdrptr();
rimeaddr_copy(&hdr->dest, to);
rimeaddr_copy(&hdr->originator, &rimeaddr_node_addr);
hdr->hops = 1;
hdr->max_rexmits = num_rexmit;
runicast_send(&c->c, nexthop, num_rexmit);
}
return 1;
}
}
示例8: input_packet
/* -------------------------------------------------------------------- */
static void input_packet(void)
{
static struct packet_s reference_packet;
static uint16_t last_number;
static uint16_t rx_ok;
static uint16_t rx_corrupt;
struct packet_s *p = (struct packet_s *) packetbuf_hdrptr();
if(memcmp(p->filling, reference_packet.filling, sizeof(p->filling))) {
/* corrupt packet detected */
rx_corrupt++;
return;
}
if(last_number > p->number) {
printf("Out of 100 packets %u seen, %u good, %u corrupt\n",
rx_ok + rx_corrupt + (uint16_t)rimestats.badcrc,
rx_ok, rx_corrupt + (uint16_t)rimestats.badcrc);
rx_ok = 0;
rx_corrupt = 0;
rimestats.badcrc = 0;
}
rx_ok++;
last_number = p->number;
}
示例9: send_announcement
static void
send_announcement(void *ptr)
{
struct xmac_hdr *hdr;
int announcement_len;
/* Set up the probe header. */
packetbuf_clear();
hdr = packetbuf_dataptr();
announcement_len = format_announcement((char *)hdr +
sizeof(struct xmac_hdr));
if(announcement_len > 0) {
packetbuf_set_datalen(sizeof(struct xmac_hdr) + announcement_len);
hdr->dispatch = DISPATCH;
hdr->type = TYPE_ANNOUNCEMENT;
packetbuf_set_addr(PACKETBUF_ADDR_SENDER, &rimeaddr_node_addr);
packetbuf_set_addr(PACKETBUF_ADDR_RECEIVER, &rimeaddr_null);
packetbuf_set_attr(PACKETBUF_ATTR_RADIO_TXPOWER, announcement_radio_txpower);
if(NETSTACK_FRAMER.create() >= 0) {
NETSTACK_RADIO.send(packetbuf_hdrptr(), packetbuf_totlen());
}
}
}
示例10: send_packet
/*---------------------------------------------------------------------------*/
static int
send_packet(void)
{
if(radio->send(packetbuf_hdrptr(), packetbuf_totlen()) == RADIO_TX_OK) {
return MAC_TX_OK;
}
return MAC_TX_ERR;
}
示例11: packetbuf_copyto
/*---------------------------------------------------------------------------*/
int
packetbuf_copyto(void *to)
{
if(packetbuf->hdrlen + packetbuf->datalen > PACKETBUF_SIZE) {
return 0;
}
memcpy(to, packetbuf_hdrptr(), packetbuf->hdrlen);
memcpy((uint8_t *)to + packetbuf->hdrlen, packetbuf_dataptr(), packetbuf->datalen);
return packetbuf->hdrlen + packetbuf->datalen;
}
示例12: packetbuf_copyto
/*---------------------------------------------------------------------------*/
int
packetbuf_copyto(void *to)
{
if(hdrlen + buflen > PACKETBUF_SIZE) {
return 0;
}
memcpy(to, packetbuf_hdrptr(), hdrlen);
memcpy((uint8_t *)to + hdrlen, packetbuf_dataptr(), buflen);
return hdrlen + buflen;
}
示例13: send_packet
/*---------------------------------------------------------------------------*/
static void
send_packet(mac_callback_t sent, void *ptr)
{
int ret;
if(NETSTACK_RADIO.send(packetbuf_hdrptr(), packetbuf_totlen()) == RADIO_TX_OK) {
ret = MAC_TX_OK;
} else {
ret = MAC_TX_ERR;
}
mac_call_sent_callback(sent, ptr, ret, 1);
}
示例14: send_packet
/*---------------------------------------------------------------------------*/
static int
send_packet(void)
{
const rimeaddr_t *addr;
addr = packetbuf_addr(PACKETBUF_ADDR_RECEIVER);
PRINTF("rime-udp: Sending %d bytes to %d.%d\n", packetbuf_totlen(),
addr->u8[RIMEADDR_SIZE-2], addr->u8[RIMEADDR_SIZE-1]);
if(rimeaddr_cmp(&rimeaddr_null, addr)) {
uip_udp_packet_send(broadcast_conn,
packetbuf_hdrptr(), packetbuf_totlen());
} else {
uip_ip6addr(&unicast_conn->ripaddr, 0xfe80, 0, 0, 0, 0, 0, 0, 0);
uip_netif_addr_autoconf_set(&unicast_conn->ripaddr, (uip_lladdr_t *)addr);
uip_udp_packet_send(unicast_conn,
packetbuf_hdrptr(), packetbuf_totlen());
uip_create_unspecified(&unicast_conn->ripaddr);
}
return 1;
}
示例15: send_packet
/*---------------------------------------------------------------------------*/
static void
send_packet(mac_callback_t sent_callback, void *ptr)
{
const rimeaddr_t *addr;
addr = packetbuf_addr(PACKETBUF_ADDR_RECEIVER);
PRINTF("rime-udp: Sending %d bytes to %d.%d\n", packetbuf_totlen(),
addr->u8[0], addr->u8[1]);
if(rimeaddr_cmp(&rimeaddr_null, addr)) {
uip_udp_packet_send(broadcast_conn,
packetbuf_hdrptr(), packetbuf_totlen());
mac_call_sent_callback(sent_callback, ptr, MAC_TX_OK, 1);
} else {
uip_ip6addr(&unicast_conn->ripaddr, 0xfe80, 0, 0, 0, 0, 0, 0, 0);
uip_netif_addr_autoconf_set(&unicast_conn->ripaddr, (uip_lladdr_t *)addr);
uip_udp_packet_send(unicast_conn,
packetbuf_hdrptr(), packetbuf_totlen());
uip_create_unspecified(&unicast_conn->ripaddr);
}
return;
}