亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? sim.c

?? 是一個手機功能的模擬程序
?? C
?? 第 1 頁 / 共 5 頁
字號:
/*
 * SIM.C
 *
 * Pole Star SIM
 *                 
 * Target : ARM
 *
 *
 * SIM card driver. This module contents all functions 
 * included in specifications GSM 11.11 V4.10
 *
 *
 * Copyright (c) Texas Instruments 1995-1997
 *
 */
                                        
#define SIM_C   1

#ifndef _WINDOWS
	#include "chipset.cfg"
#endif

#include "sys_types.h"

#include "mem.h"

//#include "assert.h"
#include "iq.h"
#include "sim.h"
#include <string.h>
#include "armio.h"
#include "ind_os.h"
#include "abb.h"                     //controls level shifter of ABB


//current voltage mode 3V or 5V, or 1.8V
SYS_UWORD8            CurrentVolt;



#ifdef SIM_DEBUG_TRACE

#ifdef SIM_RETRY
/* one byte more to trace the number of retry for each functions */
#define SIM_DBG_NULL 5
#else
/* size of buffer tracing the reception of NULL byte */
#define SIM_DBG_NULL 4
#endif

/* working buffer for NULL BYTE and number of RETRY */
SYS_UWORD8  SIM_dbg_null[SIM_DBG_NULL];
/* size of buffer tracing the chronology of calls */
#define SIM_DBG_CMD 7500
/* working buffer for chronology calls */
SYS_UWORD8  SIM_dbg_cmd[SIM_DBG_CMD];
/* index for positionning in working buffer for chronology calls */
SYS_UWORD16  SIM_dbg_cmd_cmpt;       
/* working variable to calculate the TDMA ecart */
SYS_UWORD16 SIM_dbg_tdma_diff;
/* working variable to store the maximum TDMA frame between two characters */
SYS_UWORD16 SIM_dbg_max_interchardelay;
/* working variable used in each L2/L3 access function */
SYS_UWORD8 SIM_dbg_tmp[10];
/* internal function due to factorization of use of traces */
void SIM_dbg_write_trace(SYS_UWORD8 *ptr, SYS_UWORD16 len);

#endif

#ifdef SIM_RETRY
/* number of retry */
#define	NUM_SIM_RETRIES	10
/* Add variables to support sim retry */
SYS_UWORD8 SimRetries;
#endif






/*
 * Low level routines  : mapped to hardware
 *    SIM_WriteBuffer
 *    SIM_Command
 *    SIM_Reset
 *    
 */



/*
 * SIM_WriteBuffer
 *
 * Write n bytes to SIM card in interrupt mode:
 *   return the line, write first byte and let interrupt handler do the rest
 * return the line, write first byte and let interrupt handler do the rest
 *
 * Parameters : 
 *   SIM_PORT *p : buffer for received chars
 *   offset      : starting point for reading data.
 *   n           : number of chars to read.
 */
void SIM_WriteBuffer(SIM_PORT *p, SYS_UWORD16 offset, SYS_UWORD16 n)
{
   unsigned volatile i;

   // Set write direction
   p->conf1 |= SIM_CONF1_TXRX;
   p->c->conf1 = p->conf1;

   p->SWcount  = 0;
   p->rx_index = 0;
   p->expected_data = 0;

   p->xOut = p->xbuf + offset;
   p->xIn  = p->xbuf + offset + n;

   if ((p->xIn - p->xOut) == 1)        //if only one char is transmitted
   {                                   //need to wait a minimum of 1 ETU
        ind_os_sleep (1);                  //for IO line to stay in TX mode
   } 
   // Write first byte 
   p->c->tx = *(p->xOut);              // transmit

   if ((p->xIn - p->xOut) == 1)        //if only one char to transmit
   {                                   // return the direction to rx
        p->conf1 &= ~SIM_CONF1_TXRX;   //to be able to receive ACK char
        p->c->conf1 = p->conf1;        

   }
}

/*
 * SIM_Result
 *    
 * Parameters : SIM port, buffer for received chars, pointer to receive size
 * 
 * Return the result code (SW1/SW2) at the end of the string
 */
