/*
+--------------------------------------------------------------------+
| PROJECT: MMI-Framework (8417)         $Workfile:: mfw_nm.h        $|
| $Author:: Es                          $Revision::  1              $|
| CREATED: 07.10.98                     $Modtime:: 20.01.00 18:48   $|
| STATE  : code                                                      |
+--------------------------------------------------------------------+

  PURPOSE: Type definitions for network management

  HISTORY:

	Feb 15, 2006    ER: OMAPS00065203 x0pleela
   	Description: Cingular Operator Name Prioritization implementation required
   	Solution: Incorporated review comments
   			- Implemented prototypes of 2 new functions set_opn_sel_done() and 
   				get_opn_sel_done() to set and get the current status of the operator selection
			- Added T_MFW_NM_OPN opn_read_from as part of T_MFW_NETWORK_STRUCT
				structure to avoid use of global variable as per review comments    

	Feb 09, 2006    ER: OMAPS00065203 x0pleela
   	Description: Cingular Operator Name Prioritization implementation required
   	Solution: Added new enumeration T_MFW_NM_OPN
   			Added new event E_NM_OPN
   			Added prototype of newly incorporated functions
   	
  	July 14, 2005  REF: CRR 31916  x0021334
    	Description: rCI_PercentCOPS() and rAT_PercentCOPS() is not implemented
    	Solution: rAT_PercentCOPS() is implemented. 
*/

#ifndef DEF_MFW_NM
#define DEF_MFW_NM



/* #include "phb.h" RSA 20/12/01 - Removed */
#include"mfw_phb.h" //RSA 20/12/01 - Added
#ifdef FF_2TO1_PS
#include "prim.h"
#else
#include "p_mmreg.val"
#endif
/*
 * global constants
 */
#define NM_AUTOMATIC    0       /* automatic mode set */
#define NM_MANUAL       1       /* manual mode is set */


/* permit maximal value */

#define MAX_PLMN          12     /* maximal PLMN number */

#define LONG_NAME         26
#define SHORT_NAME        10
#define SP_NAME           17
#define NUMERIC_LENGTH    7     /* 3 digits MCC + 3 digits MNC + '\0' */

#define MFW_PLMN_AVAILABLE  0   /* a permitted PLMN */
#define MFW_PLMN_FORBIDDEN  1   /* a forbidden PLMN */

#define MFW_FULL_SERVICE      1      /* definition for services */
#define MFW_LIMITED_SERVICE   2
#define MFW_SEARCH_NETWORK    3
#define MFW_NO_SERVICE        0

typedef enum
{
  NEW_PREF_PLMN = 1,    /* Add a new entry to the end of the list        */
  CHANGE_PREF_PLMN,     /* Change the place of two entries               */
  INSERT_PREF_PLMN,     /* Add a new entry to the list at a given index  */
  REPLACE_PREF_PLMN,    /* Overwrite an existing entry  at a given index */
  DELETE_PREF_PLMN      /* Delete an entry from the list                 */
} T_MFW_PPLMN_MODE;

typedef enum
{
  NM_ERR,
  NM_OK
} T_MFW_NM_RETURN;

//x0pleela 08 Feb, 2006 ER: OMAPS00065203
typedef enum
{
  NM_ROM,			/* operator name read from ROM   */
  NM_EONS,			/* operator name read from EONS */
  NM_CPHS,			/* operator name read from ONS   */
  NM_NITZ,			/* operator name read from NITZ  */
  NM_NONE = 255 	/* no operator name                     */
}T_MFW_NM_OPN;

//x0pleel 8 Feb, 2006 ER: OMAPS00065203
#define E_NM_OPN 0x4000  /* Event sent by MFW when operator name is obtained */

/*
 * events are organised as bitmaps
 */
