Home | History | Annotate | Download | only in snep
      1 /******************************************************************************
      2  *
      3  *  Copyright (C) 2010-2012 Broadcom Corporation
      4  *
      5  *  Licensed under the Apache License, Version 2.0 (the "License");
      6  *  you may not use this file except in compliance with the License.
      7  *  You may obtain a copy of the License at:
      8  *
      9  *  http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  *  Unless required by applicable law or agreed to in writing, software
     12  *  distributed under the License is distributed on an "AS IS" BASIS,
     13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  *  See the License for the specific language governing permissions and
     15  *  limitations under the License.
     16  *
     17  ******************************************************************************/
     18 
     19 /******************************************************************************
     20  *
     21  *  This is the main implementation file for the NFA SNEP.
     22  *
     23  ******************************************************************************/
     24 #include <string.h>
     25 #include "nfa_sys.h"
     26 #include "nfa_sys_int.h"
     27 #include "nfa_snep_int.h"
     28 
     29 /*****************************************************************************
     30 **  Global Variables
     31 *****************************************************************************/
     32 
     33 /* system manager control block definition */
     34 #if NFA_DYNAMIC_MEMORY == FALSE
     35 tNFA_SNEP_CB nfa_snep_cb;
     36 #endif
     37 
     38 /*****************************************************************************
     39 **  Static Functions
     40 *****************************************************************************/
     41 
     42 /* event handler function type */
     43 static BOOLEAN nfa_snep_evt_hdlr (BT_HDR *p_msg);
     44 
     45 /* disable function type */
     46 static void nfa_snep_sys_disable (void);
     47 
     48 /* debug functions type */
     49 #if (BT_TRACE_VERBOSE == TRUE)
     50 static char *nfa_snep_evt_code (UINT16 evt_code);
     51 #endif
     52 
     53 /*****************************************************************************
     54 **  Constants
     55 *****************************************************************************/
     56 static const tNFA_SYS_REG nfa_snep_sys_reg =
     57 {
     58     NULL,
     59     nfa_snep_evt_hdlr,
     60     nfa_snep_sys_disable,
     61     NULL
     62 };
     63 
     64 #define NFA_SNEP_NUM_ACTIONS  (NFA_SNEP_LAST_EVT & 0x00ff)
     65 
     66 /* type for action functions */
     67 typedef BOOLEAN (*tNFA_SNEP_ACTION) (tNFA_SNEP_MSG *p_data);
     68 
     69 /* action function list */
     70 const tNFA_SNEP_ACTION nfa_snep_action[] =
     71 {
     72     nfa_snep_start_default_server,          /* NFA_SNEP_API_START_DEFAULT_SERVER_EVT */
     73     nfa_snep_stop_default_server,           /* NFA_SNEP_API_STOP_DEFAULT_SERVER_EVT  */
     74     nfa_snep_reg_server,                    /* NFA_SNEP_API_REG_SERVER_EVT           */
     75     nfa_snep_reg_client,                    /* NFA_SNEP_API_REG_CLIENT_EVT           */
     76     nfa_snep_dereg,                         /* NFA_SNEP_API_DEREG_EVT                */
     77     nfa_snep_connect,                       /* NFA_SNEP_API_CONNECT_EVT              */
     78     nfa_snep_get_req,                       /* NFA_SNEP_API_GET_REQ_EVT              */
     79     nfa_snep_put_req,                       /* NFA_SNEP_API_PUT_REQ_EVT              */
     80     nfa_snep_get_resp,                      /* NFA_SNEP_API_GET_RESP_EVT             */
     81     nfa_snep_put_resp,                      /* NFA_SNEP_API_PUT_RESP_EVT             */
     82     nfa_snep_disconnect                     /* NFA_SNEP_API_DISCONNECT_EVT           */
     83 };
     84 
     85 /*******************************************************************************
     86 **
     87 ** Function         nfa_snep_init
     88 **
     89 ** Description      Initialize NFA SNEP
     90 **
     91 **
     92 ** Returns          None
     93 **
     94 *******************************************************************************/
     95 void nfa_snep_init (BOOLEAN is_dta_mode)
     96 {
     97     /* initialize control block */
     98     memset (&nfa_snep_cb, 0, sizeof (tNFA_SNEP_CB));
     99     nfa_snep_cb.trace_level = APPL_INITIAL_TRACE_LEVEL;
    100     nfa_snep_cb.is_dta_mode = is_dta_mode;
    101 
    102     SNEP_TRACE_DEBUG1 ("nfa_snep_init (): is_dta_mode=%d", is_dta_mode);
    103 
    104     nfa_snep_default_init ();
    105 
    106     /* register message handler on NFA SYS */
    107     nfa_sys_register (NFA_ID_SNEP,  &nfa_snep_sys_reg);
    108 }
    109 
    110 /*******************************************************************************
    111 **
    112 ** Function         nfa_snep_sys_disable
    113 **
    114 ** Description      Clean up and deregister NFA SNEP from NFA SYS/DM
    115 **
    116 **
    117 ** Returns          None
    118 **
    119 *******************************************************************************/
    120 static void nfa_snep_sys_disable (void)
    121 {
    122     UINT8 xx;
    123 
    124     SNEP_TRACE_DEBUG0 ("nfa_snep_sys_disable ()");
    125 
    126     /* deallocate any buffer and deregister from LLCP */
    127     for (xx = 0; xx < NFA_SNEP_MAX_CONN; xx++)
    128     {
    129         if (nfa_snep_cb.conn[xx].p_cback != NULL)
    130         {
    131             LLCP_Deregister (nfa_snep_cb.conn[xx].local_sap);
    132             nfa_snep_deallocate_cb (xx);
    133         }
    134     }
    135 
    136     /* deregister message handler on NFA SYS */
    137     nfa_sys_deregister (NFA_ID_SNEP);
    138 }
    139 
    140 /*******************************************************************************
    141 **
    142 ** Function         nfa_snep_evt_hdlr
    143 **
    144 ** Description      Processing event for NFA SNEP
    145 **
    146 **
    147 ** Returns          TRUE if p_msg needs to be deallocated
    148 **
    149 *******************************************************************************/
    150 static BOOLEAN nfa_snep_evt_hdlr (BT_HDR *p_hdr)
    151 {
    152     BOOLEAN delete_msg = TRUE;
    153     UINT16  event;
    154 
    155     tNFA_SNEP_MSG *p_msg = (tNFA_SNEP_MSG *) p_hdr;
    156 
    157 #if (BT_TRACE_VERBOSE == TRUE)
    158     SNEP_TRACE_DEBUG1 ("nfa_snep_evt_hdlr (): Event [%s]", nfa_snep_evt_code (p_msg->hdr.event));
    159 #else
    160     SNEP_TRACE_DEBUG1 ("nfa_snep_evt_hdlr(): Event 0x%02x", p_msg->hdr.event);
    161 #endif
    162 
    163     event = p_msg->hdr.event & 0x00ff;
    164 
    165     /* execute action functions */
    166     if (event < NFA_SNEP_NUM_ACTIONS)
    167     {
    168         delete_msg = (*nfa_snep_action[event]) (p_msg);
    169     }
    170     else
    171     {
    172         SNEP_TRACE_ERROR0 ("Unhandled event");
    173     }
    174 
    175     return delete_msg;
    176 }
    177 
    178 
    179 #if (BT_TRACE_VERBOSE == TRUE)
    180 /*******************************************************************************
    181 **
    182 ** Function         nfa_snep_evt_code
    183 **
    184 ** Description
    185 **
    186 ** Returns          string of event
    187 **
    188 *******************************************************************************/
    189 static char *nfa_snep_evt_code (UINT16 evt_code)
    190 {
    191     switch (evt_code)
    192     {
    193     case NFA_SNEP_API_START_DEFAULT_SERVER_EVT:
    194         return "API_START_DEFAULT_SERVER";
    195     case NFA_SNEP_API_STOP_DEFAULT_SERVER_EVT:
    196         return "API_STOP_DEFAULT_SERVER";
    197     case NFA_SNEP_API_REG_SERVER_EVT:
    198         return "API_REG_SERVER";
    199     case NFA_SNEP_API_REG_CLIENT_EVT:
    200         return "API_REG_CLIENT";
    201     case NFA_SNEP_API_DEREG_EVT:
    202         return "API_DEREG";
    203     case NFA_SNEP_API_CONNECT_EVT:
    204         return "API_CONNECT";
    205     case NFA_SNEP_API_GET_REQ_EVT:
    206         return "API_GET_REQ";
    207     case NFA_SNEP_API_PUT_REQ_EVT:
    208         return "API_PUT_REQ";
    209     case NFA_SNEP_API_GET_RESP_EVT:
    210         return "API_GET_RESP";
    211     case NFA_SNEP_API_PUT_RESP_EVT:
    212         return "API_PUT_RESP";
    213     case NFA_SNEP_API_DISCONNECT_EVT:
    214         return "API_DISCONNECT";
    215     default:
    216         return "Unknown event";
    217     }
    218 }
    219 #endif  /* Debug Functions */
    220