SYS_UWORD16 SIM_Result(SIM_PORT *p, SYS_UWORD8 *rP, SYS_UWORD8 *lenP, SYS_UWORD8 offset)
{
   SYS_UWORD8 sw1, sw2, len;
   SYS_UWORD8 verdict;
   
   // Check if all characters were transmitted
   if (p->xIn - 1 != p->xOut)
      return (SIM_ERR_XMIT);
   
   len = p->rx_index;
   *lenP = len - offset;

   if (p->expected_data == 256)
   {
       verdict = SIM_Memcpy(rP, ((p->rbuf) + offset), 255 - offset);
       if (verdict != 0)
       { 
           return (verdict);
       }
   }
   else if ((len != 0) && (len >= offset))
   {
       verdict = SIM_Memcpy(rP, ((p->rbuf) + offset), len - 1 - offset);
       if (verdict != 0)
       {
           return (verdict);
       }
   }
   
   // change to remove SW1 and SW2 bytes from the receive buffer of data 
   sw1 = p->rSW12[0];
   sw2 = p->rSW12[1];

   return((sw1 << 8) | sw2);
}





/*
 * SIM_Command_base
 *
 * Perform a command with the SIM T=0 protocol
 *
 * Arguments : pointer to SIM port structure
 *             number of characters above 5
 *             expected command time in TDMA
 *
 * Returns an error code :
 *             SIM_ERR_READ : no answer from the card to a command
 *             SIM_ERR_LEN  : the answer is not corresponding to a
 *                            correct answer of T=0 protocol
 * 06/11/2002	JYT
 *		Modified to be base command function. New SIM_Command() created to call it 
 * 		with wrapper. Created to manage retries on Internals errors of the driver.
 */

SYS_UWORD16 SIM_Command_Base(SIM_PORT *p, SYS_UWORD16 n, SYS_UWORD8 *dP, SYS_UWORD8 *lP)
{
    SYS_UWORD16  res;
    SYS_UWORD8    err;
    SYS_UWORD8    ins;
    SYS_UWORD8    nack;
    SYS_UWORD8    nack1;
    SYS_UWORD16  offset;

    if (SIM_sleep_status == SIM_SLEEP_DESACT)
    {   //freeze the timer
        status_os_sim = NU_Control_Timer (&SIM_timer,  NU_DISABLE_TIMER);
    }
    else if (SIM_sleep_status == SIM_SLEEP_ACT)
    {   //get out sleep mode
        status_os_sim = NU_Control_Timer (&SIM_timer,  NU_DISABLE_TIMER);
        SIM_SleepMode_Out (p);   //get up SIM card of sleep mode before executing the command
    }

    SIM_WriteBuffer(p, 0, 5);

    //adaptative driver

    if (n > 0)          //need to send data to the card, TX mode
    {
        offset = 0;
        // protocol T=0 returns a acknowledge char which is
        //     ins or (ins+1)   : transmit the rest of the command in one time
        //     ~ins or ~(ins+1) : transmit the rest of the command char by char
        ins   = p->xbuf[1] & p->hw_mask;
        nack  = (~p->xbuf[1]) & p->hw_mask;;

        p->moderx = 6;  //mode of wait for ACK char

NEXT_CHAR_PROC:

        if (err = SIM_Waitforchars(p, p->etu9600))
        {
            if ((SIM_sleep_status == SIM_SLEEP_DESACT) || (SIM_sleep_status == SIM_SLEEP_ACT))
            {   //enable to count 2.5s before entering in sleep mode
                status_os_sim = NU_Reset_Timer (&SIM_timer, SIM_SleepMode_In,
                                                SIM_SLEEP_WAITING_TIME,
                                                0, NU_ENABLE_TIMER);
            }
            return (err);
        }

        if (p->moderx == 5)     //return SW1/SW2
        {
            res = SIM_Result(p, dP, lP, 0);

            if ((SIM_sleep_status == SIM_SLEEP_DESACT) || (SIM_sleep_status == SIM_SLEEP_ACT))
            {   //enable to count 2.5s before entering in sleep mode
                status_os_sim = NU_Reset_Timer (&SIM_timer, SIM_SleepMode_In,
                                                SIM_SLEEP_WAITING_TIME,
                                                0, NU_ENABLE_TIMER);
            }

            return(res);
        }
        else if ((p->ack & p->hw_mask) == ins)
        {
        // Write the rest of the command if needed
        // if more than 5 characters, the ack character will disappear

            SIM_WriteBuffer(p, 5 + offset, n - offset);
        }
        // special transmission mode if ACK = ~INS or ~(INS + 1).
        // refer to ISO/CEI 7816-3 [8.2.2]
        // need to send char by char
        else if ((p->ack & p->hw_mask) == nack)
        {
            SIM_WriteBuffer(p, 5 + offset, 1);
            offset++;
            goto NEXT_CHAR_PROC;
        }

        p->moderx = 5;
        if (err = SIM_Waitforchars (p, p->etu9600))  //wait SW1 / SW2
        {
            if ((SIM_sleep_status == SIM_SLEEP_DESACT) || (SIM_sleep_status == SIM_SLEEP_ACT))
            {   //enable to count 2.5s before entering in sleep mode
                status_os_sim = NU_Reset_Timer (&SIM_timer, SIM_SleepMode_In,
                                                SIM_SLEEP_WAITING_TIME,
                                                0, NU_ENABLE_TIMER);
            }
            return (err);
        }

    }
    else                //receive mode
    {
        if (err = SIM_WaitReception(p))  //wait for next procedure character
        {
            if ((SIM_sleep_status == SIM_SLEEP_DESACT) || (SIM_sleep_status == SIM_SLEEP_ACT))
            {   //enable to count 2.5s before entering in sleep mode
                status_os_sim = NU_Reset_Timer (&SIM_timer, SIM_SleepMode_In,
                                                SIM_SLEEP_WAITING_TIME,
                                                0, NU_ENABLE_TIMER);
            }
            return (err);
        }
    }

    res = SIM_Result(p, dP, lP, 0);

            if ((SIM_sleep_status == SIM_SLEEP_DESACT) || (SIM_sleep_status == SIM_SLEEP_ACT))
    {   //enable to count 2.5s before entering in sleep mode
        status_os_sim = NU_Reset_Timer (&SIM_timer, SIM_SleepMode_In,
                                                SIM_SLEEP_WAITING_TIME,
                                                0, NU_ENABLE_TIMER);
    }

    return(res);
}


