
#include "BRIDLEInit.h"
#include "AEEStdLib.h"
#define BRIDLE_CM_IMPL
#include "bridle_cm.h"

#if __ARMCC_VERSION >= 120000
#pragma arm section zidata = "bridle_svc_rw_usr_ro"
#endif
uint32 BRIDLE_SUBSYS_NO(cm);

typedef struct {
   boolean bInit;
   cm_client_id_type  client_id;
   cm_mm_call_event_f_type *call_event_func;
   cm_mm_call_cmd_err_f_type *call_cmd_err_func;
   cm_ph_event_f_type *ph_event_func;
   cm_ph_cmd_err_f_type *ph_cmd_err_func;
   cm_mm_ss_event_f_type *ss_event_func;
   cm_ss_cmd_err_f_type *ss_cmd_err_func;
   cm_inband_event_f_type *inband_event_func;
   cm_mm_inband_cmd_err_f_type *inband_cmd_err_func;

   cm_mm_call_info_s_type call_info;
   cm_ph_info_s_type ph_info;
   cm_mm_ss_info_s_type ss_info;
   cm_inband_info_s_type inband_info;
} CMINST;

static CMINST bridle_client_inst;


#if __ARMCC_VERSION >= 120000
#pragma arm section zidata
#endif

#ifndef ARRAY_SIZE
#define  ARRAY_SIZE(a) (sizeof((a))/sizeof((a)[0]))
#endif

static void bridle_svc_call_event_func( cm_call_event_e_type call_event, const cm_mm_call_info_s_type *call_info_ptr );
static void bridle_svc_call_cmd_err_func( cm_call_id_type call_id, cm_client_id_type client_id, cm_call_cmd_e_type cmd, 
                                          cm_call_cmd_err_e_type cmd_err );
static void bridle_svc_ph_event_func( cm_ph_event_e_type ph_event, const cm_ph_info_s_type *ph_info_ptr );
static void bridle_svc_ph_cmd_err_func( cm_client_id_type client_id, cm_ph_cmd_e_type cmd, cm_ph_cmd_err_e_type cmd_err );
static void bridle_svc_ss_event_func( cm_ss_event_e_type ss_event, const cm_mm_ss_info_s_type *ss_info_ptr );
static void bridle_svc_ss_cmd_err_func( cm_client_id_type client_id, cm_ss_cmd_e_type cmd, cm_ss_cmd_err_e_type cmd_err );
static void bridle_svc_inband_event_func( cm_inband_event_e_type inband_event, const cm_inband_info_s_type *inband_info_ptr );
static void bridle_svc_inband_cmd_err_func( cm_call_id_type call_id, cm_client_id_type client_id, cm_inband_cmd_e_type cmd,
                                            cm_inband_cmd_err_e_type cmd_err );


static uint32 unpackbridle_cm_client_init( uint32 swi, uint32 a1, uint32 a2, uint32 a3, uint32 a4 );
static uint32 unpackbridle_cm_mm_client_call_reg( uint32 swi, uint32 a1, uint32 a2, uint32 a3, uint32 a4 );
static uint32 unpackbridle_cm_client_ph_reg( uint32 swi, uint32 a1, uint32 a2, uint32 a3, uint32 a4 );
static uint32 unpackbridle_cm_mm_client_ss_reg( uint32 swi, uint32 a1, uint32 a2, uint32 a3, uint32 a4 );
static uint32 unpackbridle_cm_mm_client_inband_reg( uint32 swi, uint32 a1, uint32 a2, uint32 a3, uint32 a4 );
static uint32 unpackbridle_cm_client_release( uint32 swi, uint32 a1, uint32 a2, uint32 a3, uint32 a4 );

BRIDLE_DECLARE_SUBSYS_HANDLER_TABLE(cm);

BRIDLE_DECLARE_GENERIC_SUBSYS_SWIHANDLER(cm)

