⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mfw_sat.c

📁 是一个手机功能的模拟程序
💻 C
📖 第 1 页 / 共 5 页
字号:
| PROJECT : MMI-Framework (8417)        MODULE  : MFW_SAT            |
| STATE   : code                        ROUTINE : satResponse        |
+--------------------------------------------------------------------+

  PURPOSE : setup Terminal Response for SIM

  SPR#2121 - DS - Dynamically allocate memory for Terminal Response.

*/

static void satResponse (U8 res)
{
    U8* trmResponse = NULL;
    
    TRACE_FUNCTION("satResponse()");

    if (satNoResponse)                  /* no response, if ...      */
        return;                         /* ... notified by ACI      */

    /* Allocate memory for Terminal Response buffer */
    trmResponse = (U8*)mfwAlloc(TRM_RSP_LEN);

    if (trmResponse == NULL)
    {
        /* Memory allocation failed */
        TRACE_ERROR("ERROR: Failed to allocate memory for TR buffer");
        return;
    }

    /*SPR#2121 - DS - Set up terminal response with default values */
    lenResponse = sizeof(defResponse);  /* prep. terminal response  */
    memcpy(trmResponse,defResponse,lenResponse);

    /*SPR#2121 - DS - Set up command specific details. defCmdDetails set up in rAT_PercentSATI */
    memcpy(trmResponse, defCmdDetails, CMD_DETAILS_LEN);

    trmResponse[10] = 1;
    trmResponse[11] = res;
    sAT_PercentSATR(CMD_SRC_LCL,sizeof(defResponse),trmResponse);

    /* Deallocate memory used for Terminal Response buffer */
    if (trmResponse != NULL)
    {
        mfwFree(trmResponse, TRM_RSP_LEN);
        trmResponse = NULL;
    }

    return;
}


/*
+--------------------------------------------------------------------+
| PROJECT : MMI-Framework (8417)        MODULE  : MFW_SAT            |
| STATE   : code                        ROUTINE : getTLValue         |
+--------------------------------------------------------------------+

  PURPOSE : check TLV:
            setup curCR, curTag, curLen
            return size of TL part

*/

static U8 getTLValue (U8 *sc)
{
    TRACE_FUNCTION("getTLValue()");

    curCR = *(sc+0) & 0x80;             /* comprehension required ? */
    curTag = *(sc+0) & 0x7f;            /* TLV id                   */
    curLen = *(sc+1);                   /* length of TLV value part */

    if (curLen < 0x80)
        return 2;
    if (curLen == 0x81)
    {
        curLen = *(sc+2);               /* long length              */
        return 3;
    }
    TRACE_ERROR("invalid length coding");
    satResponse(SatResUnknownData);

    return 0;                           /* invalid TLV object       */
}


/*
+--------------------------------------------------------------------+
| PROJECT : MMI-Framework (8417)        MODULE  : MFW_SAT            |
| STATE   : code                        ROUTINE : decTLV             |
+--------------------------------------------------------------------+

  PURPOSE : decode TLV

*/

static U8 decTLV (U8 tagWanted, U8 mandatory, char *id)
{
    U8 *sc = curCmd;
    S16 len = curCmdLen;
    U8 tl, partial = 0;
    static char outstr [64];

    sprintf(outstr,"decTLV(%02x,%d,%s)",tagWanted,mandatory,id);
    TRACE_EVENT(outstr);

    while (len > 0)
    {
        tl = getTLValue(sc);
        if (!tl)
            return 0;
        if (curTag == tagWanted)
        {
            sc += tl;
            curVal = sc;
            curCmd = sc + curLen;
            curCmdLen = len - (tl + curLen);
            partialCompr += partial;
            return 2;
        }
        sprintf(outstr,"no %s TLV",id);
				TRACE_EVENT(outstr);
        if (curCR)
        {
            if (mandatory)
                satResponse(SatResUnknownData);
            return !mandatory;
        }
        sc += tl + curLen;
        len -= tl + curLen;
        partial = 1;
    }
    if(!strcmp(id,"Tone"))
    {
      /*
       *  according to GSM 11.14 if no tone is included play general beep
       */
      *curVal = 10;     /* General Beep */
      return 2;
    }
    if(!strcmp(id,"Duration"))
    {
      /*
       *  according to GSM 11.14 if no duration is included set to a default value
       */
      *(curVal) = 1;  /* Units = sec  */
      *(curVal+1) = 5;  /* play 5 seconds ??*/
      return 2;
    }
    sprintf(outstr,"not found: %s TLV",id);
		TRACE_EVENT(outstr);
    if (mandatory)
        satResponse(SatResNoValues);

    return !mandatory;
}


