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

📄 auth.c

📁 brew代码里面的一个文件
💻 C
📖 第 1 页 / 共 5 页
字号:
      ERR( "AUTH not initialized", 0, 0, 0);
      cmd_ptr->hdr.status = AUTH_INVALID_S;
      if (cmd_ptr->hdr.cmd_hdr.task_ptr != NULL)
      {
        (void) rex_set_sigs( cmd_ptr->hdr.cmd_hdr.task_ptr,
                            cmd_ptr->hdr.cmd_hdr.sigs );
      }
      return;
    }
  }
#endif /* !FEATURE_UIM_RUIM || FEATURE_UIM_RUN_TIME_ENABLE */

  switch (cmd_ptr->hdr.command)
  {
#ifdef FEATURE_AUTH
    case AUTH_INIT_F:
      {
        cmd_ptr->hdr.status = AUTH_RECEIVED_S;

        if (cmd_ptr->hdr.cmd_hdr.task_ptr != NULL)
        {
          (void) rex_set_sigs( cmd_ptr->hdr.cmd_hdr.task_ptr,
                              cmd_ptr->hdr.cmd_hdr.sigs );
        }
#ifdef FEATURE_UIM_RUIM
        /* Allow the RUIM to power off for AUTH. */
        uim_power_control ( UIM_AUTH, FALSE );

#if defined( FEATURE_UIM_RUN_TIME_ENABLE )
        /* Determine if the R-UIM is available for this NAM */
        if (nv_rtre_use_ruim_for_nam(auth_stored_NAM_index))
#endif /* FEATURE_UIM_RUN_TIME_ENABLE */
        {
          auth_saved_registers = FALSE;
          auth_ssd_update_in_progress = FALSE;
          auth_valid_CMEA_key = FALSE;
          auth_valid_PLCM = FALSE;

          /* Store NAM index */
          auth_stored_NAM_index = cmd_ptr->init.nam;

          auth_init_status = AUTH_INIT_OK;

          /* Treat this command as a read from Call Count */
          /* Retrieve a UIM command buffer from the queue. */
          if ((uim_cmd_ptr = (uim_cmd_type*) q_get( &uim_free_q )) != NULL)
          {
            uim_cmd_ptr->access_uim.hdr.command = UIM_ACCESS_F;
            uim_cmd_ptr->access_uim.num_bytes = 1;  /* One byte in size */
            uim_cmd_ptr->access_uim.offset = 1;     /* First byte */
            uim_cmd_ptr->access_uim.rec_mode = UIM_ABSOLUTE;
            uim_cmd_ptr->access_uim.data_ptr = (byte *)&(temp_auth_count);
            uim_cmd_ptr->access_uim.item = UIM_CDMA_CC;       /* EF is "Call Count" */
            uim_cmd_ptr->access_uim.access = UIM_READ_F;     /* "Read" command        */

            /* Send the command and wait for the response. */
            auth_send_uim_command(uim_cmd_ptr);

            /* Determine if the command passed. */
            if (uim_rpt_ptr->rpt_status == UIM_PASS)
            {
              /* Copy the new call count to the call count buffer. */
              auth_count = temp_auth_count & RUIM_CC_MASK;
            } /* end if - the command passed */
          }
          else /* No UIM command buffers on the free queue. */
          {
            ERR( "No free buffers on auth_free_q", 0, 0, 0 );
          } /* Get a UIM command buffer from the UIM free queue. */
          auth_init_status = AUTH_INIT_OK;
        }
#if defined( FEATURE_UIM_RUN_TIME_ENABLE )
        else /* R-UIM is not available */
#endif /* FEATURE_UIM_RUN_TIME_ENABLE */
#endif /* FEATURE_UIM_RUIM */
#if !defined( FEATURE_UIM_RUIM ) || defined( FEATURE_UIM_RUN_TIME_ENABLE )
        {
          auth_var_init(cmd_ptr->init.nam);
          auth_init_status = CAVE_init( cmd_ptr->init.nam );
        }
#endif /* !FEATURE_UIM_RUIM || FEATURE_UIM_RUN_TIME_ENABLE */
      } /* end case - AUTH_INIT_F */
      break;

    case AUTH_SSD_UPDATE_F:
      {
        /* Clear the T64 timer to handle the case where an SSD Update
        is in progress and an Idle HO occurs.  The new BS will initiate
        SSD Update and we don't want the old timer expiration to abort
        the new attempt */
        (void) rex_clr_timer( &auth_ssd_timer );
        (void) rex_clr_sigs( &auth_tcb, AUTH_SSD_TIMER_SIG );

        /* Inform the client that the command is being processed. */
        cmd_ptr->hdr.status = AUTH_RECEIVED_S;

        if (cmd_ptr->hdr.cmd_hdr.task_ptr != NULL)
        {
          (void) rex_set_sigs( cmd_ptr->hdr.cmd_hdr.task_ptr,
                              cmd_ptr->hdr.cmd_hdr.sigs );
        }
        /* Indicate the SSD update has started */
        auth_ssd_update_in_progress = TRUE;

#ifdef FEATURE_UIM_RUIM
#if defined( FEATURE_UIM_RUN_TIME_ENABLE )
        /* Determine if the R-UIM is available for this NAM */
        if (nv_rtre_use_ruim_for_nam(auth_stored_NAM_index))
#endif /* FEATURE_UIM_RUN_TIME_ENABLE */
        {
          /* Retrieve a UIM command buffer from the queue. */
          if ((uim_cmd_ptr = (uim_cmd_type*) q_get( &uim_free_q )) != NULL)
          {
            /* Build a SSD update command. */
            uim_cmd_ptr->hdr.command = UIM_SSD_UPDATE_F;
            uim_cmd_ptr->ssd_update.randssd[0] = cmd_ptr->ssd.randssd[0];
            uim_cmd_ptr->ssd_update.randssd[1] = cmd_ptr->ssd.randssd[1];
            /* Include the process control bit if the card has
               generated new A-Key */
            if (a_key_temp_valid)
            {
                cmd_ptr->ssd.process_control |= RUIM_COMMIT_NEW_SSD;
            }
            /* Fill in the rest of the command parameters. */
            uim_cmd_ptr->ssd_update.process_control = cmd_ptr->ssd.process_control;
            uim_cmd_ptr->ssd_update.esn = cmd_ptr->ssd.esn;

            /* Send the command and wait for the response. */
            auth_send_uim_command(uim_cmd_ptr);

            /* Do NOT check the response.  There is no use for a response
               for this command. */
          }
          else /* No UIM command buffers on the free queue. */
          {
            ERR( "No free buffers on auth_free_q", 0, 0, 0 );
          } /* Get a UIM command buffer from the UIM free queue. */
        }
#if defined( FEATURE_UIM_RUN_TIME_ENABLE )
        else /* R-UIM is not available */
#endif /* FEATURE_UIM_RUN_TIME_ENABLE */
#endif /* FEATURE_UIM_RUIM */
#if !defined( FEATURE_UIM_RUIM ) || defined( FEATURE_UIM_RUN_TIME_ENABLE )
        {
          CAVE_generate_SSD( cmd_ptr->ssd.randssd );
          authbs = CAVE_auth_signature( cmd_ptr->ssd.randbs,
                     cmd_ptr->ssd.auth_data, TRUE, FALSE
#ifdef FEATURE_OTASP_OTAPA
                     , FALSE  // Not for SPASM
#endif /* FEATURE_OTASP_OTAPA */
                           );
        }
#endif /* !FEATURE_UIM_RUIM || FEATURE_UIM_RUN_TIME_ENABLE */

        MSG_MED( "SSD update command recd", 0, 0, 0 );
      } /* end case - AUTH_SSD_UPDATE_F */
      break;

    case AUTH_FINISH_SSD_UPDATE_F:
      {
        /* Cancel the SSD timer now that the FINISH_SSD command has
           been received. */
        (void) rex_clr_sigs( &auth_tcb, AUTH_SSD_TIMER_SIG );
        (void) rex_clr_timer( &auth_ssd_timer );

        /* Determine if the SSD update has started. */
        if (!auth_ssd_update_in_progress)
        {
          MSG_MED( "No SSD Update in progress", 0, 0, 0 );
          cmd_ptr->hdr.status = AUTH_INVALID_S;
          if (cmd_ptr->hdr.cmd_hdr.task_ptr != NULL)
          {
            (void) rex_set_sigs( cmd_ptr->hdr.cmd_hdr.task_ptr,
                                cmd_ptr->hdr.cmd_hdr.sigs );
          }
          /* We do not need to process this command and the buffer
             needs to be released */
        }
        else /* We can proceed and finish the SSD Update */
        {
          /* Inform the client the command was received. */
          cmd_ptr->hdr.status = AUTH_RECEIVED_S;
          if (cmd_ptr->hdr.cmd_hdr.task_ptr != NULL)
          {
            (void) rex_set_sigs( cmd_ptr->hdr.cmd_hdr.task_ptr,
                                cmd_ptr->hdr.cmd_hdr.sigs );
          }
          /* Indicate the SSD is finished. */
          auth_ssd_update_in_progress = FALSE;
#ifdef FEATURE_UIM_RUIM
#if defined( FEATURE_UIM_RUN_TIME_ENABLE )
          /* Determine if the R-UIM is available for this NAM */
          if (nv_rtre_use_ruim_for_nam(auth_stored_NAM_index))
#endif /* FEATURE_UIM_RUN_TIME_ENABLE */
          {
            /* Retrieve a UIM command buffer from the queue. */
            if ((uim_cmd_ptr = (uim_cmd_type*) q_get( &uim_free_q )) != NULL)
            {
              /* Build a confirm SSD command. */
              uim_cmd_ptr->confirm_ssd.hdr.command = UIM_CONFIRM_SSD_F;
              uim_cmd_ptr->confirm_ssd.authbs = cmd_ptr->f_ssd.authbs;

              /* Send the command and wait for the response. */
              auth_send_uim_command(uim_cmd_ptr);

              /* -------------------------------------
              ** Now, if required, report back whether
              ** or not SSD update was successful.
              ** ------------------------------------- */
              if (cmd_ptr->f_ssd.rpt_function != NULL)
              {
                /* Retrieve the UIM response from the UIM report buffer. */
                auth_rpt_buf.rpt_type = AUTH_FINISH_SSD_R;
                auth_rpt_buf.rpt_status = uim_rpt_ptr->rpt_status;

                /* Copy the UIM response to the report buffer. */
                auth_rpt_buf.rpt.ssd_update_ok = uim_rpt_ptr->rpt.ssd_update_ok;

                /* Fill in necessary fields of command block */
                auth_rpt_buf.rpt_hdr.task_ptr = NULL;

                /* Report to requesting task */
                (*(cmd_ptr->f_ssd.rpt_function))( &auth_rpt_buf );
                MSG_MED( "Reporting SSD update complete", 0, 0, 0 );
              }
            }
            else /* No UIM command buffers on the free queue. */
            {
              ERR( "No free buffers on auth_free_q", 0, 0, 0 );
            } /* Get a UIM command buffer from the UIM free queue. */
            /* The SSD is no longer in progress.  Allow the UIM to be powered 
               down */
            uim_power_control ( UIM_AUTH, FALSE );
          }
#if defined( FEATURE_UIM_RUN_TIME_ENABLE )
          else /* R-UIM is not available */
#endif /* FEATURE_UIM_RUN_TIME_ENABLE */
#endif /* FEATURE_UIM_RUIM */
#if !defined( FEATURE_UIM_RUIM ) || defined( FEATURE_UIM_RUN_TIME_ENABLE )
          {
            MSG_MED( "Received authbs %ld", cmd_ptr->f_ssd.authbs, 0, 0 );

            /* If the base station value is correct, report SSD Update success */
            if (authbs == cmd_ptr->f_ssd.authbs)
            {
              return_status = TRUE;
            }
            else
            {
              return_status = FALSE;
            }

            /* -------------------------------------
            ** Now, if required, report back whether
            ** or not SSD update was successful.
            ** ------------------------------------- */
            if (cmd_ptr->f_ssd.rpt_function != NULL)
            {
              auth_rpt_buf.rpt_type = AUTH_FINISH_SSD_R;
              auth_rpt_buf.rpt.ssd_update_ok = return_status;

              /* Fill in necessary fields of command block */
              auth_rpt_buf.rpt_hdr.task_ptr = NULL;

              /* Queue report for requesting task */
              (*(cmd_ptr->f_ssd.rpt_function))( &auth_rpt_buf );
              MSG_MED( "Reporting SSD update complete", 0, 0, 0 );
            }

            /* ----------------------------------------------------------------
            ** Tell CAVE to update the SSD (Write it to NV) after reporting
            ** the success.  There is a 750 ms timeout for analog voice channel
            ** operation, and we take too long otherwise.  this is OK since the
            ** NV is guaranteed to write properly or else cause a fatal error.
            ** The NV writes take almost two seconds.
            ** ---------------------------------------------------------------- */

            /* ------------------------------------------------------------------
            ** If a_key_temp_valid is true, we do not want to write SSD to NV.
            ** The new_ssd_valid flag is set to true to indicate that ssd has
            ** been generated from the new A-Key. Also if we got a commit request,
            ** by looking at this flag we can decide if we need to commit the ssd
            ** ---------------------------------------------------------------- */

            if (a_key_temp_valid) {
              /* change the flag to indicate that new A-Key has been used
              ** to generate the SSDs  */
              new_ssd_valid = TRUE;
            }
            else 
            {
              if (return_status == TRUE)
              {
                (void) CAVE_update_SSD();
              }
            }
          }
#endif /* !FEATURE_UIM_RUIM || FEATURE_UIM_RUN_TIME_ENABLE */
        }
        /* Send a indicating what was done. */
        MSG_MED( "Received SSD update command ", 0, 0, 0 );
      } /* end case - AUTH_FINISH_SSD_UPDATE_F */
      break;

    case AUTH_SIGNATURE_F:
      {
        cmd_ptr->hdr.status = AUTH_RECEIVED_S;
        if (cmd_ptr->hdr.cmd_hdr.task_ptr != NULL)
        {
           (void) rex_set_sigs( cmd_ptr->hdr.cmd_hdr.task_ptr,
                             cmd_ptr->hdr.cmd_hdr.sigs );
        }

#ifdef FEATURE_UIM_RUIM
#if defined( FEATURE_UIM_RUN_TIME_ENABLE )
        /* Determine if the R-UIM is available for this NAM */
        if (nv_rtre_use_ruim_for_nam(auth_stored_NAM_index))
#endif /* FEATURE_UIM_RUN_TIME_ENABLE */
        {
          /* Retrieve a UIM command buffer from the queue. */
          if ((uim_cmd_ptr = (uim_cmd_type*) q_get( &uim_free_q )) != NULL)
          {
            uim_cmd_ptr->run_cave.hdr.command = UIM_RUN_CAVE_F;
            uim_cmd_ptr->run_cave.rand_type = cmd_ptr->sig.rand_type;
            uim_cmd_ptr->run_cave.rand_chal = cmd_ptr->sig.rand_chal;
            uim_cmd_ptr->run_cave.dig_len = cmd_ptr->sig.dig_len;
            memcpy ( uim_cmd_ptr->run_cave.digits, 
                     cmd_ptr->sig.digits, 
                     RUIM_RUN_CAVE_DIGITS);
            uim_cmd_ptr->run_cave.process_control = cmd_ptr->sig.process_control;
            uim_cmd_ptr->run_cave.esn[0] = cmd_ptr->sig.esn;
            uim_cmd_ptr->run_cave.esn[1] = 0; /* Zero out the MSbits of the ESN 
                                                 since the command takes 7 bytes 
                                                 and our ESN is only 4 bytes.*/

            /* Send the command and wait for the response. */
            auth_send_uim_command(uim_cmd_ptr);

            /* Determine if the run CAVE command passed. */
            if (uim_rpt_ptr->rpt_status == UIM_PASS)
            {
              /* Determine whether the registers were saved based on the
                 command control. */

⌨️ 快捷键说明

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