int bridle_cm_RegisterSubSystem(void *po)
{
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_mm_call_cmd_orig);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_mm_call_cmd_answer);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_mm_call_cmd_end);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_mm_call_cmd_sups);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_mm_call_cmd_privacy_pref);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_mm_call_cmd_get_call_info);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_mm_call_cmd_setup_res);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_mm_call_cmd_pdp_act_res);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_mm_call_cmd_pdp_modify);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_mm_call_cmd_rab_reestablish);
#ifdef FEATURE_PS_DORMANT_PWR_SAVE
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_mm_ss_cmd_ps_data_available);
#else
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_mm_call_cmd_ps_data_available);
#endif
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_nc_reg);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_ph_cmd_oprt_mode);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_ph_cmd_sys_sel_pref);
#if MIN_CM_REV(3,15)
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_ph_cmd_ddtm_pref);
#endif
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_ph_cmd_avoid_sys);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_ph_cmd_answer_voice);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_ph_cmd_nam_sel);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_ph_cmd_get_ph_info);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_ph_cmd_rssi_delta_threshold);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_ph_cmd_subscription_available);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_ph_cmd_subscription_not_available);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_ph_cmd_subscription_changed);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_ph_cmd_get_networks);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_ph_cmd_terminate_get_networks);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_ph_cmd_set_preferred_networks);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_ph_cmd_packet_state);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_ph_cmd_voc_activity);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_ph_cmd_wakeup_from_standby);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_ph_cmd_change_rtre_config);
#if MIN_CM_REV(3,100)
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_ph_cmd_aoc_reset_acm);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_ph_cmd_aoc_set_acmmax);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_ph_cmd_aoc_get_ccm);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_ph_cmd_aoc_get_acm);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_ph_cmd_aoc_get_acmmax);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_ph_cmd_aoc_get_puct);
#endif
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_ss_cmd_get_ss_info);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_mm_inband_cmd_burst_dtmf);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_mm_inband_cmd_start_cont_dtmf);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_mm_inband_cmd_stop_cont_dtmf);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_sms_cmd_mo_msg);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_sms_cmd_awi_ack);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_sms_cmd_bc_enable);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_pd_cmd_session_start);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_pd_cmd_session_end);
#ifdef FEATURE_GPSONE
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_pd_cmd_reva_mo_msg);
#endif
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm, cm_pd_reg);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_sups_cmd_register);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_sups_cmd_erase);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_sups_cmd_activate);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_sups_cmd_deactivate);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_sups_cmd_interrogate);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_sups_cmd_process_uss);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_sups_cmd_reg_password);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_sups_cmd_release);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_sups_cmd_get_password_res);
#ifdef FEATURE_MMGPS
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_sups_cmd_lcs_molr);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_sups_cmd_lcs_location_notification_res);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_sups_cmd_lcs_molr_completed);
#endif
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_sups_cmd_uss_notify_res);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_sups_cmd_uss_res);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_dbm_cmd_mo_msg);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_client_init);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_client_release);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_mm_client_call_reg);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_client_ph_reg);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_mm_client_ss_reg);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_mm_client_inband_reg);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_client_sms_reg);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_client_pd_reg);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_client_dbm_event_reg);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_client_dbm_class_reg);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_client_sups_reg);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_client_act);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_client_deact);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cmclient_get_client_type);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_change_m511_mode);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_change_m512_mode);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_change_m513_mode);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_m51_mode_reg);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_is_valid_mode_band_pref);
#if (defined(FEATURE_CDMA_800) || defined(FEATURE_CDMA_1900))
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_is_valid_mode_pref);
#endif
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_is_sys_mode_digital);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_get_pref_srv_type_for_packet_orig);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_get_curr_nam);
#ifdef FEATURE_HDR_HYBRID
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_get_cur_hybr_status);
#endif
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_num_init);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_num_fill);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_num_get);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_num_cmp);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_num_cmp_exact);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_num_copy);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_num_ep_msg_copy);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_num_ep_cli_copy);
#if (defined(FEATURE_CDMA_800) || defined(FEATURE_CDMA_1900))
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_num_attrib_copy);
#endif
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_num_validate);
#ifdef FEATURE_IS95B_EXT_DISP
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_ext_disp_itr_reset);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_ext_disp_itr_next);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_ext_disp_itr_more);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_ext_disp_itr_get);
#endif
#if MIN_CM_REV(3,100)
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_get_current_acq_sys_mode);
#if defined FEATURE_HDR_HYBRID && defined FEATURE_GPSONE
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_pd_cmd_fix_start);
BRIDLE_INIT_SUBSYS_HANDLER_TABLE(cm,cm_pd_cmd_fix_end);
#endif
#endif
return BRIDLE_REGISTER_SUBSYS(cm);
}

static CMINST *bridle_cm_check_client( uint32 swi, cm_client_id_type client_id )
{
   if( !(bridle_client_inst.bInit && client_id == bridle_client_inst.client_id) ) {
      BRIDLE_CHECK_WRITEACCESS((swi), 0, 4);
   }

   return &bridle_client_inst;
}