/*
+--------------------------------------------------------------------+
| PROJECT : MMI-Framework (8417)        MODULE  : MFW_SAT            |
| STATE   : code                        ROUTINE : decByte            |
+--------------------------------------------------------------------+

  PURPOSE : decode TLV: miscelleaneous TLVs (single byte value)

*/

static U8 decByte (U8 *t, U8 tagWanted, U8 mandatory)
{
    U8 res;

    TRACE_FUNCTION("decByte()");

    res = decTLV(tagWanted,mandatory,"byte");

    if (res > 1)
    {
        *t = *curVal;
        return 1;
    }

    return res;
}


/*
+--------------------------------------------------------------------+
| PROJECT : MMI-Framework (8417)        MODULE  : MFW_SAT            |
| STATE   : code                        ROUTINE : decData            |
+--------------------------------------------------------------------+

  PURPOSE : decode TLV: miscelleaneous TLVs (length, data)

*/

static U8 decData (SatData *t, U8 tagWanted, U8 mandatory)
{
    U8 res;

    TRACE_FUNCTION("decData()");

    res = decTLV(tagWanted,mandatory,"data");

    if (res > 1)
    {
        t->len = curLen;                /* data len                 */
        curData -= curLen;
        memcpy(curData,curVal,curLen);  /* data itself              */
        t->data = (U16) (curData - (U8*) t); /* save the offset     */
        return 1;
    }

    return res;
}


/*
+--------------------------------------------------------------------+
| PROJECT : MMI-Framework (8417)        MODULE  : MFW_SAT            |
| STATE   : code                        ROUTINE : decText            |
+--------------------------------------------------------------------+

  PURPOSE : decode TLV: text string

*/

static U8 decText (SatTxt *t, U8 tagWanted, U8 mandatory)
{
    U8 res;

    TRACE_FUNCTION("decText()");

    res = decTLV(tagWanted,mandatory,"text");

    TRACE_EVENT_P1("res %d", res);

    if (res > 1)
    {
        if (curLen == 0x00) /* SPR#2340 - DS - Text len zero */
            t->len = 0;
        else
            t->len = curLen - 1;            /* text len (not dcs)       */
        
        if (t->len)
            t->code = *curVal;          /* data coding scheme       */
        else
            t->code = 0;
        curData -= t->len;
        memcpy(curData,curVal+1,t->len); /* text itself             */
        t->text = (U16) (curData - (U8*) t); /* save the offset     */

        TRACE_EVENT_P2("len %d, code(dcs) %d", t->len, t->code);
        
        return 1;      
    }

    return res;
}


/*
+--------------------------------------------------------------------+
| PROJECT : MMI-Framework (8417)        MODULE  : MFW_SAT            |
| STATE   : code                        ROUTINE : decAddrSS          |
+--------------------------------------------------------------------+

  PURPOSE : decode TLV: address or SS string

*/

static U8 decAddrSS (SatAddress *t, U8 tagWanted, U8 mandatory)
{
    U8 res;

    TRACE_FUNCTION("decAddr-SS()");

    res = decTLV(tagWanted,mandatory,"Addr-SS");

    if (res > 1)                        /* address or ss string     */
    {
        t->len = curLen - 1;            /* number len wo ton/npi    */
        curData -= t->len;
        t->ton = *curVal;               /* type of number, npi      */
        memcpy(curData,curVal+1,t->len); /* number itself           */
        t->number = (U16) (curData - (U8*) t); /* offset            */
        return 1;
    }

    return res;
}


