void *udp_packet_handler(void *arg) { (void) arg; msg_t m_recv_ip, m_send_ip, m_recv_udp, m_send_udp; socket_internal_t *udp_socket = NULL; msg_init_queue(udp_msg_queue, UDP_PKT_RECV_BUF_SIZE); while (1) { msg_receive(&m_recv_ip); ipv6_hdr_t *ipv6_header = ((ipv6_hdr_t *)m_recv_ip.content.ptr); udp_hdr_t *udp_header = ((udp_hdr_t *)(m_recv_ip.content.ptr + IPV6_HDR_LEN)); uint16_t chksum = ipv6_csum(ipv6_header, (uint8_t*) udp_header, NTOHS(udp_header->length), IPPROTO_UDP); if (chksum == 0xffff) { udp_socket = get_udp_socket(udp_header); if (udp_socket != NULL) { m_send_udp.content.ptr = (char *)ipv6_header; msg_send_receive(&m_send_udp, &m_recv_udp, udp_socket->recv_pid); } else { printf("Dropped UDP Message because no thread ID was found for delivery!\n"); } } else { printf("Wrong checksum (%x)!\n", chksum); } msg_reply(&m_recv_ip, &m_send_ip); } }
static void riot_ccn_transceiver_start(kernel_pid_t _relay_pid) { transceiver_init(TRANSCEIVER); int transceiver_pid = transceiver_start(); DEBUG("transceiver on thread_id %d...\n", transceiver_pid); /* register for transceiver events */ uint8_t reg = transceiver_register(TRANSCEIVER, _relay_pid); if (reg != 1) { DEBUG("transceiver register failed\n"); } /* set channel to CCNL_CHAN */ msg_t mesg; transceiver_command_t tcmd; int32_t c = CCNL_DEFAULT_CHANNEL; tcmd.transceivers = TRANSCEIVER; tcmd.data = &c; mesg.content.ptr = (char *) &tcmd; mesg.type = SET_CHANNEL; msg_send_receive(&mesg, &mesg, transceiver_pid); if (c == -1) { puts("[transceiver] Error setting/getting channel"); } else { printf("[transceiver] Got channel: %" PRIi32 "\n", c); } }
static void *thread1(void *args) { msg_t msg_req, msg_resp; test_struct_t req_struct; int counter = 0; (void)args; req_struct.a = &counter; msg_req.content.ptr = (char *)(&req_struct); while (1) { msg_send_receive(&msg_req, &msg_resp, thread2_pid); if (msg_resp.content.ptr == NULL) { printf("Response is null\n"); } else { printf("*req_struct->a == %d; *resp_struct->a == %d\n", counter, *(((test_struct_t *)msg_resp.content.ptr)->a)); } } return NULL; }
void _cc110x_ng_send_handler(char *pkt) { radio_packet_t p; uint32_t response; uint16_t addr; char *tok; tcmd.transceivers = TRANSCEIVER_CC1100; tcmd.data = &p; tok = strtok(pkt + 7, " "); if(tok) { addr = atoi(tok); tok = strtok(NULL, " "); if(tok) { memset(text_msg, 0, TEXT_SIZE); memcpy(text_msg, tok, strlen(tok)); p.data = (uint8_t *) text_msg; p.length = strlen(text_msg) + 1; p.dst = addr; mesg.type = SND_PKT; mesg.content.ptr = (char *) &tcmd; printf("[cc110x] Sending packet of length %u to %hu: %s\n", p.length, p.dst, (char *) p.data); msg_send_receive(&mesg, &mesg, transceiver_pid); response = mesg.content.value; printf("[cc110x] Packet sent: %" PRIu32 "\n", response); return; } } puts("Usage:\ttxtsnd <ADDR> <MSG>"); }
/** * @brief signals (sends a message to) all registered routing protocols * registered with a matching prefix (usually this should be only one). * The message informs the recipient that no next-hop is available for the * requested destination address. * The receiver MUST copy the content, i.e. the address before reply. * * @param[in] dst the destination address * @param[in] dst_size the destination address size * * @return 0 on a new available entry, * -ENOENT if no suiting entry is provided. */ static int fib_signal_rp(uint8_t *dst, size_t dst_size, uint32_t dst_flags) { msg_t msg, reply; rp_address_msg_t content; content.address = dst; content.address_size = dst_size; content.address_flags = dst_flags; int ret = -ENOENT; msg.type = FIB_MSG_RP_SIGNAL; msg.content.ptr = (void *)&content; for (size_t i = 0; i < FIB_MAX_REGISTERED_RP; ++i) { if (notify_rp[i] != KERNEL_PID_UNDEF) { DEBUG("[fib_signal_rp] send msg@: %p to pid[%d]: %d\n", \ msg.content.ptr, (int)i, (int)notify_rp[i]); /* do only signal a RP if its registered prefix matches */ size_t dst_size_in_bits = dst_size<<3; if (universal_address_compare(prefix_rp[i], dst, &dst_size_in_bits) == 1) { /* the receiver, i.e. the RP, MUST copy the content value. * using the provided pointer after replying this message * will lead to errors */ msg_send_receive(&msg, &reply, notify_rp[i]); DEBUG("[fib_signal_rp] got reply.\n"); } } } return ret; }
void _transceiver_send_handler(int argc, char **argv) { if (transceiver_pid < 0) { puts("Transceiver not initialized"); return; } if (argc != 3) { printf("Usage:\t%s <ADDR> <MSG>\n", argv[0]); return; } radio_packet_t p; transceiver_command_t tcmd; tcmd.transceivers = _TC_TYPE; tcmd.data = &p; char text_msg[TEXT_SIZE]; memset(text_msg, 0, TEXT_SIZE); strcpy(text_msg, argv[2]); p.data = (uint8_t *) text_msg; p.length = strlen(text_msg) + 1; p.dst = atoi(argv[1]); msg_t mesg; mesg.type = SND_PKT; mesg.content.ptr = (char *) &tcmd; printf("[transceiver] Sending packet of length %" PRIu16 " to %" PRIu16 ": %s\n", p.length, p.dst, (char*) p.data); msg_send_receive(&mesg, &mesg, transceiver_pid); int8_t response = mesg.content.value; printf("[transceiver] Packet sent: %" PRIi8 "\n", response); }
/** * @brief signals (sends a message to) all registered RRPs * to start a route discovery for the provided destination. * The receiver MUST copy the content, i.e. the address before reply. * * @param[in] dst the destination address * @param[in] dst_size the destination address size * * @return 0 on a new available entry, * -ENOENT if no suiting entry is provided. */ static int fib_signal_rrp(uint8_t *dst, size_t dst_size, uint32_t dst_flags) { msg_t msg, reply; rrp_address_msg_t content; content.address = dst; content.address_size = dst_size; content.address_flags = dst_flags; int ret = -ENOENT; msg.type = FIB_MSG_RRP_SIGNAL; msg.content.ptr = (void *)&content; for (size_t i = 0; i < FIB_MAX_RRP; ++i) { if (notify_rrp[i] != KERNEL_PID_UNDEF) { DEBUG("[fib_signal_rrp] send msg@: %p to pid[%d]: %d\n", \ msg.content.ptr, (int)i, (int)notify_rrp[i]); /* the receiver, i.e. the RRP, MUST copy the content value. * using the provided pointer after replying this message * will lead to errors */ msg_send_receive(&msg, &reply, notify_rrp[i]); DEBUG("[fib_signal_rrp] got reply."); } } return ret; }
static void *thread1(void *args) { (void)args; msg_t msg_req, msg_resp; int success = 1; msg_resp.content.ptr = NULL; msg_req.content.ptr = &counter1; for (int i = 0; i < TEST_EXECUTION_NUM; i++) { msg_send_receive(&msg_req, &msg_resp, thread2_pid); if ((NULL == msg_resp.content.ptr) || (&counter1 != ((int *) msg_req.content.ptr)) || (counter1 != (*(int *) msg_resp.content.ptr)) || (counter1 != (*(int *) msg_req.content.ptr))) { success = 0; break; } } if (success) { puts("Test successful."); } else { puts("Test failed."); } return NULL; }
/* checked for type safety */ int _transceiver_get_set_pan_handler(int argc, char **argv) { if (transceiver_pid == KERNEL_PID_UNDEF) { puts("Transceiver not initialized"); return 1; } int32_t p; transceiver_command_t tcmd; tcmd.transceivers = _TC_TYPE; tcmd.data = &p; msg_t mesg; mesg.content.ptr = (char*) &tcmd; if (argc > 1) { p = atoi(argv[1]); printf("[transceiver] Trying to set pan %" PRIi32 "\n", p); mesg.type = SET_PAN; } else { mesg.type = GET_PAN; } msg_send_receive(&mesg, &mesg, transceiver_pid); if (p == -1) { puts("[transceiver] Error setting/getting pan"); } else { printf("[transceiver] Got pan: %" PRIi32 "\n", p); } return 0; }
int riot_send_transceiver(uint8_t *buf, uint16_t size, uint16_t to) { DEBUGMSG(1, "this is a RIOT TRANSCEIVER based connection\n"); DEBUGMSG(1, "size=%" PRIu16 " to=%" PRIu16 "\n", size, to); if (size > PAYLOAD_SIZE) { DEBUGMSG(1, "size > PAYLOAD_SIZE: %d > %d\n", size, PAYLOAD_SIZE); return 0; } #if MODULE_AT86RF231 || MODULE_CC2420 || MODULE_MC1322X memset(&p, 0, sizeof(ieee802154_packet_t)); p.frame.payload_len = size; p.frame.fcf.frame_type = IEEE_802154_DATA_FRAME; p.frame.fcf.dest_addr_m = IEEE_802154_SHORT_ADDR_M; p.frame.fcf.src_addr_m = IEEE_802154_SHORT_ADDR_M; p.frame.dest_addr[1] = (to & 0xff); p.frame.dest_addr[0] = (to >> 8); p.frame.payload = buf; p.frame.dest_pan_id = IEEE_802154_DEFAULT_PAN_ID; #else p.length = size; p.dst = (to == RIOT_BROADCAST) ? 0 : to; p.data = buf; #endif tcmd.transceivers = TRANSCEIVER; tcmd.data = &p; mesg.type = SND_PKT; mesg.content.ptr = (char *) &tcmd; msg_send_receive(&mesg, &rep, transceiver_pid); return size; }
/* checked for type safety */ int _transceiver_get_set_address_handler(int argc, char **argv) { msg_t mesg; transceiver_command_t tcmd; radio_address_t a; if (transceiver_pid == KERNEL_PID_UNDEF) { puts("Transceiver not initialized"); return 1; } tcmd.transceivers = _TC_TYPE; tcmd.data = &a; mesg.content.ptr = (char *) &tcmd; if (argc > 1) { a = atoi(argv[1]); printf("[transceiver] trying to set address %" PRIu16 "\n", a); mesg.type = SET_ADDRESS; } else { mesg.type = GET_ADDRESS; } msg_send_receive(&mesg, &mesg, transceiver_pid); printf("[transceiver] got address: %" PRIu16 "\n", a); return 0; }
/* checked for type safety */ int _transceiver_get_set_channel_handler(int argc, char **argv) { msg_t mesg; transceiver_command_t tcmd; int32_t c; if (transceiver_pid == KERNEL_PID_UNDEF) { puts("Transceiver not initialized"); return 1; } tcmd.transceivers = _TC_TYPE; tcmd.data = &c; mesg.content.ptr = (char *) &tcmd; if (argc > 1) { c = atoi(argv[1]); printf("[transceiver] Trying to set channel %" PRIi32 "\n", c); mesg.type = SET_CHANNEL; } else { mesg.type = GET_CHANNEL; } msg_send_receive(&mesg, &mesg, transceiver_pid); if (c == -1) { puts("[transceiver] Error setting/getting channel"); } else { printf("[transceiver] Got channel: %" PRIi32 "\n", c); } return 0; }
/* checked for type safety */ int _transceiver_get_set_long_addr_handler(int argc, char **argv) { msg_t mesg; transceiver_command_t tcmd; transceiver_eui64_t a; if (transceiver_pid == KERNEL_PID_UNDEF) { puts("Transceiver not initialized"); return 1; } tcmd.transceivers = _TC_TYPE; tcmd.data = &a; mesg.content.ptr = (char *) &tcmd; if (argc > 1) { #ifdef MODULE_NET_IF net_if_eui64_t eui64; net_if_hex_to_eui64(&eui64, argv[1]); a = eui64.uint64; #else a = _str_to_eui64(argv[1]); #endif printf("[transceiver] trying to set EUI-64 %016"PRIx64"\n", a); mesg.type = SET_LONG_ADDR; } else { mesg.type = GET_LONG_ADDR; } msg_send_receive(&mesg, &mesg, transceiver_pid); printf("[transceiver] got EUI-64: %016"PRIx64"\n", a); return 0; }
void _transceiver_set_ignore_handler(int argc, char **argv) { if (transceiver_pid < 0) { puts("Transceiver not initialized"); return; } else if (argc != 2) { printf("Usage:\n%s <address>\n", argv[0]); return; } radio_address_t a; transceiver_command_t tcmd; tcmd.transceivers = _TC_TYPE; tcmd.data = &a; msg_t mesg; mesg.content.ptr = (char*) &tcmd; a = atoi(argv[1]); printf("[transceiver] trying to add address %" PRIu16 " to the ignore list \n", a); mesg.type = DBG_IGN; msg_send_receive(&mesg, &mesg, transceiver_pid); int16_t response = a; if (response == -1) { printf("Error: ignore list full\n"); } else { printf("Success (added at index %" PRIi16 ").\n", response); } }
void udp_packet_handler(void) { msg_t m_recv_ip, m_send_ip, m_recv_udp, m_send_udp; ipv6_hdr_t *ipv6_header; udp_hdr_t *udp_header; uint8_t *payload; socket_internal_t *udp_socket = NULL; uint16_t chksum; while (1) { msg_receive(&m_recv_ip); ipv6_header = ((ipv6_hdr_t *)m_recv_ip.content.ptr); udp_header = ((udp_hdr_t *)(m_recv_ip.content.ptr + IPV6_HDR_LEN)); payload = (uint8_t *)(m_recv_ip.content.ptr + IPV6_HDR_LEN + UDP_HDR_LEN); chksum = udp_csum(ipv6_header, udp_header); if (chksum == 0xffff) { udp_socket = get_udp_socket(ipv6_header, udp_header); if (udp_socket != NULL) { m_send_udp.content.ptr = (char *)ipv6_header; msg_send_receive(&m_send_udp, &m_recv_udp, udp_socket->recv_pid); } else { printf("Dropped UDP Message because no thread ID was found for delivery!\n"); } } else { printf("Wrong checksum (%x)!\n", chksum); } msg_reply(&m_recv_ip, &m_send_ip); } }
static int _posix_fileop(kernel_pid_t pid, int op, int flags) { msg_t m; m.type = op; m.content.value = flags; msg_send_receive(&m, &m, pid); return m.content.value; }
void sixlowpan_mac_set_radio_address(uint8_t addr) { int16_t address = (int16_t)addr; tcmd.transceivers = transceiver_type; tcmd.data = &address; mesg.content.ptr = (char *)&tcmd; mesg.type = SET_ADDRESS; msg_send_receive(&mesg, &mesg, transceiver_pid); }
void set_radio_channel(uint8_t channel) { int16_t chan = (int16_t)channel; tcmd.transceivers = transceiver_type; tcmd.data = &chan; mesg.content.ptr = (char *)&tcmd; mesg.type = SET_CHANNEL; msg_send_receive(&mesg, &mesg, transceiver_pid); }
static void _semtech_loramac_call(semtech_loramac_func_t func, void *arg) { semtech_loramac_call_t call; call.func = func; call.arg = arg; msg_t msg, msg_resp; msg.type = MSG_TYPE_LORAMAC_CMD; msg.content.ptr = &call; msg_send_receive(&msg, &msg_resp, semtech_loramac_pid); }
uint8_t sixlowpan_mac_get_radio_address(void) { int16_t address; tcmd.transceivers = transceiver_type; tcmd.data = &address; mesg.content.ptr = (char *)&tcmd; mesg.type = GET_ADDRESS; msg_send_receive(&mesg, &mesg, transceiver_pid); return (uint8_t)address; }
void sixlowpan_mac_send_ieee802154_frame(const ieee_802154_long_t *addr, const uint8_t *payload, uint8_t length, uint8_t mcast) { uint16_t daddr; /* TODO: check if dedicated response struct is necessary */ msg_t transceiver_rsp; r_src_addr = local_address; mesg.type = SND_PKT; mesg.content.ptr = (char *) &tcmd; tcmd.transceivers = transceiver_type; tcmd.data = &p; ieee802154_frame_t frame; memset(&frame, 0, sizeof(frame)); set_ieee802154_fcf_values(&frame, IEEE_802154_LONG_ADDR_M, IEEE_802154_LONG_ADDR_M); set_ieee802154_frame_values(&frame); memcpy(&(frame.dest_addr[0]), &(addr->uint8[0]), 8); memcpy(&(frame.src_addr[0]), &(iface.laddr.uint8[0]), 8); daddr = HTONS(addr->uint16[3]); frame.payload = (uint8_t *)payload; // payload won't be changed so cast is legal. frame.payload_len = length; uint8_t hdrlen = get_802154_hdr_len(&frame); memset(&buf, 0, PAYLOAD_SIZE); init_802154_frame(&frame, (uint8_t *)&buf); memcpy(&buf[hdrlen], frame.payload, frame.payload_len); /* set FCS */ /* RSSI = 0 */ buf[frame.payload_len+hdrlen] = 0; /* FCS Valid = 1 / LQI Correlation Value = 0 */ buf[frame.payload_len+hdrlen+1] = 0x80; DEBUG("IEEE802.15.4 frame - FCF: %02X %02X DPID: %02X SPID: %02X DSN: %02X\n", buf[0], buf[1], frame->dest_pan_id, frame->src_pan_id, frame->seq_nr); p.length = hdrlen + frame.payload_len + IEEE_802154_FCS_LEN; if (mcast == 0) { p.dst = daddr; } else { p.dst = 0; } p.data = buf; msg_send_receive(&mesg, &transceiver_rsp, transceiver_pid); hwtimer_wait(5000); }
void rpl_remove_srh_header(ipv6_hdr_t *ipv6_header, const void *buf, uint8_t nextheader) { ipv6_hdr_t *temp_ipv6_header = ((ipv6_hdr_t *)(&srh_send_buffer)); uint8_t *payload = &srh_send_buffer[IPV6_HDR_LEN]; memcpy(temp_ipv6_header, ipv6_header, sizeof(ipv6_hdr_t)); int msg_length = NTOHS(ipv6_header->length) - sizeof(ipv6_srh_t); temp_ipv6_header->length = HTONS(msg_length); temp_ipv6_header->nextheader = nextheader; memcpy(payload, buf, msg_length); DEBUGF("Source routing header extraction finished.\n"); DEBUGF("Dest is now: %s\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, &temp_ipv6_header->destaddr)); srh_m_send.content.ptr = (char *) srh_send_buffer; DEBUGF("Return from relay: %d\n", msg_send_receive(&srh_m_send, &srh_m_recv, ip_process_pid)); }
static int _posix_fileop_data(kernel_pid_t pid, int op, char *buffer, int nbytes) { struct posix_iop_t r; r.nbytes = nbytes; r.buffer = buffer; msg_t m; m.type = op; m.content.ptr = (char *) &r; msg_send_receive(&m, &m, pid); return r.nbytes; }
int main(void) { printf("Hello world!\n"); msg_t m; int pid = thread_create(second_thread_stack, sizeof(second_thread_stack), PRIORITY_MAIN-1, CREATE_WOUT_YIELD | CREATE_STACKTEST, second_thread, "pong"); m.content.value = 1; while(1) { msg_send_receive(&m, &m, pid); printf("Got msg with content %lu\n", m.content.value); } }
void send_tcp_msg(char *str) { msg_t send_msg, recv_msg; sscanf(str, "send_tcp %s", current_message.tcp_string_msg); // printf("Message: %s\n", current_message.tcp_string_msg); if (strcmp(current_message.tcp_string_msg, "close") == 0) { send_msg.content.value = 0; } else { send_msg.content.value = 1; } msg_send_receive(&send_msg, &recv_msg, tcp_send_pid); }
uint32_t net_if_transceiver_get_set_handler(int if_id, uint16_t op_type, void *data) { DEBUG("net_if_transceiver_get_set_handler: if_id = %d, op_type = %d, data = %p\n", if_id, op_type, data); msg_t msg; transceiver_command_t tcmd; tcmd.transceivers = interfaces[if_id].transceivers; tcmd.data = (char *)data; msg.content.ptr = (char *)&tcmd; msg.type = op_type; msg_send_receive(&msg, &msg, transceiver_pid); return msg.content.value; }
int main(void) { int16_t a; msg_t mesg; transceiver_command_t tcmd; printf("\n\tmain(): initializing transceiver\n"); transceiver_init(TRANSCEIVER_NATIVE); printf("\n\tmain(): starting transceiver\n"); transceiver_start(); #ifndef SENDER printf("\n\tmain(): starting radio thread\n"); kernel_pid_t radio_pid = thread_create( radio_stack_buffer, sizeof(radio_stack_buffer), PRIORITY_MAIN - 2, CREATE_STACKTEST, radio, NULL, "radio"); transceiver_register(TRANSCEIVER_NATIVE, radio_pid); #endif #ifdef SENDER a = SENDER_ADDR; #elif defined ADDR a = ADDR; #else a = DEFAULT_RCV_ADDR; #endif tcmd.transceivers = TRANSCEIVER_NATIVE; tcmd.data = &a; mesg.content.ptr = (char *) &tcmd; mesg.type = SET_ADDRESS; printf("[nativenet] trying to set address %" PRIi16 "\n", a); msg_send_receive(&mesg, &mesg, transceiver_pid); #ifdef SENDER hwtimer_wait(HWTIMER_TICKS(SECOND)); sender(); #else hwtimer_wait(HWTIMER_TICKS(WAIT_TIME * SECOND)); receiving = 0; printf("Missed %u of %u packets after %u seconds\n", missed_cnt, (last_seq - first), WAIT_TIME); #endif return 0; }
void set_address_handler(uint16_t a) { msg_t mesg; transceiver_command_t tcmd; tcmd.transceivers = TRANSCEIVER; tcmd.data = &a; mesg.content.ptr = (char *) &tcmd; printf("trying to set address %" PRIu16 "\n", a); mesg.type = SET_ADDRESS; printf("transceiver_pid=%" PRIkernel_pid"\n", transceiver_pid); msg_send_receive(&mesg, &mesg, transceiver_pid); printf("got address: %" PRIu16 "\n", a); }
void thread1(void) { puts("THREAD 1 start\n"); for (int i = 0; i < 3; ++i) { msg_t msg, reply; msg_receive(&msg); //printf("T1 recv: %" PRIu32 "(i=%d)\n", msg.content.value, i); msg.content.value = i; msg_send_receive(&msg, &reply, p2); //printf("T1 got reply: %" PRIu32 " (i=%d)\n", reply.content.value, i); } puts("THREAD 1 end\n"); }
void thread1(void) { printf("THREAD %u start\n", p1); msg_t msg, reply; memset(&msg, 1, sizeof(msg_t)); /* step 1: send asynchonously */ msg_send(&msg, p_main, 0); /* step 2: send message, turning its status into STATUS_REPLY_BLOCKED */ msg_send_receive(&msg, &reply, p_main); printf("received: %u, %u \n", reply.sender_pid, reply.type); printf("pointer: %s\n", reply.content.ptr); printf("THREAD %u SHOULD BE BLOCKING :(\n", p1); }