int sixlowpan_mac_send_data(int if_id, const void *dest, uint8_t dest_len, const void *payload, uint8_t payload_len, uint8_t mcast) { if (mcast) { return net_if_send_packet_broadcast(IEEE_802154_SHORT_ADDR_M, payload, payload_len); } else { if (dest_len == 8) { return net_if_send_packet_long(if_id, (net_if_eui64_t *) dest, payload, (size_t)payload_len); } else if (dest_len == 2) { return net_if_send_packet(if_id, NTOHS(*((uint16_t *)dest)), payload, (size_t)payload_len); } } return -1; }
int net_if_send_packet_broadcast(net_if_trans_addr_m_t preferred_dest_mode, const void *payload, size_t payload_len) { int if_id = -1; int res = 0, res_prev = 0; while ((if_id = net_if_iter_interfaces(if_id)) >= 0) { if (interfaces[if_id].transceivers & (TRANSCEIVER_CC1100 | TRANSCEIVER_NATIVE)) { res = net_if_send_packet(if_id, 0, payload, payload_len); } else if (preferred_dest_mode == NET_IF_TRANS_ADDR_M_SHORT) { res = net_if_send_packet(if_id, IEEE_802154_SHORT_MCAST_ADDR, payload, payload_len); } else { net_if_eui64_t mcast_addr = IEEE_802154_LONG_MCAST_ADDR; res = net_if_send_packet_long(if_id, &mcast_addr, payload, payload_len); } if (res_prev != 0) { if (res != res_prev) { return -1; } } else { if (res == 0) { break; } } res_prev = res; } return res; }