static uint32 unpackbridle_cm_client_init( uint32 swi, uint32 a1, uint32 a2, uint32 a3, uint32 a4 )
{
   cm_client_type_e_type client_type = UNPACKBRIDLE_PARAM_1;
     /* Type of client */
   cm_client_id_type *client_id_ptr = (cm_client_id_type *)UNPACKBRIDLE_PARAM_2;
     /* Client ID pointer*/
   cm_client_status_e_type ret;
   cm_client_id_type local_client;
   
   BRIDLE_CHECK_WRITEACCESS(swi, client_id_ptr, sizeof(cm_client_id_type));

   /* This only handles one client. If another client init is made abort. */
   if( bridle_client_inst.bInit ) {
      BRIDLE_CHECK_WRITEACCESS((swi), 0, 4);
   }

   ret = cm_client_init(client_type, &local_client);

   if( CM_CLIENT_OK == ret ) {
      bridle_client_inst.client_id = local_client;
      bridle_client_inst.bInit = TRUE;
      *client_id_ptr = local_client;
   }

   return (uint32)ret;
}

static uint32 unpackbridle_cm_mm_client_call_reg( uint32 swi, uint32 a1, uint32 a2, uint32 a3, uint32 a4 )
{
   cm_client_id_type client_id = (cm_client_id_type)UNPACKBRIDLE_PARAM_1;        
   /* Requesting client */
   cm_mm_call_event_f_type *call_event_func = (cm_mm_call_event_f_type *)UNPACKBRIDLE_PARAM_2; 
   /* Pointer to a callback function to notify the client of call events */
   cm_client_event_reg_e_type event_reg_type = (cm_client_event_reg_e_type)UNPACKBRIDLE_PARAM_3;   
   /* register or deregister */
   cm_call_event_e_type from_call_event = (cm_call_event_e_type)UNPACKBRIDLE_PARAM_4;  
   /* register from this event (including) */
   cm_call_event_e_type to_call_event = (cm_call_event_e_type)UNPACKBRIDLE_PARAM_5;    
   /* to this event (including) */
   cm_mm_call_cmd_err_f_type *call_cmd_err_func = (cm_mm_call_cmd_err_f_type *)UNPACKBRIDLE_PARAM_6; 
   /* pointer to a callback function to notify the client of call command errors of OTHER clients */
   cm_client_status_e_type     ret;
   CMINST                      *pInst;

   pInst = bridle_cm_check_client(swi, client_id);

   ret = cm_mm_client_call_reg( client_id, bridle_svc_call_event_func, event_reg_type, from_call_event, to_call_event,
                                bridle_svc_call_cmd_err_func );
   if( CM_CLIENT_OK == ret ) {
      if( event_reg_type == CM_CLIENT_EVENT_REG ) {
         pInst->call_event_func = call_event_func;
         pInst->call_cmd_err_func = call_cmd_err_func;
      }
      else {
         pInst->call_event_func = 0;
         pInst->call_cmd_err_func = 0;
      }
   }

   return (uint32)ret;
}

static uint32 unpackbridle_cm_client_ph_reg( uint32 swi, uint32 a1, uint32 a2, uint32 a3, uint32 a4 )
{
   cm_client_id_type           client_id = (cm_client_id_type)UNPACKBRIDLE_PARAM_1;
     /* Requesting client */
   cm_ph_event_f_type          *ph_event_func = (cm_ph_event_f_type *)UNPACKBRIDLE_PARAM_2;
     /* Pointer to a callback function to notify the client of phone events */
   cm_client_event_reg_e_type  event_reg_type = (cm_client_event_reg_e_type)UNPACKBRIDLE_PARAM_3;
     /* register or deregister */
   cm_ph_event_e_type          from_ph_event = (cm_ph_event_e_type)UNPACKBRIDLE_PARAM_4;
     /* register from this event (including) */
   cm_ph_event_e_type          to_ph_event = (cm_ph_event_e_type)UNPACKBRIDLE_PARAM_5;
     /* to this event (including) */
   cm_ph_cmd_err_f_type        *ph_cmd_err_func = (cm_ph_cmd_err_f_type *)UNPACKBRIDLE_PARAM_6;
     /* pointer to a callback function to notify the client of phone command errors of OTHER clients */
   cm_client_status_e_type     ret;
   CMINST                      *pInst;

   pInst = bridle_cm_check_client(swi, client_id);

   ret = cm_client_ph_reg(client_id,bridle_svc_ph_event_func,event_reg_type,from_ph_event,to_ph_event,bridle_svc_ph_cmd_err_func);
   if( CM_CLIENT_OK == ret ) {
      if( event_reg_type == CM_CLIENT_EVENT_REG ) {
         pInst->ph_event_func = ph_event_func;
         pInst->ph_cmd_err_func = ph_cmd_err_func;
      }
      else {
         pInst->ph_event_func = 0;
         pInst->ph_cmd_err_func = 0;
      }
   }

   return (uint32)ret;
}

