view src/g23m-aci/aci/plmn_decoder.c @ 600:8f50b202e81f

board preprocessor conditionals: prep for more FC hw in the future This change eliminates the CONFIG_TARGET_FCDEV3B preprocessor symbol and all preprocessor conditionals throughout the code base that tested for it, replacing them with CONFIG_TARGET_FCFAM or CONFIG_TARGET_FCMODEM. These new symbols are specified as follows: CONFIG_TARGET_FCFAM is intended to cover all hardware designs created by Mother Mychaela under the FreeCalypso trademark. This family will include modem products (repackagings of the FCDEV3B, possibly with RFFE or even RF transceiver changes), and also my desired FreeCalypso handset product. CONFIG_TARGET_FCMODEM is intended to cover all FreeCalypso modem products (which will be firmware-compatible with the FCDEV3B if they use TI Rita transceiver, or will require a different fw build if we switch to one of Silabs Aero transceivers), but not the handset product. Right now this CONFIG_TARGET_FCMODEM preprocessor symbol is used to conditionalize everything dealing with MCSI. At the present moment the future of FC hardware evolution is still unknown: it is not known whether we will ever have any beyond-FCDEV3B hardware at all (contingent on uncertain funding), and if we do produce further FC hardware designs, it is not known whether they will retain the same FIC modem core (triband), if we are going to have a quadband design that still retains the classic Rita transceiver, or if we are going to switch to Silabs Aero II or some other transceiver. If we produce a quadband modem that still uses Rita, it will run exactly the same fw as the FCDEV3B thanks to the way we define TSPACT signals for the RF_FAM=12 && CONFIG_TARGET_FCFAM combination, and the current fcdev3b build target will be renamed to fcmodem. OTOH, if that putative quadband modem will be Aero-based, then it will require a different fw build target, the fcdev3b target will stay as it is, and the two targets will both define CONFIG_TARGET_FCFAM and CONFIG_TARGET_FCMODEM, but will have different RF_FAM numbers. But no matter which way we are going to evolve, it is not right to have conditionals on CONFIG_TARGET_FCDEV3B in places like ACI, and the present change clears the way for future evolution.
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 01 Apr 2019 01:05:24 +0000
parents 53929b40109c
children
line wrap: on
line source

/* plmn_decoder.cpp : Defines the entry point for the console application. */

#include <assert.h>
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>

#ifdef TI_PS_OP_OPN_TAB_ROMBASED
#ifndef CMH_PLMN_DECODER_C
#define CMH_PLMN_DECODER_C
#endif

#include "aci_all.h"

/*==== INCLUDES ===================================================*/

#include "aci_cmh.h"
#include "ati_cmd.h"
#include "aci_cmd.h"
#include "aci_mem.h"
#include "pcm.h"

#ifdef TI_PS_OP_OPN_TAB_ROMBASED
  #include "rom_tables.h"
#endif /* TI_PS_OP_OPN_TAB_ROMBASED */


#ifdef FAX_AND_DATA
#include "aci_fd.h"
#endif    /* of #ifdef FAX_AND_DATA */

#include "aci.h"
#include "psa.h"
#include "psa_mm.h"
#include "psa_sim.h"
#include "psa_util.h"
#include "cmh.h"



#define PLMN_LONGNAME_LOOKUP 0xff

EXTERN void  cmhSIM_getMncMccFrmPLMNsel( const UBYTE* ntry, 
                                                         SHORT* mcc, 
                                                         SHORT* mnc );

/* NHK:
 * Once the tables plmn_compressed, plmn_dict_offset and plmn_dict go to ROM, their names below should match corresponding ROM addresses
 * KSR: Moved to g23m\condat\com\src\drivers\rom_tables.c
 */

/*
+----------------------------------------------------------------------------+
| PROJECT : GSM-PS (6147)       MODULE  : MM_MM                              |
| STATE   : code                ROUTINE : cmhMM_CompLongLength               |
+----------------------------------------------------------------------------+

  PURPOSE : This function gets the compressed length of the longName
            from a compressed PLMN entry.
  
*/
LOCAL USHORT cmhMM_CompLongLength (const UBYTE *plmn_comp_entry)
{
  UBYTE length_byte;

  length_byte = *(plmn_comp_entry + 3);

  return ((length_byte >> 3) & 0x1f) + 1;
}

/*
+----------------------------------------------------------------------------+
| PROJECT : GSM-PS (6147)       MODULE  : MM_MM                              |
| STATE   : code                ROUTINE : cmhMM_CompShrtLength               |
+----------------------------------------------------------------------------+

  PURPOSE : This function gets the compressed length of the shrtName
            from a compressed PLMN entry.
  
*/
LOCAL USHORT cmhMM_CompShrtLength (const UBYTE *plmn_comp_entry)
{
  UBYTE length_byte;

  length_byte = *(plmn_comp_entry + 3);

  return ((length_byte     ) & 0x07) + 1;
}


