view src/g23m-gprs/sm/sm_aci_output_handler.c @ 220:0ed36de51973

ABB semaphore protection overhaul The ABB semaphone protection logic that came with TCS211 from TI was broken in several ways: * Some semaphore-protected functions were called from Application_Initialize() context. NU_Obtain_Semaphore() called with NU_SUSPEND fails with NU_INVALID_SUSPEND in this context, but the return value wasn't checked, and NU_Release_Semaphore() would be called unconditionally at the end. The latter call would increment the semaphore count past 1, making the semaphore no longer binary and thus no longer effective for resource protection. The fix is to check the return value from NU_Obtain_Semaphore() and skip the NU_Release_Semaphore() call if the semaphore wasn't properly obtained. * Some SPI hardware manipulation was being done before entering the semaphore- protected critical section. The fix is to reorder the code: first obtain the semaphore, then do everything else. * In the corner case of L1/DSP recovery, l1_abb_power_on() would call some non-semaphore-protected ABB & SPI init functions. The fix is to skip those calls in the case of recovery. * A few additional corner cases existed, all of which are fixed by making ABB semaphore protection 100% consistent for all ABB functions and code paths. There is still one remaining problem of priority inversion: suppose a low- priority task calls an ABB function, and some medium-priority task just happens to preempt right in the middle of that semaphore-protected ABB operation. Then the high-priority SPI task is locked out for a non-deterministic time until that medium-priority task finishes its work and goes back to sleep. This priority inversion problem remains outstanding for now.
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 26 Apr 2021 20:55:25 +0000
parents fa8dc04885d8
children
line wrap: on
line source

/*----------------------------------------------------------------------------
|  Project :  3G PS
|  Module  :  SM
+-----------------------------------------------------------------------------
|             Copyright 2003 Texas Instruments.
|             All rights reserved. 
| 
|             This file is confidential and a trade secret of Texas 
|             Instruments .
|             The receipt of or possession of this file does not convey 
|             any rights to reproduce or disclose its contents or to 
|             manufacture, use, or sell anything it may describe, in 
|             whole, or in part, without the specific written consent of 
|             Texas Instruments. 
+-----------------------------------------------------------------------------
| Purpose:    Output functions for primitives from SM to the ACI entity.
|             For design details, see:
|             8010.908 SM Detailed Specification
+---------------------------------------------------------------------------*/

/*==== DECLARATION CONTROL =================================================*/

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

#include "sm.h"

#include "sm_aci_output_handler.h"
#include "sm_qos.h"

/*==== CONSTS ===============================================================*/

/*==== TYPES ================================================================*/

/*==== LOCALS ===============================================================*/

/*==== PUBLIC FUNCTIONS =====================================================*/

/*
+------------------------------------------------------------------------------
| Function    : send_smreg_pdp_activate_cnf
+------------------------------------------------------------------------------
| Description : Allocate, pack and send SMREG_PDP_ACTIVATE_CNF primitive.
|
| Parameters  : context   - Pointer to context structure
+------------------------------------------------------------------------------
*/
void send_smreg_pdp_activate_cnf(struct T_SM_CONTEXT_DATA *context)
{
  U16  pco_len;
  (void)TRACE_FUNCTION("send_smreg_pdp_activate_cnf");

  pco_len = (context->negotiated_pco != NULL
	     ? (U16)context->negotiated_pco->c_pco_value
	     : (U16)0);

  {
    U16 pco_bit_len = pco_len << 3;
    PALLOC_SDU(prim, SMREG_PDP_ACTIVATE_CNF, pco_bit_len);

    if (prim != NULL) {
      prim->nsapi               = context->nsapi;
      prim->pdp_type            = context->pdp_type;
      sm_qos_copy_from_sm(&prim->qos, &context->accepted_qos, &prim->ctrl_qos);
      memcpy(&prim->comp_params, &context->comp_params, sizeof(T_NAS_comp_params));
      prim->ctrl_ip_address     = context->negotiated_address.ctrl_ip_address;
      memcpy(&prim->ip_address, &context->negotiated_address.ip_address, sizeof(T_NAS_ip_address));
      if (pco_len > 0 && context->negotiated_pco != NULL) {
	U16 offset = prim->sdu.o_buf >> 3;
	/* sdu.o_buf and sdu.l_buf already by PALLOC_SDU macro above! */
	memcpy(&prim->sdu.buf[offset], context->negotiated_pco->pco_value,
               (size_t)pco_len);
      } else {
	prim->sdu.l_buf = 0;
      }

      (void)PSEND(hCommACI, prim);
    } else {
      (void)TRACE_ERROR("Unable to allocate SMREG_PDP_ACTIVATE_CNF primitive!");
    }
  }
}

