view src/g23m-aci/aci/psa_ppps.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 :  GSM-PS (6147)
|  Modul   :  PSA_PPPS
+----------------------------------------------------------------------------- 
|  Copyright 2002 Texas Instruments Berlin, AG 
|                 All rights reserved. 
| 
|                 This file is confidential and a trade secret of Texas 
|                 Instruments Berlin, AG 
|                 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 Berlin, AG. 
+----------------------------------------------------------------------------- 
|  Purpose :  
+----------------------------------------------------------------------------- 
*/ 

#ifdef DTI

#if defined (FF_WAP) || defined (FF_PPP) || defined (FF_GPF_TCPIP) || defined (FF_SAT_E)

#ifndef PSA_PPPS_C
#define PSA_PPPS_C
#endif  /* PSA_PPPS_C */

#include "aci_all.h"
/*==== INCLUDES ===================================================*/
#include "aci_cmh.h"
#include "ati_cmd.h"
#include "aci_cmd.h"
#include "dti.h"      /* functionality of the dti library */
#include "dti_conn_mng.h"

#include "aci_fd.h"
#include "aci.h"
#include "psa.h"
#include "psa_l2r.h"
#include "cmh.h"
#include "cmh_ra.h"
#include "cmh_l2r.h"

#include "wap_aci.h"
#include "psa_ppp_w.h"

#include "dcm_f.h"

/*==== CONSTANTS ==================================================*/


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

/*==== EXPORT =====================================================*/

/*==== VARIABLES ==================================================*/


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

/*
+-------------------------------------------------------------------+
| PROJECT : GSM-PS (6147)         MODULE  : PSA_PPP                 |
|                                 ROUTINE : psaPPP_Establish        |
+-------------------------------------------------------------------+

  PURPOSE : This function sends an PPP_ESTABLISH_REQ.

*/

GLOBAL void psaPPP_Establish(T_DTI_CONN_LINK_ID link_id, UBYTE peer)
{
  T_login pLogin;

  TRACE_FUNCTION("psaPPP_Establish()");

  if( (is_gpf_tcpip_call() GPF_TCPIP_STATEMENT(AND (peer EQ DTI_ENTITY_TCPIP))) OR
       peer EQ DTI_ENTITY_IP OR peer EQ DTI_ENTITY_AAA OR peer EQ DTI_ENTITY_PSI)
  {
    prot_link_id  = link_id;
    prot_entity_id = peer;
  }
  else if (peer EQ DTI_ENTITY_L2R)
  {
    peer_link_id  = link_id;
  }
  else
  {
    TRACE_EVENT("wrong peer entity");
  }

#ifdef FF_WAP
  rAT_WAP_start_login();
#endif /* FF_WAP */

  if (pppShrdPrm.state NEQ PPP_ESTABLISH)
  {
    /* wait for the second call of psaPPP_Establish() */
    pppShrdPrm.state = PPP_ESTABLISH;
    return;
  }
  /* Set the unused bytes of login and password to zero */
  memset(&pLogin, 0x00, sizeof( T_login ));
  pLogin.name_len = strlen(pppShrdPrm.ppp_login);
  memcpy((char*)(pLogin.name),pppShrdPrm.ppp_login, pLogin.name_len);
  pLogin.password_len = strlen(pppShrdPrm.ppp_password);
  memcpy((char*)(pLogin.password),
         pppShrdPrm.ppp_password,
         pLogin.password_len);

  {
    PALLOC(ppp_establish_req, PPP_ESTABLISH_REQ);

    ppp_establish_req -> mode   = PPP_CLIENT;
    ppp_establish_req -> mru    = PPP_MRU_DEFAULT;
    ppp_establish_req -> ap     = pppShrdPrm.auth_prot;

    /* Copy user and password */
    memcpy( &(ppp_establish_req->login),&pLogin, sizeof( T_login ));

    ppp_establish_req -> accm   = PPP_ACCM_DEFAULT;
    ppp_establish_req -> rt     = PPP_RT_DEFAULT;
    ppp_establish_req -> mc     = PPP_MC_DEFAULT;
    ppp_establish_req -> mt     = PPP_MT_DEFAULT;
    ppp_establish_req -> mf     = PPP_MF_DEFAULT;
    ppp_establish_req -> ppp_hc = PPP_HC_OFF;
    ppp_establish_req -> ip     = PPP_IP_DYNAMIC;
    ppp_establish_req -> dns1   = PPP_DNS1_DYNAMIC;
    ppp_establish_req -> dns2   = PPP_DNS2_DYNAMIC;

    strcpy((char*)ppp_establish_req->peer_channel.peer_entity, 
            dti_entity_name[DTI_ENTITY_L2R].name);

    strcpy((char*)ppp_establish_req->protocol_channel.protocol_entity, 
            dti_entity_name[prot_entity_id].name);

    ppp_establish_req -> peer_link_id = peer_link_id;
    ppp_establish_req -> prot_link_id = prot_link_id;

    /* Direction for the Protocol Layer */
    ppp_establish_req -> peer_direction = DTI_CHANNEL_TO_LOWER_LAYER;

    /* Direction for the Peer Layer     */
    ppp_establish_req -> prot_direction = DTI_CHANNEL_TO_HIGHER_LAYER;
    
    PSENDX(PPP,ppp_establish_req);
  }
}

/*
+-------------------------------------------------------------------+
| PROJECT : GSM-PS (6147)         MODULE  : PSA_PPP                 |
|                                 ROUTINE : psaPPP_Terminate        |
+-------------------------------------------------------------------+

  PURPOSE :

*/

GLOBAL void psaPPP_Terminate(T_ACI_PPP_LOWER_LAYER ppp_lower_layer)
{

  TRACE_FUNCTION("psaPPP_Terminate()");

  if ((pppShrdPrm.state EQ PPP_TERMINATE) OR (pppShrdPrm.state EQ PPP_TERMINATED))
  {
    return;
  }

  pppShrdPrm.state = PPP_TERMINATE;
  {
    PALLOC(ppp_terminate_req, PPP_TERMINATE_REQ);
    switch (ppp_lower_layer)
    {
    case (UP):
      ppp_terminate_req -> lower_layer = PPP_LOWER_LAYER_UP;
      break;

    case (DWN):
      ppp_terminate_req -> lower_layer = PPP_LOWER_LAYER_DOWN;
      break;

    default:
      TRACE_EVENT("error: status of lower_layer undefined");
    }

    PSENDX(PPP,ppp_terminate_req);
  }
}
#endif /* of FF_WAP or FF_PPP OR FF_GPF_TCPIP or FF_SAT_E */
#endif /* DTI */