OT_WEAK void dll_activate(void) { /// Do session creation /// 1. Block DLL Idle-time tasks: they get reactivated by dll_idle() /// 2. Get top session /// 3. Associated Applet can construct packet, or control parameters /// 4. Session is terminated if "SCRAP" bit is 1 /// 5. Session is processed otherwise m2session* s_active; ot_app s_applet; dll_block_idletasks(); //dll.idle_state = sub_default_idle(); s_active = session_top(); s_applet = (s_active->applet == NULL) ? \ &dll_response_applet : s_active->applet; s_active->applet = NULL; s_applet(s_active); if (s_active->netstate & M2_NETSTATE_SCRAP) { session_pop(); dll_idle(); } else if (s_active->netstate & M2_NETSTATE_RX) { dll_init_rx(s_active); } else { dll_init_tx(s_active->netstate & (M2_NETFLAG_BG | M2_NETFLAG_STREAM)); } }
void dll_processing(void) { /// This is the task for processing a DASH7 packet which has been received. /// If the packet is a valid request, this task will put the DLL into HOLD. /// If the listen bit is high, additionally, this task will clone the session /// to be re-visited at a later time. m2session* active; ot_int proc_score; sys.task_RFA.event = 0; // Only run processing once active = session_top(); active->counter = 0; proc_score = network_route_ff(active); /// Response is prepared already, so setup holdstate and flow control. /// proc_score is always negative after parsing a response. if (proc_score >= 0) { sub_fceval(proc_score); sys.task_HSS.cursor = 0; dll.counter = dll.netconf.hold_limit; dll.idle_state = M2_DLLIDLE_HOLD; /// If the Listen flag is high, clone the session to a time in the /// future, when it will listen again. /// <LI> dll.comm.tc has just been assigned by the request. It is the /// response contention period (Tc). </LI> /// <LI> This device should listen again after Tc ends, so the session /// is cloned & scheduled for Tc </LI> /// <LI> The current session is popped after response, or on next kernel /// loop (immediately) if no response </LI> if (active->flags & M2_FLAG_LISTEN) { network_cont_session(active->applet, M2_NETSTATE_REQRX, 0); } } /// Bad score, plus session indicates no listening or sending response. /// Scrap the session. else if ((active->netstate & M2_NETSTATE_RESP) == 0) { goto dll_processing_SCRAP; } /// A protocol parser has scrapped the session, or possibly the above /// condition branched here directly. if (active->netstate & M2_NETSTATE_SCRAP) { dll_processing_SCRAP: session_pop(); dll_idle(); } }
OT_WEAK ot_u16 otapi_open_request(addr_type addr, routing_tmpl* routing) { /// Set the header if the session is valid. Also conditionally write the header /// depending on the address type (a parameter). if (session_notempty()) { m2session* s_active; s_active = session_top(); // Set the dll parameters to a safe setting; can be changed later dll_set_defaults(s_active); // Unicast/Anycast support routing, so copy the supplied template if ((addr & M2QUERY_GLOBAL) == 0) { platform_memcpy((ot_u8*)&m2np.rt, (ot_u8*)routing, sizeof(routing_tmpl)); } // Load the header m2np_header(s_active, (ot_u8)addr, M2FI_FRDIALOG); return 1; } return 0; }