/*
+--------------------------------------------------------------------+
| PROJECT : MMI-Framework (8417)        MODULE  : MFW_SAT            |
| STATE   : code                        ROUTINE : decAlpha           |
+--------------------------------------------------------------------+

  PURPOSE : decode TLV: alpha identifier

*/

static U8 decAlpha (SatTxt *t, U8 mandatory)
{
    U8 res;

    TRACE_FUNCTION("decAlpha()");

    res = decTLV(0x05,mandatory,"Alpha");

    /* SPR#2340 - DS - Added check of val returned from decTLV */
    if (res > 1)
    {
        t->len = curLen;                /* text len                 */
        if (t->len)
            t->code = 0x04;             /* data coding scheme       */
        else
            t->code = 0;
        curData -= t->len;
        memcpy(curData,curVal,t->len);  /* text itself              */
        t->text = (U16) (curData - (U8*) t); /* save the offset     */
        return 1;
    }
    else
    {
        /* Alpha tag not present */
        t->len = 0x00;
        t->code = 0x00;
        t->text = 0x00;
    }

    return res;
}



/*
+--------------------------------------------------------------------+
| PROJECT : MMI-Framework (8417)        MODULE  : MFW_SAT            |
| STATE   : code                        ROUTINE : decSMS             |
+--------------------------------------------------------------------+

  PURPOSE : decode TLV: SMS TPDU

*/

static U8 decSMS (SatSmsPdu *t, U8 mandatory)
{
    U8 res;

    TRACE_FUNCTION("decSMS()");

    res = decTLV(0x0B,mandatory,"SMS TPDU");

    if (res > 1)
    {
        t->len = curLen;                /* SMS len                  */
        curData -= t->len;
        memcpy(curData,curVal,t->len);  /* SMS itself               */
        t->data = (U16) (curData - (U8*) t); /* save the offset     */
        return 1;
    }

    return res;
}


/*
+--------------------------------------------------------------------+
| PROJECT : MMI-Framework (8417)        MODULE  : MFW_SAT            |
| STATE   : code                        ROUTINE : decItem            |
+--------------------------------------------------------------------+

  PURPOSE : decode TLV: item

*/

static U8 decItem (SatItem *t, U8 mandatory)
{
    U8 res;

    TRACE_FUNCTION("decItem()");

    res = decTLV(0x0F,mandatory,"Item");

    if (res > 1)
    {
        if (!curLen)                    /* no item: remove menu     */
        {
            t->id = 0;                  /* no id                    */
            t->len = 0;                 /* no length                */
        }
        else
        {
            t->id = *curVal;
            t->len = curLen - 1;        /* without item id          */
        }
        t->action = 0;                  /* filled in later          */
        t->icon = 0;                    /* filled in later          */
        curData -= t->len;
        memcpy(curData,curVal+1,t->len); /* item data               */
        t->text = (U16) (curData - (U8*) t); /* save the offset     */
        return 1;
    }

    return res;
}


/*
+--------------------------------------------------------------------+
| PROJECT : MMI-Framework (8417)        MODULE  : MFW_SAT            |
| STATE   : code                        ROUTINE : decNextAction      |
+--------------------------------------------------------------------+

  PURPOSE : decode TLV: next action

*/

static U8 decNextAction (SatItem *t, U8 nItems, U8 mandatory)
{
    U8 res;

    TRACE_FUNCTION("decNextAction()");

    res = decTLV(0x18,mandatory,"Next Action");

    if (res > 1)
    {
        if (nItems > curLen)
            nItems = curLen;
        while (nItems--)
        {
            t->action = *curVal++;      /* next action identifier   */
            t++;
        }
        return 1;
    }

    return res;
}


/*
+--------------------------------------------------------------------+
| PROJECT : MMI-Framework (8417)        MODULE  : MFW_SAT            |
| STATE   : code                        ROUTINE : decItemIcons       |
+--------------------------------------------------------------------+

  PURPOSE : decode TLV: icon identifier list

*/

static U8 decItemIcons (SatMenu *m, SatItem *t, U8 nItems, U8 mandatory)
{
    U8 res;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -