• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2012 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 /*
18  *  Import and export general routing data using a XML file.
19  */
20 #pragma once
21 #include "NfcJniUtil.h"
22 #include "nfa_api.h"
23 #include <libxml/parser.h>
24 #include <vector>
25 #include <string>
26 
27 
28 /*****************************************************************************
29 **
30 **  Name:           RouteData
31 **
32 **  Description:    Base class for every kind of route data.
33 **
34 *****************************************************************************/
35 class RouteData
36 {
37 public:
38     enum RouteType {ProtocolRoute, TechnologyRoute};
39     RouteType mRouteType;
40 
41 protected:
RouteData(RouteType routeType)42     RouteData (RouteType routeType) : mRouteType (routeType)
43     {}
44 };
45 
46 
47 
48 
49 /*****************************************************************************
50 **
51 **  Name:           RouteDataForProtocol
52 **
53 **  Description:    Data for protocol routes.
54 **
55 *****************************************************************************/
56 class RouteDataForProtocol : public RouteData
57 {
58 public:
59     int mNfaEeHandle; //for example 0x4f3, 0x4f4
60     bool mSwitchOn;
61     bool mSwitchOff;
62     bool mBatteryOff;
63     tNFA_PROTOCOL_MASK mProtocol;
64 
RouteDataForProtocol()65     RouteDataForProtocol () : RouteData (ProtocolRoute), mNfaEeHandle (NFA_HANDLE_INVALID),
66             mSwitchOn (false), mSwitchOff (false), mBatteryOff (false),
67             mProtocol (0)
68     {}
69 };
70 
71 
72 /*****************************************************************************
73 **
74 **  Name:           RouteDataForTechnology
75 **
76 **  Description:    Data for technology routes.
77 **
78 *****************************************************************************/
79 class RouteDataForTechnology : public RouteData
80 {
81 public:
82     int mNfaEeHandle; //for example 0x4f3, 0x4f4
83     bool mSwitchOn;
84     bool mSwitchOff;
85     bool mBatteryOff;
86     tNFA_TECHNOLOGY_MASK mTechnology;
87 
RouteDataForTechnology()88     RouteDataForTechnology () : RouteData (TechnologyRoute), mNfaEeHandle (NFA_HANDLE_INVALID),
89             mSwitchOn (false), mSwitchOff (false), mBatteryOff (false),
90             mTechnology (0)
91     {}
92 };
93 
94 
95 /*****************************************************************************/
96 /*****************************************************************************/
97 
98 
99 /*****************************************************************************
100 **
101 **  Name:           AidBuffer
102 **
103 **  Description:    Buffer to store AID after converting a string of hex
104 **                  values to bytes.
105 **
106 *****************************************************************************/
107 class AidBuffer
108 {
109 public:
110 
111     /*******************************************************************************
112     **
113     ** Function:        AidBuffer
114     **
115     ** Description:     Parse a string of hex numbers.  Store result in an array of
116     **                  bytes.
117     **                  aid: string of hex numbers.
118     **
119     ** Returns:         None.
120     **
121     *******************************************************************************/
122     AidBuffer (std::string& aid);
123 
124 
125     /*******************************************************************************
126     **
127     ** Function:        ~AidBuffer
128     **
129     ** Description:     Release all resources.
130     **
131     ** Returns:         None.
132     **
133     *******************************************************************************/
134     ~AidBuffer ();
135 
136 
buffer()137     UINT8* buffer () {return mBuffer;};
length()138     int length () {return mBufferLen;};
139 
140 private:
141     UINT8* mBuffer;
142     UINT32 mBufferLen;
143 };
144 
145 
146 /*****************************************************************************/
147 /*****************************************************************************/
148 
149 
150 /*****************************************************************************
151 **
152 **  Name:           RouteDataSet
153 **
154 **  Description:    Import and export general routing data using a XML file.
155 **                  See /data/bcm/param/route.xml
156 **
157 *****************************************************************************/
158 class RouteDataSet
159 {
160 public:
161     typedef std::vector<RouteData*> Database;
162     enum DatabaseSelection {DefaultRouteDatabase, SecElemRouteDatabase};
163 
164 
165     /*******************************************************************************
166     **
167     ** Function:        ~RouteDataSet
168     **
169     ** Description:     Release all resources.
170     **
171     ** Returns:         None.
172     **
173     *******************************************************************************/
174     ~RouteDataSet ();
175 
176 
177     /*******************************************************************************
178     **
179     ** Function:        initialize
180     **
181     ** Description:     Initialize resources.
182     **
183     ** Returns:         True if ok.
184     **
185     *******************************************************************************/
186     bool initialize ();
187 
188 
189     /*******************************************************************************
190     **
191     ** Function:        import
192     **
193     ** Description:     Import data from an XML file.  Fill the database.
194     **
195     ** Returns:         True if ok.
196     **
197     *******************************************************************************/
198     bool import ();
199 
200 
201     /*******************************************************************************
202     **
203     ** Function:        getDatabase
204     **
205     ** Description:     Obtain a database of routing data.
206     **                  selection: which database.
207     **
208     ** Returns:         Pointer to database.
209     **
210     *******************************************************************************/
211     Database* getDatabase (DatabaseSelection selection);
212 
213 
214     /*******************************************************************************
215     **
216     ** Function:        saveToFile
217     **
218     ** Description:     Save XML data from a string into a file.
219     **                  routesXml: XML that represents routes.
220     **
221     ** Returns:         True if ok.
222     **
223     *******************************************************************************/
224     static bool saveToFile (const char* routesXml);
225 
226 
227     /*******************************************************************************
228     **
229     ** Function:        loadFromFile
230     **
231     ** Description:     Load XML data from file into a string.
232     **                  routesXml: string to receive XML data.
233     **
234     ** Returns:         True if ok.
235     **
236     *******************************************************************************/
237     static bool loadFromFile (std::string& routesXml);
238 
239 
240     /*******************************************************************************
241     **
242     ** Function:        deleteFile
243     **
244     ** Description:     Delete route data XML file.
245     **
246     ** Returns:         True if ok.
247     **
248     *******************************************************************************/
249     static bool deleteFile ();
250 
251     /*******************************************************************************
252     **
253     ** Function:        printDiagnostic
254     **
255     ** Description:     Print some diagnostic output.
256     **
257     ** Returns:         None.
258     **
259     *******************************************************************************/
260     void printDiagnostic ();
261 
262 private:
263     Database mSecElemRouteDatabase; //routes when NFC service selects sec elem
264     Database mDefaultRouteDatabase; //routes when NFC service deselects sec elem
265     static const char* sConfigFile;
266     static const bool sDebug = false;
267 
268 
269     /*******************************************************************************
270     **
271     ** Function:        deleteDatabase
272     **
273     ** Description:     Delete all routes stored in all databases.
274     **
275     ** Returns:         None.
276     **
277     *******************************************************************************/
278     void deleteDatabase ();
279 
280 
281     /*******************************************************************************
282     **
283     ** Function:        importProtocolRoute
284     **
285     ** Description:     Parse data for protocol routes.
286     **                  element: XML node for one protocol route.
287     **                  database: store data in this database.
288     **
289     ** Returns:         None.
290     **
291     *******************************************************************************/
292     void importProtocolRoute (xmlNodePtr& element, Database& database);
293 
294 
295     /*******************************************************************************
296     **
297     ** Function:        importTechnologyRoute
298     **
299     ** Description:     Parse data for technology routes.
300     **                  element: XML node for one technology route.
301     **                  database: store data in this database.
302     **
303     ** Returns:         None.
304     **
305     *******************************************************************************/
306     void importTechnologyRoute (xmlNodePtr& element, Database& database);
307 };
308 
309