/*
+------------------------------------------------------------------------------
| Function    : send_smreg_pdp_activate_ind
+------------------------------------------------------------------------------
| Description : Allocate, pack and send SMREG_PDP_ACTIVATE_IND primitive.
|
| Parameters  : context   - Pointer to context structure
+------------------------------------------------------------------------------
*/
void send_smreg_pdp_activate_ind(struct T_SM_CONTEXT_DATA *context)
{
  (void)TRACE_FUNCTION("send_smreg_pdp_activate_ind");

  {
    PALLOC(prim, SMREG_PDP_ACTIVATE_IND);

    prim->ti                  = context->ti;
    prim->pdp_type            = context->pdp_type;
    prim->ctrl_ip_address     = context->negotiated_address.ctrl_ip_address;
    memcpy(&prim->ip_address, &context->negotiated_address.ip_address, sizeof(T_NAS_ip_address));
    if (context->apn != NULL) { /* NOTE: *MUST* be present acc to 3G 24.008, but just in case... */
      memcpy(&prim->apn, context->apn, sizeof(T_SMREG_apn));
    } else {
      prim->apn.c_apn_buf = (U8)0;
    }

    (void)PSEND(hCommACI, prim);
  }
}

/*
+------------------------------------------------------------------------------
| Function    : send_smreg_pdp_activate_rej
+------------------------------------------------------------------------------
| Description : Allocate, pack and send SMREG_PDP_ACTIVATE_REJ primitive.
|
| Parameters  : context   - Pointer to context structure
+------------------------------------------------------------------------------
*/
void send_smreg_pdp_activate_rej(U8 nsapi, T_CAUSE_ps_cause *cause)
{
  (void)TRACE_FUNCTION("send_smreg_pdp_activate_rej");

  {
    PALLOC(prim, SMREG_PDP_ACTIVATE_REJ);

    prim->nsapi               = nsapi;
    prim->ps_cause.ctrl_value = cause->ctrl_value;
    prim->ps_cause.value      = cause->value;

    (void)PSEND(hCommACI, prim);
  }
}

/*
+------------------------------------------------------------------------------
| Function    : send_smreg_pdp_activate_sec_cnf
+------------------------------------------------------------------------------
| Description : Allocate, pack and send SMREG_PDP_ACTIVATE_SEC_CNF primitive.
|
| Parameters  : context   - Pointer to context structure
+------------------------------------------------------------------------------
*/
void send_smreg_pdp_activate_sec_cnf(struct T_SM_CONTEXT_DATA *context)
{
  (void)TRACE_FUNCTION("send_smreg_pdp_activate_sec_cnf");

  {
    PALLOC(prim, SMREG_PDP_ACTIVATE_SEC_CNF);

    prim->nsapi               = context->nsapi;

    sm_qos_copy_from_sm(&prim->qos, &context->accepted_qos, &prim->ctrl_qos);

    (void)PSEND(hCommACI, prim);
  }
}

/*
+------------------------------------------------------------------------------
| Function    : send_smreg_pdp_activate_sec_rej
+------------------------------------------------------------------------------
| Description : Allocate, pack and send SMREG_PDP_ACTIVATE_SEC_REJ primitive.
|
| Parameters  : nsapi          - Context identifier
|               cause          - Rejection cause
+------------------------------------------------------------------------------
*/
void send_smreg_pdp_activate_sec_rej(U8 nsapi, T_CAUSE_ps_cause *cause)
{
  (void)TRACE_FUNCTION("send_smreg_pdp_activate_sec_rej");

  {
    PALLOC(prim, SMREG_PDP_ACTIVATE_SEC_REJ);
    
    prim->nsapi               = nsapi;
    prim->ps_cause.ctrl_value = cause->ctrl_value;
    prim->ps_cause.value      = cause->value;

    (void)PSEND(hCommACI, prim);
  }
}

/*
+------------------------------------------------------------------------------
| Function    : send_smreg_pdp_deactivate_cnf
+------------------------------------------------------------------------------
| Description : Allocate, pack and send SMREG_PDP_DEACTIVATE_CNF primitive.
|
| Parameters  : nsapi_set - Set of NSAPIs successfully deactivated
+------------------------------------------------------------------------------
*/
void send_smreg_pdp_deactivate_cnf(U16 nsapi_set)
{
  (void)TRACE_FUNCTION("send_smreg_pdp_deactivate_cnf");

  {
    PALLOC(prim, SMREG_PDP_DEACTIVATE_CNF);

    prim->nsapi_set           = nsapi_set;

    (void)PSEND(hCommACI, prim);
  }
}

/*
+------------------------------------------------------------------------------
| Function    : send_smreg_pdp_deactivate_ind
+------------------------------------------------------------------------------
| Description : Allocate, pack and send SMREG_PDP_DEACTIVATE_IND primitive.
|
| Parameters  : nsapi_set - Set of NSAPIs being deactivated
|               cause     - Reason for deactivation
+------------------------------------------------------------------------------
*/
void send_smreg_pdp_deactivate_ind(U16 nsapi_set, T_CAUSE_ps_cause *cause)
{
  (void)TRACE_FUNCTION("send_smreg_pdp_deactivate_ind");

  {
    PALLOC(prim, SMREG_PDP_DEACTIVATE_IND);

    prim->nsapi_set           = nsapi_set;
    prim->ps_cause.ctrl_value = cause->ctrl_value;
    prim->ps_cause.value      = cause->value;

    (void)PSEND(hCommACI, prim);
  }
}