/* Main function to manage the retry mechanism */
SYS_UWORD16 SIM_Command(SIM_PORT *p, SYS_UWORD16 n, SYS_UWORD8 *dP, SYS_UWORD8 *lP) {   
	int res;

#ifdef SIM_DEBUG_TRACE
	memset(SIM_dbg_null, 0x00, SIM_DBG_NULL);
	SIM_dbg_tdma_diff = 0;
#endif

	// Issue initial SIM_Command() call
    res = SIM_Command_Base(p, n, dP, lP);
    /* Change from to 10 to 15 for specific SIM card (Racal) */

#ifdef SIM_RETRY
    // While there is an error then retry NUM_SIM_RETRIES times
	while ((res & 0xFF00) == 0)	{	// Reissue command
		p->errorSIM = 0;
		if(++SimRetries > NUM_SIM_RETRIES) {	// return special retry failure
		   	res = SIM_ERR_RETRY_FAILURE;
		   	break;
		}
	    res = SIM_Command_Base(p, n, dP, lP);
	}

#ifdef SIM_DEBUG_TRACE
	SIM_dbg_null[SIM_DBG_NULL-1] = SimRetries;
#endif

	SimRetries = 0;
#endif

    return(res);
}





                                
/*
 * SIM_ByteReverse
 *
 * Reverse a byte, both up/down (1 <> 0) and left/right (0001 <> 1000)
 * 
 */
SYS_UWORD8 SIM_ByteReverse(SYS_UWORD8 b)
{
    SYS_UWORD8 bh, bl;
    int i;
    const SYS_UWORD8 Reverse[] = {0x0, 0x8, 0x4, 0xC, 0x2, 0xA, 0x6, 0xE, 
                                    0x1, 0x9, 0x5, 0xD, 0x3, 0xB, 0x7, 0xF };

    // Up/Down
    b = ~ b;

    // left / right (by nibble)
    bh = (b >> 4) & 0xF;
    bl = b & 0xF;
      
    b = (Reverse[bl]) << 4 | Reverse[bh];
    return(b);
   
}

/*
 * SIM_TxParityErrors
 *
 * return number of transmit parity errors occured since the last reset
 * of the SIM card
 *
 */
SYS_UWORD16 SIM_TxParityErrors(void)
{
    SIM_PORT *p;

    p= &(Sim[0]);

    return(p->txParityErr);
}


/*
 * SIM_Reset
 *
 * Reset SIM card 
 * Call-back SIM insert if successful
 * or SIM remove otherwise
 *
 * Returns 0 for success, or
 *         SIM_ERR_NOCARD : no card
 *         SIM_ERR_NATR   : no answer to reset
 *         SIM_ERR_NOINT  : no 
 *         SIM_ERR_READ   : unknown data return by the card
 *         SIM_ERR_CARDREJECT : card not accepted
 *
 * 29/01/02, JYT, adding of low voltage managment for IOTA device
 */ 