#define E_NM_FULL_SERVICE      0x0001
#define E_NM_NO_SERVICE        0x0002
#define E_NM_LIMITED_SERVICE   0x0004
#define E_NM_SEARCH_NETWORK    0x0008
#define E_NM_PLMN_LIST         0x0010
#define E_NM_NO_NETWORK        0x0020
#define E_NM_DEREGISTRATION    0x0040
#define E_NM_PREF_PLMN_LIST    0x0080
#define E_NM_CHANGE_PPLMN_OK   0x0100
#define E_NM_CHANGE_PPLMN_ERR  0x0200
#define E_NM_PPLMN_MEM         0x0400
#define E_MFW_NET_IND          0x0800
#define E_MFW_TIME_IND         0x1000
#define E_NM_CELL_SELECT		 0x1001
#define E_NM_BAND				 0x2000	/*SPR919 - SH - added */

#define E_NM_ALL_SERVICES      /*0x0FFF*/ 0xFFFF /* SPR919 - SH - changed */

/* Structures */

/* Cell Reselection Structure API 16-04-02 */
typedef struct
{
	USHORT ci;		/* cell identification */
	USHORT lid;		/* location identification */
}T_MFW_CELL_STRUCT;
	
typedef struct  /* LONG NAME */
{
  UBYTE dcs;
  UBYTE len;                  /* length of string data        */
  UBYTE data[LONG_NAME];      /* string data                  */
} T_MFW_LNAME;

typedef struct  /* SHORT NAME */
{
  UBYTE dcs;
  UBYTE len;                  /* length of string data        */
  UBYTE data[SHORT_NAME];     /* string data                  */
} T_MFW_SNAME;

typedef struct  /* SERVICE PROVIDER NAME */
{
  UBYTE dcs;
  UBYTE len;               /* length of string data        */
  UBYTE data[SP_NAME];     /* string data                  */
  UBYTE dummy;
} T_MFW_SP_NAME;

typedef struct
{
    SHORT index;
#ifdef NO_ASCIIZ
    T_MFW_SP_NAME service_provider; /* service provider name */
	T_MFW_LNAME network_long;  /* operator name in long format */
    T_MFW_SNAME network_short; /* operator name in short format */
#else
    UBYTE service_provider[LONG_NAME]; /* service provider name */
    UBYTE network_long [LONG_NAME];  /* operator name in long format */
    UBYTE network_short[SHORT_NAME]; /* operator name in short format */
#endif
    UBYTE network_numeric[NUMERIC_LENGTH];  /* operator name in numeric format */
    UBYTE display_condition;
    UBYTE roaming_indicator;    /* PLMN in HPLMN or not */
    UBYTE forbidden_indicator;  /* PLMN is member of the forbidden PLMN list */
    UBYTE *fieldstrength;       /* fieldstrength of PLMN */
    //x0pleela 15 Feb, 2006   ER: OMAPS00065203
    //Added as part of this structure to avoid use of global variable as per review comments
    T_MFW_NM_OPN opn_read_from; /* Holds the source id from where operator name was read */
} T_MFW_NETWORK_STRUCT;

typedef struct {
    UBYTE count;                /* number of entries in perferred PLMN list */
    T_MFW_NETWORK_STRUCT *plmn;      /* plmn identifications */
} T_MFW_PREF_PLMN_LIST; /* prefered PLMN list*/

typedef struct
{
    UBYTE count;                /* number of available PLMNs */
    T_MFW_NETWORK_STRUCT plmn[MAX_PLMN];  /* plmn identifications */
} T_MFW_PLMN_LIST;

typedef struct
{
    UBYTE maxRcd;               /* maximum preferred PLMN records in SIM card */
    UBYTE usedRcd;              /* used preferred PLMN records in SIM card */
} T_MFW_PPLMN_MEM;

typedef struct /* data for network name */
{
  UBYTE dcs;
  UBYTE add_ci;
  UBYTE num_spare;
  UBYTE len;
#ifdef FF_2TO1_PS
  UBYTE data[MMREG_MAX_TEXT_LEN];
#else
  UBYTE data[MMR_MAX_TEXT_LEN];
#endif
} T_MFW_NET_NAME;

typedef struct /* data buffer for network name */
{
#ifdef FF_2TO1_PS
  UBYTE mcc[PS_SIZE_MCC];       /* mobile country code */
  UBYTE mnc[PS_SIZE_MNC_MAX];       /* mobile network code */
#else
  UBYTE mcc[SIZE_MCC];       /* mobile country code */
  UBYTE mnc[SIZE_MNC];       /* mobile network code */
#endif
  T_MFW_NET_NAME long_name;  /* Network name, long format */
  T_MFW_NET_NAME short_name; /* Network name, short format */
} T_MFW_NET_IND;

