Esempio n. 1
0
OT_WEAK void dll_scan_applet(m2session* active) {
/// Scanning is a Request-RX operation, so Tc is not important.
    ot_long timeout;
    ot_u8 scan_code;

    dll_set_defaults(active);
    scan_code       = active->extra;
    active->extra   = 0;
    timeout         = otutils_calc_timeout(scan_code);

    if (timeout > 65535) {
        timeout = 65535;
    }

    dll.comm.rx_timeout = (ot_u16)timeout;
    //dll.comm.csmaca_params  = 0;
}
Esempio n. 2
0
ot_u16 otapi_put_dialog_tmpl(ot_u8* status, dialog_tmpl* dialog) {
    if (dialog == NULL) {
        dll.comm.rx_timeout = (m2qp.cmd.ext & 2) ? 0 : 15;
        q_writebyte(&txq, 0);
    }
    else {
        // Calculate actual timeout and write timeout code field
        dll.comm.rx_timeout = otutils_calc_timeout(dialog->timeout);
        dialog->timeout    |= (dialog->channels != 0) ? 0 : 0x80;
        q_writebyte(&txq, dialog->timeout);

        // Write response list
        if (dialog->channels != 0) {
            dll.comm.rx_channels = dialog->channels;
            dll.comm.rx_chanlist = dialog->chanlist;
            q_writestring(&txq, dialog->chanlist, dialog->channels);
        }
    }

    *status = 1;
    return txq.length;
}
Esempio n. 3
0
OT_WEAK ot_u16 otapi_put_dialog_tmpl(ot_u8* status, dialog_tmpl* dialog) {
    if (dialog == NULL) {
        ///@todo "15" is hard-coded timeout.  Have this be a constant
        dll.comm.rx_timeout = (m2qp.cmd.ext & 2) ? 0 : 15;
        q_writebyte(&txq, (ot_u8)dll.comm.rx_timeout);
    }
    else {
        // Place dialog with timeout
        dll.comm.rx_timeout = otutils_calc_timeout(dialog->timeout);
        dialog->timeout    |= (dialog->channels == 0) << 7;     // 0 or 0x80
        q_writebyte(&txq, dialog->timeout);
    
        // Write response list
        if (dialog->channels != 0) {
            dll.comm.rx_channels = dialog->channels;
            dll.comm.rx_chanlist = dialog->chanlist;
            q_writestring(&txq, dialog->chanlist, dialog->channels);
        }
    }

    *status = 1;
    return q_length(&txq);
}
Esempio n. 4
0
ot_int sub_parse_request(m2session* session) {
    ot_int  score   = 0;
    ot_u8   cmd_opcode;
    //ot_u8   nack    = 0;

    /// 1.  Universal Comm Processing                                       <BR>
    ///     - Load CCA type & CSMA disable from command extension           <BR>
    ///     - Load NA2P or A2P dialog type from command code
    m2qp.cmd.code           = q_readbyte(&rxq);
    m2qp.cmd.ext            = (m2qp.cmd.code & 0x80) ? q_readbyte(&rxq) : 0;
    dll.comm.csmaca_params  = m2qp.cmd.ext & (M2_CSMACA_CAMASK | M2_CSMACA_NOCSMA);
    dll.comm.csmaca_params |= m2qp.cmd.code & M2_CSMACA_ARBMASK;
    cmd_opcode              = m2qp.cmd.code & M2OP_MASK;

    /// 2.  All Requests contain the dialog template, so load it.           <BR>
    ///     - [ num resp channels ] [ list of resp channels]                <BR>
    ///     - if number of resp channels is 0, use the current channel
    {
        ot_u8 timeout_code  = q_readbyte(&rxq);
        dll.comm.rx_timeout = otutils_calc_timeout(timeout_code);    // original contention period
        dll.comm.tc         = dll.comm.rx_timeout;  // contention period counter

        if (timeout_code & 0x80) {
            dll.comm.tx_channels    = q_readbyte(&rxq);
            dll.comm.tx_chanlist    = q_markbyte(&rxq, dll.comm.tx_channels);
        }
        else {
            dll.comm.tx_channels    = 1;
            dll.comm.tx_chanlist    = &dll.comm.scratch[0];
            dll.comm.scratch[0]     = session->channel;
        }
    }

    /// 3. Handle Command Queries (filtering)                               <BR>
    /// Multicast and anycast addressed requests include queries
    if (m2np.header.addr_ctl & 0x80) {
        score = sub_process_query(session);
    }

    /// 4. If the query is good (sometimes this is trivial):                <BR>
    ///    - Prepare the response header (same for all responses)           <BR>
    ///    - Run command-specific dialog data processing
    if (score >= 0) {
        q_empty(&txq); // Flush TX Queue

        if (m2qp.cmd.ext & M2CE_NORESP) {
            session->netstate  |= M2_NETFLAG_SCRAP;
        }
        else {
            ot_u8 addressing;
            session->netstate  &= ~M2_NETSTATE_TMASK;
            session->netstate  |= M2_NETSTATE_RESPTX;
            addressing          = ext_get_m2appflags();
            addressing         |= m2np.header.addr_ctl & 0x30;  // make unicast, retain VID & NLS
            m2np_header(session, addressing, 0);                // Create M2QP header
            q_writebyte(&txq, (M2TT_RESPONSE | cmd_opcode));    // Write Cmd code byte
        }

        switch ((cmd_opcode>>1) & 7) {
        case 0:
        case 1:
            break;
        case 2:
            sub_opgroup_shell();
            break;
        case 3:
        case 4:
            sub_opgroup_collection();
            break;
        case 5:
            break;
        case 6:
            sub_opgroup_datastream();
            break;
        case 7:
            sub_ack_datastream();
            break;
        }
    }