SYS_UWORD16 SIM_Reset(SIM_CARD *cP)
{
    SIM_PORT        *p;
    unsigned int    ATR_Attempt;
    SYS_UWORD8      BackValue;
    SYS_UWORD8      Result_ATR;

#ifdef SIM_DEBUG_TRACE
	memset(SIM_dbg_null, 0x00, SIM_DBG_NULL);
	SIM_dbg_cmd_cmpt = 0;
	memset(SIM_dbg_cmd, 0x00, SIM_DBG_CMD);
#endif

    // Initialize pointers 
    p = &(Sim[0]);

// begin of JYT modifications
    if ( (BackValue = SIM_StartVolt()) != SIM_OK)
       return((SYS_UWORD16)BackValue);
// end of JYT modifications

    p->etu9600    = 1075; // old = 239, increase of 450%
    p->etu400     = 20;
    p->hw_mask    = MASK_INS;

    ATR_Attempt      = 1;

COLD_RESET:

    p->SWcount       = 0;
    p->Freq_Algo     = 0;
    p->PTS_Try       = 0;            //use to calculate how many PTS try were already done
    
    // Initialize pointers 
    p->xIn   = p->xOut = p->xbuf;
    p->rx_index        = 0;
    p->errorSIM        = 0;
    p->moderx          = 0;
    p->null_received   = 0;

    BackValue = SIM_ManualStart(p);
    if (BackValue != 0)
        return ((SYS_UWORD16)BackValue);
    
      
    p->c->conf1 = p->conf1 &= ~SIM_CONF1_BYPASS;      //switch to automatic mode             

//#else //SW_WRK_AROUND_H_S == 0 // Automatic procedure -> fails with test 27.11.2.1
//
//                                  // Mask all interrupts
//    p->c->maskit = SIM_MASK_NATR | SIM_MASK_WT | SIM_MASK_OV | 
//                   SIM_MASK_TX | SIM_MASK_RX | SIM_MASK_CD;
//
//
//   IQ_Unmask (IQ_SIM);           // Unmask interrupt controller
//
//
//    p->c->cmd = (p->c->cmd & MASK_CMD) | SIM_CMD_STOP;
//    ind_os_sleep(1);
//                      
//    p->c->cmd = (p->c->cmd & MASK_CMD) | SIM_CMD_SWRST;    // Set START bit and wait a while
//    ind_os_sleep(1);
//                                  // Unmask all sources of interrupts except WT, OV, and NATR
//    p->c->maskit = SIM_MASK_OV | SIM_MASK_WT | SIM_MASK_NATR;

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
麻豆精品在线看| 成人动漫一区二区三区| 国产91精品入口| 欧美高清视频不卡网| 久久久www免费人成精品| 亚洲精品国产视频| 国产成人免费视频精品含羞草妖精 | 欧美一区二区三区在线看| 国产清纯白嫩初高生在线观看91| 亚洲一区在线播放| 99v久久综合狠狠综合久久| 日韩精品最新网址| 亚洲成人你懂的| www.一区二区| 中文欧美字幕免费| 精品一区二区三区日韩| 欧美日韩一区二区欧美激情| 国产精品日产欧美久久久久| 精品亚洲成a人| 欧美一级二级在线观看| 亚洲永久免费av| 日本久久一区二区| 亚洲免费电影在线| 色综合天天在线| 一区二区三区四区激情| 成人免费看的视频| 中文字幕亚洲电影| 福利电影一区二区三区| 精品国一区二区三区| 一区二区三区欧美久久| 91同城在线观看| 中文字幕在线免费不卡| 99久久久免费精品国产一区二区| 26uuu久久综合| 国产高清久久久久| 国产网站一区二区| 国产**成人网毛片九色 | www.日韩在线| 日韩一区日韩二区| 日本高清不卡aⅴ免费网站| 综合自拍亚洲综合图不卡区| 盗摄精品av一区二区三区| 国产拍揄自揄精品视频麻豆| 国产精品白丝av| 国产精品三级av| 97久久精品人人做人人爽| 亚洲色图欧美在线| 在线一区二区视频| 日日骚欧美日韩| 亚洲精品一区二区三区影院| 国产一区二区久久| 一区视频在线播放| 欧美伊人久久久久久久久影院| 亚洲国产精品一区二区久久恐怖片 | 国产精品 欧美精品| 国产人成亚洲第一网站在线播放| 国产91精品一区二区麻豆网站| 国产欧美精品一区二区色综合 | 精品国产91久久久久久久妲己| 极品瑜伽女神91| 国产精品欧美久久久久一区二区| 白白色亚洲国产精品| 一区二区三区免费观看| 91精品国产综合久久精品性色 | 久久噜噜亚洲综合| 色综合久久久久久久久久久| 无吗不卡中文字幕| 国产欧美日韩激情| 欧美裸体bbwbbwbbw| 国产乱码字幕精品高清av | 中文字幕不卡在线观看| 日韩欧美在线不卡| 亚洲一区二区偷拍精品| 中文字幕在线一区| 国产成人精品免费网站| 一区二区三区在线视频免费| 日韩欧美中文字幕一区| 99久久亚洲一区二区三区青草| 亚洲国产精品久久人人爱蜜臀| 亚洲国产精品av| 91精品婷婷国产综合久久性色 | 亚洲与欧洲av电影| 久久亚洲捆绑美女| 91国偷自产一区二区开放时间| 蜜桃一区二区三区在线| 亚洲女人****多毛耸耸8| 2020国产成人综合网| 欧美视频完全免费看| 高清在线成人网| 免费看欧美美女黄的网站| 自拍偷在线精品自拍偷无码专区 | 亚洲精品菠萝久久久久久久| wwwwxxxxx欧美| 欧美人与z0zoxxxx视频| 成人性色生活片免费看爆迷你毛片| 亚洲成人自拍网| 综合自拍亚洲综合图不卡区| 国产亚洲一二三区| 精品久久国产字幕高潮| 欧美色图激情小说| 色欧美88888久久久久久影院| 国产一区二区在线影院| 奇米影视一区二区三区小说| 亚洲精品国产视频| 亚洲色大成网站www久久九九| 久久久精品免费网站| 精品国产一区二区三区av性色 | 久久精品噜噜噜成人av农村| 亚洲香蕉伊在人在线观| 一个色在线综合| 亚洲免费观看高清完整版在线 | 国产91丝袜在线播放0| 久久精品国产99久久6| 日本免费在线视频不卡一不卡二| 六月婷婷色综合| 久久国产成人午夜av影院| 看片网站欧美日韩| 国产在线精品国自产拍免费| 国内精品久久久久影院色| 寂寞少妇一区二区三区| 韩国三级在线一区| 国产一区二区三区视频在线播放| 另类成人小视频在线| 久久99九九99精品| 韩国理伦片一区二区三区在线播放| 六月婷婷色综合| 国产一区啦啦啦在线观看| 久久66热re国产| 成人动漫在线一区| 欧美性生交片4| 欧美一区二区三区在线看| 欧美v亚洲v综合ⅴ国产v| 2023国产精品视频| 国产精品麻豆欧美日韩ww| 综合久久久久综合| 伊人夜夜躁av伊人久久| 日韩在线一二三区| 国产在线精品免费av| 97se亚洲国产综合自在线| 欧美乱妇23p| 精品精品国产高清a毛片牛牛 | 日本午夜精品一区二区三区电影| 久久成人综合网| 成人午夜在线免费| 在线观看日韩毛片| 精品国产乱码久久久久久1区2区| 国产亚洲欧美日韩日本| 亚洲免费观看高清| 黄页网站大全一区二区| 99久久精品国产麻豆演员表| 精品视频一区二区三区免费| 欧美一区二区二区| 国产精品拍天天在线| 日韩中文字幕区一区有砖一区 | 色屁屁一区二区| 欧美成人激情免费网| 国产精品久久久爽爽爽麻豆色哟哟| 亚洲日本中文字幕区| 蜜臀av亚洲一区中文字幕| 成人国产一区二区三区精品| 欧美日韩情趣电影| 欧美韩日一区二区三区| 日韩不卡一区二区| 91色九色蝌蚪| 久久午夜羞羞影院免费观看| 亚洲日穴在线视频| 久久99精品久久只有精品| 不卡的av在线| 欧美精品一区二区精品网| 国产精品国模大尺度视频| 偷窥少妇高潮呻吟av久久免费| 亚洲一二三四在线| 经典一区二区三区| 日本韩国一区二区| 亚洲精品在线三区| 喷水一区二区三区| 91黄色激情网站| 久久亚洲综合色一区二区三区| 亚洲成国产人片在线观看| 国产成人精品影视| 欧美精品日韩一本| 最新不卡av在线| 成人va在线观看| 精品国产一区a| 亚洲国产综合视频在线观看| 成人18视频在线播放| 欧美xxxx在线观看| 亚洲图片自拍偷拍| 91色视频在线| 亚洲色图自拍偷拍美腿丝袜制服诱惑麻豆 | 在线日韩av片| 一区二区三区在线视频免费| 粉嫩aⅴ一区二区三区四区五区| 欧美日韩精品三区| 亚洲天堂成人在线观看| 国产99精品国产| 久久久高清一区二区三区| 日韩不卡一区二区| 成人性色生活片| 国产精品不卡一区二区三区|