Exemplo n.º 1
0
void otapi_alpext_proc(alp_tmpl* alp, id_tmpl* user_id) {
/// The function app_invoke() will cause the kernel to call ext_systask() as
/// soon as resources are available.

    // Start the task only if: Caller is ROOT, ALP Call is Protocol-255, Task is idle
    if (    auth_isroot(user_id)    \
        &&  (alp->inrec.id == 0xFF) \
        &&  (APP_TASK.event == 0)   )   {
        
        app_invoke(alp->inrec.cmd);     // Initialize Ping Task on supplied channel
        alp_load_retval(alp, 1);        // Write back 1 (success)
    }
}
Exemplo n.º 2
0
ot_bool sub_proc_api_irregular(alp_tmpl* alp, id_tmpl* user_id, otapi_icmd* cmd, ot_u8 cmd_limit) {
    ot_u16  retval;
    ot_u8   rec_cmd     = alp->inq->getcursor[3];   // record command
    ot_u8   respond     = (rec_cmd & 0x80);
    ot_u8   lookup_cmd  = (rec_cmd & ~0x80) - 1;
    
    alp->inq->getcursor += 4;
    
    /// Do boundary check, and make sure caller is root
    if ( (lookup_cmd >= cmd_limit) || (auth_isroot(user_id) == False) )
        return False;
        
    /// Lookup and process the irregular command, supplying it from input queue
    retval = cmd[lookup_cmd](alp->inq);
    
    /// Write back the twobye retval integer when response is enabled
    return alp_load_retval(alp, retval);
}
Exemplo n.º 3
0
/** ALP Processor Callback for Starting a Ping <BR>
  * ========================================================================<BR>
  * "ALP" is the NDEF-based set of low-level API protocols that OpenTag uses.
  * ALP messages can come-in over any communication method: wire, wireless, 
  * telepathy... anything that can transfer a packet payload.
  *
  * Some ALPs are standardized. Those get handled by OTlib automatically.  ALPs
  * that are not recognized are sent to this function to be handled.  In this
  * demo, we are using a very simple ALP, shown below:
  *
  * ALP Payload Length:         0
  * ALP Protocol ID:            255 (FF)
  * ALP Protocol Commands:      0-127 (00-7F) corresponding to channel to sniff
  *
  * The "user_id" parameter corresponds to the Device ID that sent this ALP.
  * 
  * A quickstart guide to the ALP API is available on the Indigresso Wiki.
  * http://www.indigresso.com/wiki/doku.php?id=opentag:api:quickstart
  */ 
void otapi_alpext_proc(alp_tmpl* alp, id_tmpl* user_id) {
/// The function app_invoke() will cause the kernel to call ext_systask() as
/// soon as resources are available.
    vlFILE*     fp;
    ot_uni16    scratch;
    ot_u8       channel;
    ot_u8       retval;

    // Start the task only if: Caller is ROOT, ALP Call is Protocol-255, Task is idle
    if (    auth_isroot(user_id)    \
        &&  (alp->inrec.id == 0xFF) \
        &&  (APP_TASK.event == 0)   )   {
        
        /// Make sure channel is spec-legal.  If so, set the channel of the 
        /// first (and only) in the channel list to the specified one, and also
        /// set the channel of the hold scan accordingly.  By default, the scan
        /// is updated every second.  The next scan will have these settings.
        retval  = 0;
        channel = alp->inrec.cmd & 0x7F;
        if (((channel & 0xF0) <= 0x20) && ((channel & 0x0F) <= 0x0E)) {
            fp                  = ISF_open_su(ISF_ID(channel_configuration));
            scratch.ushort      = vl_read(fp, 0);
            scratch.ubyte[0]    = channel;
            vl_write(fp, 0, scratch.ushort);
            vl_close(fp);
            
            fp                  = ISF_open_su(ISF_ID(hold_scan_sequence));
            scratch.ushort      = vl_read(fp, 0);
            scratch.ubyte[0]    = channel;
            vl_write(fp, 0, scratch.ushort);
            vl_close(fp);
            
            retval = 1; //success
        }
        
        alp_load_retval(alp, retval);
    }
}
Exemplo n.º 4
0
void otapi_alpext_proc(alp_tmpl* alp, id_tmpl* user_id) {
/// For this example, the directive ID is 0x90 and the commands are 0-3.  You
/// can change these values simply by changing the implementation of this 
/// function.
///
/// Alternatively, instead of using the User Task (extprocess) you can use the
/// sys.loadapi link to an app function: sys.loadapi = &opmode_goto_gateway;
/// This is a simpler approach, but it can be blocked eternally in some setups.
/// Using the User Task guarantees that your app/applet will run at some point
/// in the future, as soon as the kernel is done with high-priority I/O tasks.

    if (alp->inrec.id == 0x90) {
    	ot_u8 task_cmd = (alp->inrec.cmd & 0x7F);

    	// Enable our command processing user task (task 0) to run the command
    	// routine, but only if the cmd is known (0<=cmd<=3)
    	if (task_cmd > 3)   task_cmd = 0;
    	else                app_invoke(++task_cmd);

        // Write back success (non-zero).
        alp_load_retval(alp, task_cmd);
    }
}