/*
+----------------------------------------------------------------------------+
| PROJECT : GSM-PS (6147)       MODULE  : MM_MM                              |
| STATE   : code                ROUTINE : cmhMM_PlmnEntryLength              |
+----------------------------------------------------------------------------+

  PURPOSE : This function gets the length of a compressed PLMN entry.
  
*/
GLOBAL USHORT cmhMM_PlmnEntryLength (const UBYTE *plmn_comp_entry)
{
  return (4 + cmhMM_CompLongLength (plmn_comp_entry) 
            + cmhMM_CompShrtLength (plmn_comp_entry));
}


/*
+----------------------------------------------------------------------------+
| PROJECT : GSM-PS (6147)       MODULE  : MM_MM                              |
| STATE   : code                ROUTINE : cmhMM_Decompress                   |
+----------------------------------------------------------------------------+

  PURPOSE : This function decompresses a compressed string.
            If the decompressed string is the long PLMN name the longName
            parameter is NULL, when the decompressed string is the short
            PLMN name the longName parameter is the previously decompressed
            PLMN long name, as in some cases the short PLMN name consists of
            parts of the long PLMN name lookups within the decompressed long
            name will be done when advised to do so by the compressed byte 
            string.
            On success the function returns with zero, on detection of an
            internal error a negative value is returned.
 
*/
LOCAL SHORT cmhMM_Decompress (char *decomp_string, 
                              const char *longName,
                              const UBYTE *comp_string,
                              USHORT comp_length)
{
  USHORT offset;
  USHORT length;

  while (comp_length > 0)
  {
    if (*comp_string < 128)
    {
      /* GSM default alphabet. Take character 1:1 */
      *decomp_string = *comp_string;
      decomp_string++;
    }
    else if (*comp_string EQ PLMN_LONGNAME_LOOKUP)
    {
      if ((longName EQ NULL) OR (comp_length <= 1))
      {
        TRACE_ERROR ("Cannot process longName lookup");
        return -1;
      }

      /* Decoding short name. Lookup into long name */

      /* Skip PLMN_LONGNAME_LOOKUP */
      comp_string++;
      comp_length--;

      /* Get offset and length of substring in long name */
      offset = (*comp_string >> 3) & 0x1f;
      length = (*comp_string & 0x07) + 1;
      memcpy (decomp_string, longName + offset, length);
      decomp_string += length;
    }
    else
    {
      /* Dictionary lookup */

      /* Get offset of dictionary entry */
      offset = *(ptr_plmn_dict_offset + (*comp_string - 128)); 

      /* Get length of dictionary entry */
      length = *(ptr_plmn_dict_offset + (*comp_string - 128 + 1)) - offset;
      memcpy (decomp_string, ptr_plmn_dict + offset, length);
      decomp_string += length;
    }
    comp_string++;
    comp_length--;
  }
  decomp_string = '\0';
  return 0;
}


/*
+----------------------------------------------------------------------------+
| PROJECT : GSM-PS (6147)       MODULE  : MM_MM                              |
| STATE   : code                ROUTINE : cmhMM_decodePlmn                   |
+----------------------------------------------------------------------------+

  PURPOSE : This function decodes a compressed PLMN entry into a decompressed
            T_OPER_ENTRY structure. On success this function returns with 
            zero, if during decompression an internal error is detected the
            function returns with a negative value.
 
*/
GLOBAL SHORT cmhMM_decodePlmn (T_OPER_ENTRY *oper, const UBYTE *plmn_comp_entry)
{
  SHORT mcc;              /* Mobile Country Code */
  SHORT mnc;              /* Mobile Network Code */
  USHORT comp_Length;     /* Compressed string length */
  SHORT result;           /* Decompression result */
  const UBYTE *comp_ptr;  /* Compressed PLMNs pointer */

  memset (oper, 0, sizeof (T_OPER_ENTRY));

  cmhSIM_getMncMccFrmPLMNsel (plmn_comp_entry, &mcc, &mnc);
  oper->mcc = mcc;
  oper->mnc = mnc;

  if (mcc EQ -1)
    return -1; /* Got end of list, not processing further */

  /* Decompress longName */
  comp_ptr = plmn_comp_entry + 4;
  comp_Length = cmhMM_CompLongLength (plmn_comp_entry);
  result = cmhMM_Decompress (oper->longName, NULL,
                             comp_ptr, comp_Length);
  if (result < 0)
    return result;

  /* Decompress shrtName */
  comp_ptr += comp_Length;
  comp_Length = cmhMM_CompShrtLength (plmn_comp_entry);
  result = cmhMM_Decompress (oper->shrtName, oper->longName, 
                             comp_ptr, comp_Length);
  return result;
}

#endif