static uint32 unpackbridle_cm_mm_client_ss_reg( uint32 swi, uint32 a1, uint32 a2, uint32 a3, uint32 a4 )
{
   cm_client_status_e_type    ret;
   cm_client_id_type           client_id = (cm_client_id_type)UNPACKBRIDLE_PARAM_1;
   /* Requesting client */
   cm_mm_ss_event_f_type       *ss_event_func = (cm_mm_ss_event_f_type *)UNPACKBRIDLE_PARAM_2;
   /* Pointer to a callback function to notify the client of serving system
       ** events */
   cm_client_event_reg_e_type  event_reg_type = (cm_client_event_reg_e_type)UNPACKBRIDLE_PARAM_3;
   /* register or deregister */
   cm_ss_event_e_type          from_ss_event = (cm_ss_event_e_type)UNPACKBRIDLE_PARAM_4;
   /* register from this event (including) */
   cm_ss_event_e_type          to_ss_event = (cm_ss_event_e_type)UNPACKBRIDLE_PARAM_5;
   /* to this event (including) */
   cm_ss_cmd_err_f_type        *ss_cmd_err_func = (cm_ss_cmd_err_f_type *)UNPACKBRIDLE_PARAM_6;
   /* pointer to a callback function to notify the client of serving system
       ** command errors of OTHER clients */
   CMINST                      *pInst;

   pInst = bridle_cm_check_client(swi,client_id);

   ret = cm_mm_client_ss_reg(client_id,bridle_svc_ss_event_func,event_reg_type,from_ss_event,to_ss_event,bridle_svc_ss_cmd_err_func);
   if( CM_CLIENT_OK == ret ) {
      if( event_reg_type == CM_CLIENT_EVENT_REG ) {
         pInst->ss_event_func = ss_event_func;
         pInst->ss_cmd_err_func = ss_cmd_err_func;
      }
      else {
         pInst->ss_event_func = 0;
         pInst->ss_cmd_err_func = 0;
      }
   }

   return (uint32)ret;
}

static uint32 unpackbridle_cm_mm_client_inband_reg( uint32 swi, uint32 a1, uint32 a2, uint32 a3, uint32 a4 )
{

   cm_client_id_type               client_id = (cm_client_id_type)UNPACKBRIDLE_PARAM_1;
     /* Requesting client */

   cm_inband_event_f_type          *inband_event_func = (cm_inband_event_f_type *)UNPACKBRIDLE_PARAM_2;
     /* Pointer to a callback function to notify the client of inband
     ** events */

   cm_client_event_reg_e_type      event_reg_type = (cm_client_event_reg_e_type)UNPACKBRIDLE_PARAM_3;
     /* register or deregister */

   cm_inband_event_e_type          from_inband_event = (cm_inband_event_e_type)UNPACKBRIDLE_PARAM_4;
     /* register from this event (including) */

   cm_inband_event_e_type          to_inband_event = (cm_inband_event_e_type)UNPACKBRIDLE_PARAM_5;
     /* to this event (including) */

   cm_mm_inband_cmd_err_f_type     *inband_cmd_err_func = (cm_mm_inband_cmd_err_f_type *)UNPACKBRIDLE_PARAM_6;
     /* pointer to a callback function to notify the client of inband
     ** command errors of OTHER clients */
   cm_client_status_e_type         ret;
   CMINST                          *pInst;

   pInst = bridle_cm_check_client(swi,client_id);

   ret = cm_mm_client_inband_reg(client_id,bridle_svc_inband_event_func,event_reg_type,from_inband_event,to_inband_event,bridle_svc_inband_cmd_err_func);
   if( CM_CLIENT_OK == ret ) {
      if( event_reg_type == CM_CLIENT_EVENT_REG ) {
         pInst->inband_event_func = inband_event_func;
         pInst->inband_cmd_err_func = inband_cmd_err_func;
      }
      else {
         pInst->inband_event_func = 0;
         pInst->inband_cmd_err_func = 0;
      }
   }

   return (uint32)ret;
}

