bool tl_eq_p(tl_state *tl, tl_value x, tl_value y) { if (tl_type(x) != tl_type(y)) return false; switch (tl_type(x)) { case TL_TT_NIL: return true; case TL_TT_SYMBOL: return strcmp(tl_symbol_ptr(x)->name, tl_symbol_ptr(y)->name) == 0; default: return false; } }
void process_app_pkt(NW_Packet *pkt, int8_t rssi) { int8_t ret; if(DEBUG_NL >= 1) { nrk_kprintf(PSTR("NL: process_app_pkt(): Entered\r\n")); nrk_kprintf(PSTR("NL process_app_pkt(): Received from ")); print_pkt_header(pkt); /* nrk_int_disable(); nrk_led_set(RED_LED); while(1) nrk_kprintf(PSTR("What the hell am I doing here\r\n")); */ } if(tl_type(pkt -> type) == UDP) // the TL protocol is UDP { // unpack the UDP header unpack_TL_UDP_header(&udp_seg, pkt -> data); // copy the application payload into the data section of the UDP segment memcpy(udp_seg.data, pkt -> data + SIZE_TRANSPORT_UDP_HEADER, MAX_APP_PAYLOAD); // check to see if the destination port in the header is associated with any socket if(is_port_associated(udp_seg.destPort) == TRUE) // yes there is { int8_t port_index; enter_cr(bm_sem, 28); enter_cr(tl_sem, 28); if(DEBUG_NL == 2) { ; //nrk_kprintf(PSTR("NL: process_app_pkt(): Received segment = ")); //print_seg(&udp_seg); nrk_kprintf(PSTR("NL: process_app_pkt(): Before inserting into port queue\r\n")); } insert_rx_pq(&udp_seg, pkt -> prio, pkt -> src, rssi); if(DEBUG_NL == 2) { nrk_kprintf(PSTR("NL: process_app_pkt(): After inserting into port queue\r\n")); } port_index = port_to_port_index(udp_seg.destPort); // extract the relevant port element if(port_index == NRK_ERROR) //sanity check for debugging { nrk_int_disable(); nrk_led_set(RED_LED); while(1) nrk_kprintf(PSTR("NL: process_app_pkt(): Bug detected in implementation of port/rbm element array\r\n")); } ret = nrk_event_signal(ports[port_index].data_arrived_signal); // signal 'data arrived' if(ret == NRK_ERROR) { if(nrk_errno_get() == 1) // this means the signal was not created. This is a bug { nrk_int_disable(); nrk_led_set(RED_LED); while(1) nrk_kprintf(PSTR("NL: process_app_pkt(): Bug detected in implementation of port signals\r\n")); } } // end if(ret == NRK_ERROR) } // end if(is_port_associated()) else // if there is no socket associated with this port, simply drop the packet { if(DEBUG_NL == 0) { nrk_kprintf(PSTR("Unassociated port found: ")); printf("%u\n", udp_seg.destPort); } record_unassociated_socket_pkt(pkt); // record this fact } leave_cr(tl_sem, 28); leave_cr(bm_sem, 28); } // end if(tl_layer == UDP) else // as of now UDP is the only supported transport layer, hence print an error { nrk_kprintf(PSTR("NL: process_app_pkt(): Unsupported transport layer type detected = ")); printf("%d\r\n", pkt -> type); } return; }