/*
+------------------------------------------------------------------------------
| Function    : send_smreg_pdp_modify_cnf
+------------------------------------------------------------------------------
| Description : Allocate, pack and send SMREG_PDP_MODIFY_CNF primitive.
|
| Parameters  : None
+------------------------------------------------------------------------------
*/
void send_smreg_pdp_modify_cnf(struct T_SM_CONTEXT_DATA *context,
			       T_SM_UPDATE_FLAGS update_flags)
{
  (void)TRACE_FUNCTION("send_smreg_pdp_modify_cnf");

  {
    PALLOC(prim, SMREG_PDP_MODIFY_CNF);
    
    prim->nsapi               = context->nsapi;

    if ((update_flags & SM_UPDATE_QOS) != (T_SM_UPDATE_FLAGS)0) {
      sm_qos_copy_from_sm(&prim->qos, &context->accepted_qos, &prim->ctrl_qos);
    } else {
      prim->ctrl_qos          = PS_is_qos_not_present;
    }

    (void)PSEND(hCommACI, prim);
  }
}

/*
+------------------------------------------------------------------------------
| Function    : send_smreg_pdp_modify_ind
+------------------------------------------------------------------------------
| Description : Allocate, pack and send SMREG_PDP_MODIFY_IND primitive.
|
| Parameters  : None
+------------------------------------------------------------------------------
*/
void send_smreg_pdp_modify_ind(struct T_SM_CONTEXT_DATA *context,
			       T_SM_UPDATE_FLAGS update_flags)
{
  (void)TRACE_FUNCTION("send_smreg_pdp_modify_ind");

  {
    PALLOC(prim, SMREG_PDP_MODIFY_IND);
      
    prim->nsapi               = context->nsapi;

    if ((int)(update_flags & SM_UPDATE_QOS) != 0) {
      sm_qos_copy_from_sm(&prim->qos, &context->accepted_qos, &prim->ctrl_qos);
    } else {
      prim->ctrl_qos          = PS_is_qos_not_present;
    }

    if ((int)(update_flags & SM_UPDATE_ADDRESS) != 0) {
      prim->ctrl_ip_address   = context->negotiated_address.ctrl_ip_address;
      memcpy(&prim->ip_address, &context->negotiated_address.ip_address, sizeof(T_NAS_ip_address));
    } else {
      prim->ctrl_ip_address   = NAS_is_ip_not_present;
    }

    (void)PSEND(hCommACI, prim);
  }
}

/*
+------------------------------------------------------------------------------
| Function    : send_smreg_pdp_modify_ind_multiple
+------------------------------------------------------------------------------
| Description : Allocate, pack and send SMREG_PDP_MODIFY_IND primitives for
|               several NSAPIs.
|
| Parameters  : None
+------------------------------------------------------------------------------
*/
void send_smreg_pdp_modify_ind_multiple(U16 nsapi_set,
					T_SM_UPDATE_FLAGS update_flags)
{
  int nsapi;

  (void)TRACE_FUNCTION("send_smreg_pdp_modify_ind_multiple");

  for (nsapi = (int)NAS_NSAPI_5;
       nsapi < NAS_SIZE_NSAPI && sm_is_nsapi_in_nsapi_set(nsapi, nsapi_set);
       nsapi++)
  {
    struct T_SM_CONTEXT_DATA *context;

    context = sm_get_context_data_from_nsapi(nsapi);
    if (context != NULL)
    {
      PALLOC(prim, SMREG_PDP_MODIFY_IND);
    
      prim->nsapi               = context->nsapi;

      if ((update_flags & SM_UPDATE_QOS_DOWNGRADE) != (T_SM_UPDATE_FLAGS)0) {
	sm_qos_copy_from_sm(&prim->qos, &context->accepted_qos, &prim->ctrl_qos);
	/* QoS downgraded to 0kbps */
	prim->qos.qos_r99.max_rate_ul = 0;
	prim->qos.qos_r99.max_rate_dl = 0;
      } else {
	prim->ctrl_qos          = PS_is_qos_not_present;
      }

      /* IP address is not changed/set using this function */
      prim->ctrl_ip_address   = NAS_is_ip_not_present;

      (void)PSEND(hCommACI, prim);
    } /* if */
  } /* for */
}

/*
+------------------------------------------------------------------------------
| Function    : send_smreg_pdp_modify_rej
+------------------------------------------------------------------------------
| Description : Allocate, pack and send SMREG_PDP_MODIFY_REJ primitive.
|
| Parameters  : None
+------------------------------------------------------------------------------
*/
void send_smreg_pdp_modify_rej(U8 nsapi, T_CAUSE_ps_cause *cause)
{
  (void)TRACE_FUNCTION("send_smreg_pdp_modify_rej");

  {
    PALLOC(prim, SMREG_PDP_MODIFY_REJ);

    prim->nsapi               = nsapi;
    prim->ps_cause.ctrl_value = cause->ctrl_value;
    prim->ps_cause.value      = cause->value;

    (void)PSEND(hCommACI, prim);
  }
}

/*==== END OF FILE ==========================================================*/