static uint32 unpackbridle_cm_client_release( uint32 swi, uint32 a1, uint32 a2, uint32 a3, uint32 a4 )
{
   cm_client_id_type client_id = (cm_client_id_type)UNPACKBRIDLE_PARAM_1;
     /* Client ID pointer*/
   cm_client_status_e_type ret;
   CMINST *pInst;

   pInst = bridle_cm_check_client(swi, client_id);

   ret = cm_client_release(client_id);

   if( CM_CLIENT_OK == ret ) {
      ZEROAT(pInst);
   }

   return (uint32)ret;
}

static void bridle_svc_call_event_func( cm_call_event_e_type call_event, const cm_mm_call_info_s_type *call_info_ptr )
{
   CMINST *pInst = &bridle_client_inst;
   if( pInst->bInit && pInst->call_event_func ) {
      pInst->call_info = *call_info_ptr;
      BRIDLE_USER_VOID_2( pInst->call_event_func, call_event, &pInst->call_info );
   }
}

static void bridle_svc_call_cmd_err_func( cm_call_id_type call_id, cm_client_id_type client_id, cm_call_cmd_e_type cmd, 
                                          cm_call_cmd_err_e_type cmd_err )
{
   CMINST *pInst = &bridle_client_inst;
   
   if( pInst->bInit && pInst->call_cmd_err_func ) {
      BRIDLE_USER_VOID_4( pInst->call_cmd_err_func, call_id, client_id, cmd, cmd_err );
   }
}

static void bridle_svc_ph_event_func( cm_ph_event_e_type ph_event, const cm_ph_info_s_type *ph_info_ptr )
{
   CMINST *pInst = &bridle_client_inst;

   if( pInst->bInit && pInst->ph_event_func ) {
      pInst->ph_info = *ph_info_ptr;
      BRIDLE_USER_VOID_2( pInst->ph_event_func, ph_event, &pInst->ph_info );
   }
}

static void bridle_svc_ph_cmd_err_func( cm_client_id_type client_id, cm_ph_cmd_e_type cmd, cm_ph_cmd_err_e_type cmd_err )
{
   CMINST *pInst = &bridle_client_inst;

   if( pInst->bInit && pInst->ph_cmd_err_func ) {
      BRIDLE_USER_VOID_3( pInst->ph_cmd_err_func, client_id, cmd, cmd_err );
   }
}

static void bridle_svc_ss_event_func( cm_ss_event_e_type ss_event, const cm_mm_ss_info_s_type *ss_info_ptr )
{
   CMINST *pInst = &bridle_client_inst;

   if( pInst->bInit && pInst->ss_event_func ) {
      pInst->ss_info = *ss_info_ptr;
      BRIDLE_USER_VOID_2( pInst->ss_event_func, ss_event, &pInst->ss_info );
   }
}

static void bridle_svc_ss_cmd_err_func( cm_client_id_type client_id, cm_ss_cmd_e_type cmd, cm_ss_cmd_err_e_type cmd_err )
{
   CMINST *pInst = &bridle_client_inst;

   if( pInst->bInit && pInst->ss_cmd_err_func ) {
      BRIDLE_USER_VOID_3( pInst->ss_cmd_err_func, client_id, cmd, cmd_err );
   }
}

static void bridle_svc_inband_event_func( cm_inband_event_e_type inband_event, const cm_inband_info_s_type *inband_info_ptr )
{
   CMINST *pInst = &bridle_client_inst;

   if( pInst->bInit && pInst->inband_event_func ) {
      pInst->inband_info = *inband_info_ptr;
      BRIDLE_USER_VOID_2( pInst->inband_event_func, inband_event, &pInst->inband_info );
   }
}

static void bridle_svc_inband_cmd_err_func( cm_call_id_type call_id, cm_client_id_type client_id, cm_inband_cmd_e_type cmd,
                                            cm_inband_cmd_err_e_type cmd_err )
{
   CMINST *pInst = &bridle_client_inst;

   if( pInst->bInit && pInst->inband_cmd_err_func ) {
      BRIDLE_USER_VOID_4( pInst->inband_cmd_err_func, call_id, client_id, cmd, cmd_err );
   }
}