typedef struct /* data for timer zone */
{
  UBYTE year;
  UBYTE month;
  UBYTE day;
  UBYTE hour;
  UBYTE minute;
  UBYTE second;
  UBYTE timezone;
} T_MFW_TIME_IND;

/*
 * Network Parameter
 */
typedef union
{
  T_MFW_NETWORK_STRUCT ident;
  T_MFW_PLMN_LIST  plmns;
  T_MFW_PREF_PLMN_LIST pplmns;
  T_MFW_PPLMN_MEM pplmn_mem;
  T_MFW_NET_IND net_info;
  T_MFW_TIME_IND tim_info;
  T_MFW_CELL_STRUCT cell_info;	/* sbh 29-04-02 - Cell reselection */
} T_MFW_NM_PARA;



/*
 * Prototypes
 */

int nm_init (void);
MfwHnd nm_create (MfwHnd hWin, MfwEvt event, MfwCb cbfunc);
MfwRes nm_delete (MfwHnd hWin);
void nm_set_mode (U8 mode);
T_MFW nm_get_mode (void);
T_MFW nm_reg_status (void);
void nm_select_plmn (U8 *network);
void nm_avail_plmn_list (void);
void nm_home_plmn (T_MFW_NETWORK_STRUCT *hplmn);
int nm_plnm_list(T_MFW_NETWORK_STRUCT *plmn_list, int start, int count);

int nm_plnm_list_longnames(char**plmn_ln_list, int start, int count); /*SPR 2635.*/

void nm_pref_plmn_list(T_MFW_NETWORK_STRUCT *pplmn, UBYTE count, SHORT start);
T_MFW_NM_RETURN nm_change_pref_plmn(T_MFW_PPLMN_MODE mode,
                                    SHORT index, SHORT index2,
                                    UBYTE *network_numeric);

T_MFW_NM_RETURN nm_change_pref_plmn_longname(T_MFW_PPLMN_MODE mode,/*SPR 2635.*/
                                    SHORT index, SHORT index2,
                                    char* network_long);

T_MFW nm_registration (U8 mode, U8 freq_bands, U8 limited);
void nm_deregistration (void);
void nm_abort_avail_plmn(void);
void nm_exit (void);
T_MFW_NM_RETURN nm_pplmn_mem_req(void);

//x0pleela 09 Feb, 2006  ER: OMAPS00065203
//Conversion from ACI souce Id type to MFW souceid type
#ifndef NEPTUNE_BOARD
int nm_decodeSourceId( UBYTE sourceId);
#endif
//To update plmn data after querying COPN
void nm_update_plmn_data( T_MFW_NETWORK_STRUCT *plmn_ident, 
							    T_ACI_OPER_NTRY oper_ntry);  
//To query COPN
void nm_get_COPN( T_MFW_NETWORK_STRUCT *plmn_ident );
//Get operator name from other sources (CPHS or NITZ or ROM)
void nm_get_opername(T_MFW_NETWORK_STRUCT  * plmn_ident);
//gets operator name from network
void nm_get_network_data(T_MFW_NETWORK_STRUCT *plmn_netw_data);

//x0pleela 15 Feb, 2006  ER: OMAPS00065203
//sets opn_sel_done flag to TRUE or FALSE
void set_opn_sel_done( UBYTE opn_selected );
//returns the current value of flag opn_sel_done
UBYTE get_opn_sel_done( void );

#ifdef NO_ASCIIZ
void nm_get_spn (T_MFW_SP_NAME *spn);
#else
/* PATCH PMC 000804 */
void nm_get_spn (char *);
/* END PATCH PMC */
#endif
void nm_abort_registraion(void);

// July 14, 2005  REF: CRR 31916  x0021334
// Prototype for new common function 'nm_Plus_Percent_COPS()'
void nm_Plus_Percent_COPS (S16 last_ind, T_ACI_COPS_OPDESC *operLst);
#endif

