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

📄 auth.c

📁 brew代码里面的一个文件
💻 C
📖 第 1 页 / 共 5 页
字号:
/*====*====*====*====*====*====*====*====*====*====*====*====*====*====*====*


          M A I N    A U T H E N T I C A T I O N    T A S K

GENERAL DESCRIPTION
  This module performs all authentication functions required by IS-95A and is
  also the server for the R-UIM card ( Removable User Identity Module) when
  FEATURE_UIM_RUIM is defined. In the presence of FEATURE_UIM_RUIM, the Authentication
  is performed by the RUIM card and this task acts as the server for the RUIM.

EXTERNALIZED FUNCTIONS
  auth_validate_a_key
    Determines if a given A-key is valid.

  auth_private_lcm_available
    Tells whether or not a private long code mask is available.

  auth_switch_to_private_lcm
    Switches to a private Long Code Mask.

  auth_get_count
    Returns the current value of COUNTsp.

  auth_calculate_digits
    Packs the origination or sms destination digits .

  auth_encryption_possible
    Tells if message encryption is possible at the current time.

  auth_encrypt_cdma
    Encrypts a CDMA message to be transmitted on the traffic channel.

  auth_decrypt_cdma
    Decrypts a CDMA message received on the traffic channel.

  auth_encrypt_analog
    Encrypts an analog message to be transmitted on the voice channel.

  auth_decrypt_analog
    Decrypts an analog message received on the voice channel.

  auth_cmd
    External interface to send a command to the authentication task.

  auth_task
    This is the entrance procedure for the Authentication/ RUIM  task.

INITIALIZATION AND SEQUENCING REQUIREMENTS
  The AUTH_INIT_F command must be sent before successful authentication
  can be performed.

Copyright (c) 1995, 1999, 2000 by QUALCOMM, Incorporated.  All Rights Reserved.
*====*====*====*====*====*====*====*====*====*====*====*====*====*====*====*/

/* <EJECT> */
/*===========================================================================

                        EDIT HISTORY FOR MODULE

$PVCSPath: L:/src/asw/MSM5100/CP_REL_A/vcs/auth.c_v   1.12   03 Sep 2002 22:10:42   azafer  $
$Header: //depot/asic/msmshared/1x/cp/MSMSHARED_CP_CDMA.02.00.64B/auth.c#3 $ $DateTime: 2004/12/13 12:02:45 $ $Author: azafer $

when       who     what, where, why
--------   ---     ----------------------------------------------------------
12/05/04   az      Submission done for Wes Li. This is for CR 53350 where 
                   a word is written to a pointer pointed to a byte.
08/17/04   yll     For burst type 0x3e and 0x3f of a data burst message, only
                   encrypt the CHARi after the first two bytes.
03/09/04   ph      Change slot to AUTOMATIC in command to UIM.
06/20/03   bkm     Clear T64 timer when SSD Update is received to prevent
                   timer expiration from aborting a second SSD Update attempt
                   after an Idle Handoff.
01/28/03   ts      Make sure UIM can power off whether RTRE control is NV or
                   UIM.
09/03/02   ts      Added support for Run Time R-UIM Enable.
08/26/02   ck      Featurised the processing of CAI_EFWIM_MSG around the feature
                   FEATURE_IS2000_REL_A.
07/25/02   jqi     Updated with task operation interface.
04/12/02   lh      Added support for subaddress in Orig_C.
03/12/02   lh      Added CMEA support for release A messages.
08/09/01   sb      Merged following from common archive:
                   07/27/01   ts      Allow UIM to power off after initializing
                                      (reading call count).
05/25/01   ts      Removed RUIM server code from auth and added interface to
                   new UIM server.
04/12/01   fc      Renamed mcc_report_event_timer to mclog_report_event_timer.
03/12/01   fas     Backed out call to MSG_LOW.
03/09/01   fas     Added includes for comdef.h and customer.h.
                   Added call to MSG_LOW to inhibit compiler warning.
03/08/01   fc      Fixed timer ID of T64m and moved "#include mccdma,h"
                   oustide feature #ifdef to support events report.
03/06/01   fc      Added support of events report: Timer expired.
02/16/01   ck      Fixed the issue where 8 digits of CHV was incorrectly
                   formatted by the CHV formatting routine.
02/07/01   wli     Split RUIM_UPDATE_RECORD_ST to two states:
                   RUIM_UPDATE_LINEAR_FIXED_RECORD_ST and
                   RUIM_UPDATE_CYCLIC_RECORD_ST.
1/27/01    wli     Added new RUIM commands, INVALIDATE and REHABILITATE.
01/11/01   ts      Added a call to flush the nvruim cache when resetting the
                   RUIM.
12/18/00   ck      Fixed the problem where the bytes of the request offset
                   in the SSPR Config request were swapped causing the R-UIM
                   to reject the request with 'Data Size Mismatch'.
11/28/00   ck      Added support for IS-683A with the R-UIM.
                   Added support for STORE_ESN_ME and STATUS command.
                   Added the debug feature for Unblocking the CHV.
                   Added paths for new EFs in the table.
                   Fixed the issue with zeroing 3 extra bytes in the RUN_CAVE.
                   Added a different time-out for the Commit command.
                   Changed the RAND_SEED_F command to BS_CHAL_F.
                   Fixed the problem where an external command that got xlated
                   to an internal command caused a buffer leak.
11/14/00   ts      Added access to the MSISDN in the CDMA directory.  Added
                   support for a faster RUIM clock frequency.  Fixed the APDU
                   for the status command.
10/11/00   ts      Include the RUIM status with auth reports.
07/11/00   ms      Added functionality to return just the size of an EF in records,
07/16/00   ck      Added support to select the CDMA DF before sending any
                   authentication related commands to the card.
                   Fixed the bug where the disabled CHV was causing the phone
                   to go offline.
06/13/00   ck      Added a debug feature to not do PPS since the cards do not do
                   PPS and the ATR tells us that they do.
06/12/00   ck      Added functionality to parse the ATR to determine if PPS can
                   be sent.
                   Added the functionality of reading and writing record from
                   RUIM.
06/06/00   ck      Cleaned up the warning caused by a bad merge for the prev fix.
06/06/00   ck      Fixed the problem where NEW_CHV command followed by any
                   command before powering down the RUIM rsulted in the cmd
                   being ignored.
06/01/00   ck      Added debug feature for ESN in the command RUN CAVE to flip
                   the byte ordering and changed the polling of RUIM based on
                   the status of the RUIM.
05/30/00   ck      Changed instances of RUIM_UI_CHV_SIG to RUIM_CHV_SIG.
05/01/00   ck      Added support for RUIM software. AUTH code has been
                   featurised such that the basic task functionality is
                   obtained by defining either FEATURE_AUTH or FEATURE_RUIM.
                   Authentication functionality performed by CAVE is defined
                   under FEATURE_AUTH and is ifdefed out when FEATURE_RUIM is
                   defined.
                   Various RUIM functions have been added.
04/06/00   va      Merged the following from MSM3100_CP.03.00.17
           ry      Added OTAPA support
08/13/99   jq      Changed the return mechanism of auth_get_nv_item() so the
                   function also returns.
06/17/99   ck      Fixed the problem where the CMEA and VPM keys were computed
                   based on the old SSD during re-authentication.
05/06/99   kmp     Changed T_ACP and T_AUTH to FEATURE_ACP and FEATURE_AUTH
                   respectively.
03/18/99   ck      Merged in the changes for A-Key exchange and
                   Re-Authentication.
09/15/98   pms     Backed out _near pointers
09/04/98   pms     Neared the variables to save ROM space.
07/28/98   dna     Retain message encryption on CDMA->AMPS handoff by
                   separating auth_reset from auth_resync.
06/21/96   dna     Removed AUTH_BAD_SSD_S status.  Always consider SSD valid.
05/15/96   dna     CMEA key generation status now set ASAP.
11/17/95   dna     Report back when keys are generated.
11/16/95   jca     Removed INTLOCK/INTFREE pair in function auth_cmd().
10/05/95   dna     re-initialize after A_Key update
08/03/95   dna     Added support for message encryption
06/07/95   dna     Created module.

===========================================================================*/

/* <EJECT> */
/*===========================================================================

                     INCLUDE FILES FOR MODULE

===========================================================================*/
#include "comdef.h"
#include "target.h"
#include "customer.h"

#if defined (FEATURE_AUTH) || defined (FEATURE_RUIM)
#include "rex.h"
#include "task.h"
#include "dog.h"
#include "msg.h"
#include "err.h"
#include "mc.h"
#include "mccdma.h"
#include "queue.h"
#include "cai.h"
#include "auth.h"
#ifdef FEATURE_AUTH
#include "authi.h"
#include "cave.h"
#endif /* FEATURE_AUTH */
#include "srch.h"
#include "enc.h"
#include "bit.h"
#ifdef FEATURE_ACP
#include "acp553.h"
#include "acprx.h"
#include "ran.h"
#endif /* FEATURE_ACP */
#include "memory.h"
#ifdef FEATURE_UIM_RUIM
#include "uim.h"
#include "nvruimi.h"
#ifdef FEATURE_OTASP
#include "otaspe.h"
#endif /* FEATURE_OTASP */
#endif /* FEATURE_UIM_RUIM */
#include "mclog.h"

/* <EJECT> */
/*===========================================================================

            DEFINITIONS AND DECLARATIONS FOR MODULE

This section contains local definitions for constants, macros, types,
variables and other items needed by this module.

===========================================================================*/

#ifdef FEATURE_AUTH

#define AUTH_THREE_BITS  3
#define AUTH_FOUR_BITS   4
#define AUTH_FIVE_BITS   5
#define AUTH_EIGHT_BITS  8
#define AUTH_TWO_BYTES   2

#define AUTH_RECORD_TYPE_SIZE FSIZ( cai_rec_hdr_type, record_type )
#define AUTH_RECORD_LEN_SIZE  FSIZ( cai_rec_hdr_type, record_len )

/* Macro to unpack the T field of an analog reverse voice channel msg */
#define AUTH_VC_MSG_T( ptr ) b_unpackb( ptr,  3,  1)

/* Macro to unpack the NAWC field of a called address reverse VC msg */
#define AUTH_VC_NAWC( ptr ) b_unpackb( ptr,  1,  2)

/* Macros to replace the characters into forward voice channel info ords */
#define AUTH_VC_MSG_CHAR1( value, ptr ) b_packb( value, ptr,  4,  8)
#define AUTH_VC_MSG_CHAR2( value, ptr ) b_packb( value, ptr, 12,  8)
#define AUTH_VC_MSG_CHAR3( value, ptr ) b_packb( value, ptr, 20,  8)

/* Buffer to hold data to be encrypted */
byte auth_temp_buf[CAI_REV_TC_MAX_MSG_BYTES];

#endif /* FEATURE_AUTH */

/* Buffers to be placed on the auth_free_q */
#define                      AUTH_NUM_CMD_BUFS 3

auth_cmd_type auth_cmd_pool[ AUTH_NUM_CMD_BUFS ];

/* Queue to hold commands for auth */
q_type          auth_cmd_q;

/* Queue to hold free buffers to be placed on the auth_cmd_q */
q_type auth_free_q;

/* Buffer to hold report to be returned to task issuing command */
auth_rpt_type auth_rpt_buf;

/* Timer definitions */
rex_timer_type auth_rpt_timer;  /* Watchdog timer */
#ifdef FEATURE_AUTH
rex_timer_type auth_ssd_timer;  /* SSD timeout timer */
#endif /* FEATURE_AUTH */

#ifdef FEATURE_AUTH
/* Boolean to indicate if we are in the middle of performing SSD update */
LOCAL boolean auth_ssd_update_in_progress = FALSE;

/* Indicates if CMEA key has been generated */
boolean auth_valid_CMEA_key = FALSE;

/* Indicates if Private Long Code Mask has been generated */
boolean auth_valid_PLCM = FALSE;

/* Indicates if auth_signature() has been told to save_registers */
boolean auth_saved_registers = FALSE;

/* Status of auth initialization */
auth_init_status_type auth_init_status = AUTH_UNINITIALIZED;

/* COUNTsp */
byte auth_count = 0;

/* NAM index used in last auth init, used for updating auth_count. */
byte auth_stored_NAM_index;

/* A_KEY_TEMP stores the newly generated A-Key  */
qword a_key_temp;

/* Indicates if a new A_KEY_TEMP has been generated */
boolean a_key_temp_valid = FALSE;

/* Indicates if new SSD has been generated */
boolean new_ssd_valid = FALSE;

/* Indicates that the new ssd has been used for generating the AUTHR in the
   Re-Authentication Response. This flag is primarily used to choose the
   correct SSD during key generation(CMEA and VPM). We cannot use new_ssd_valid
   as there is a chance that we might need to use the old SSD when new SSD is
   valid( If for some reason, encryption is turned on after SSD update and
   before Re-Authentication) */
LOCAL boolean used_new_ssd = FALSE;

#endif /* FEATURE_AUTH */

#ifdef FEATURE_UIM_RUIM
/* Response buffer */
uim_rpt_type auth_uim_rsp_buf;

/* Temporary COUNTsp */
word temp_auth_count = 0;

#ifdef FEATURE_AUTH
ulpn_type auth_plcm;
/* plcm returned by RUIM */

dword auth_randbs;
/* Randbs returned by RUIM */
#endif /* FEATURE_AUTH */

/* Constants for origination message translation */

#define AUTH_DIAL_0                0xA
#define AUTH_DIAL_STAR             0xB
#define AUTH_DIAL_PND              0xC
#define AUTH_DIAL_NULL             0x0

/*===========================================================================

            FUNCTION PROTOTYPES

This section contains local function prototypes for the RUIM interface code.

===========================================================================*/
LOCAL word  auth_wait
(
  /* Mask of signals to wait for */
  word  sigs
);

⌨️ 快捷键说明

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