]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - apps/tidep0084.git/blob - example/collector/api_mac_proto.c
Updated to use the latest TI 15.4-Stack v2.1.0 from the SimpleLink CC13x0 SDK v1.30.
[apps/tidep0084.git] / example / collector / api_mac_proto.c
1 /******************************************************************************
2  @file api_mac_proto.c
4  @brief TIMAC 2.0 API Convert the items in the api_mac.h file (implimentation)
6  Group: WCS LPC
7  $Target Devices: Linux: AM335x, Embedded Devices: CC1310, CC1350$
9  ******************************************************************************
10  $License: BSD3 2016 $
11   
12    Copyright (c) 2015, Texas Instruments Incorporated
13    All rights reserved.
14   
15    Redistribution and use in source and binary forms, with or without
16    modification, are permitted provided that the following conditions
17    are met:
18   
19    *  Redistributions of source code must retain the above copyright
20       notice, this list of conditions and the following disclaimer.
21   
22    *  Redistributions in binary form must reproduce the above copyright
23       notice, this list of conditions and the following disclaimer in the
24       documentation and/or other materials provided with the distribution.
25   
26    *  Neither the name of Texas Instruments Incorporated nor the names of
27       its contributors may be used to endorse or promote products derived
28       from this software without specific prior written permission.
29   
30    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
31    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
32    THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
33    PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
34    CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
35    EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
36    PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
37    OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
38    WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
39    OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
40    EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41  ******************************************************************************
42  $Release Name: TI-15.4Stack Linux x64 SDK ENG$
43  $Release Date: Mar 08, 2017 (2.01.00.10)$
44  *****************************************************************************/
46 #include "log.h"
48 #include "api_mac.h"
49 #include "api_mac.pb-c.h"
50 #include "api_mac_proto.h"
51 #include "malloc.h"
53 /* common function */
54 static uint64_t copy_ApiMac_sAddrExt(const ApiMac_sAddrExt_t pThis)
55 {
56     uint64_t v,a;
57     int x;
59     v = 0;
61     for(x = 0 ; x < APIMAC_SADDR_EXT_LEN ; x++)
62     {
63         a = pThis[x];
64         a = a << (x * 8);
65         v = v | a;
66     }
67     return v;
68 }
70 /* Free the device descriptor.
71  * Public function defined in api_mac_proto.h
72  */
73 void free_ApiMacDeviceDescriptor(ApiMacDeviceDescriptor *pThis)
74 {
75     if(pThis)
76     {
77         free((void*)(pThis));
78     }
79 }
81 /* Free the capability info
82  * Public function defined in api_mac_proto.h
83  */
84 void free_ApiMacCapabilityInfo(ApiMacCapabilityInfo *pThis)
85 {
86     if(pThis)
87     {
88         free((void*)(pThis));
89     }
90 }
92 /* convert the device descriptor
93  * Public function defined in api_mac_proto.h
94  */
95 ApiMacDeviceDescriptor *copy_ApiMac_deviceDescriptor(
96     const ApiMac_deviceDescriptor_t *pThis)
97 {
98     ApiMacDeviceDescriptor *pResult;
100     pResult = (ApiMacDeviceDescriptor *)calloc(1,sizeof(*pResult));
101     if(!pResult)
102     {
103         LOG_printf(LOG_ERROR, "No memory for: ApiMacDeviceDescriptor\n");
104     }
105     else
106     {
107         api_mac_device_descriptor__init(pResult);
108         pResult->panid = pThis->panID;
109         pResult->shortaddress = pThis->shortAddress;
110         pResult->extaddress   = copy_ApiMac_sAddrExt(pThis->extAddress);
111     }
112     return pResult;
115 /* convert the capabiity info
116  * Public function defined in api_mac_proto.h
117  */
118 ApiMacCapabilityInfo   *copy_ApiMac_capabilityInfo(
119     const ApiMac_capabilityInfo_t *pThis)
121     ApiMacCapabilityInfo   *pResult;
123     pResult = (ApiMacCapabilityInfo *)calloc(1,sizeof(*pResult));
124     if(!pResult)
125     {
126         LOG_printf(LOG_ERROR, "No memory for: ApiMacCapabilityInfo\n");
127     }
128     else
129     {
130         api_mac_capability_info__init(pResult);
131         pResult->pancoord = pThis->panCoord;
132         pResult->ffd = pThis->ffd;
133         pResult->mainspower = pThis->mainsPower;
134         pResult->rxonwhenidle = pThis->rxOnWhenIdle;
135         pResult->security = pThis->security;
136         pResult->allocaddr = pThis->allocAddr;
137     }
138     return pResult;
141 /* release memory for the Saddr
142  * Public function defined in api_mac_proto.h
143  */
144 void free_ApiMacSAddr(ApiMacSAddr *pThis)
146     if(pThis)
147     {
148         free((void *)(pThis));
149     }
152 /* Copy a Saddr
153  * Public function defined in api_mac_proto.h
154  */
155 ApiMacSAddr *copy_ApiMac_sAddr(const ApiMac_sAddr_t *pThis)
157     ApiMacSAddr *pResult;
159     pResult = calloc(1,sizeof(*pResult));
161     if(pResult == NULL)
162     {
163         LOG_printf(LOG_ERROR,"No memory for: ApiMacSAddr\n");
164         return pResult;
165     }
167     api_mac_s_addr__init(pResult);
169     switch(pThis->addrMode)
170     {
171     case ApiMac_addrType_none:
172         pResult->addrmode = API_MAC_ADDR_TYPE__ApiMac_addrType_none;
173         break;
174     case ApiMac_addrType_short:
175         pResult->addrmode = API_MAC_ADDR_TYPE__ApiMac_addrType_short;
176         pResult->shortaddr = pThis->addr.shortAddr;
177         break;
178     case ApiMac_addrType_extended:
179         pResult->addrmode = API_MAC_ADDR_TYPE__ApiMac_addrType_extended;
180         pResult->extaddr = copy_ApiMac_sAddrExt(pThis->addr.extAddr);
181         break;
182     }
184     return pResult;
188 /*
189  *  ========================================
190  *  Texas Instruments Micro Controller Style
191  *  ========================================
192  *  Local Variables:
193  *  mode: c
194  *  c-file-style: "bsd"
195  *  tab-width: 4
196  *  c-basic-offset: 4
197  *  indent-tabs-mode: nil
198  *  End:
199  *  vim:set  filetype=c tabstop=4 shiftwidth=4 expandtab=true
200  */