le_data_interface.h

Go to the documentation of this file.
1 
2 
3 /*
4  * ====================== WARNING ======================
5  *
6  * THE CONTENTS OF THIS FILE HAVE BEEN AUTO-GENERATED.
7  * DO NOT MODIFY IN ANY WAY.
8  *
9  * ====================== WARNING ======================
10  */
11 
12 /**
13  * @page c_le_data Data Connection
14  *
15  * @ref le_data_interface.h "API Reference" <br>
16  * @ref le_data_sample <br>
17  *
18  * A data connection is needed for applications that exchange data with devices where SMS messages
19  * are insufficient or not possible. The data connection can be established over a mobile network,
20  * WiFi or a fixed link (e.g., ethernet).
21  *
22  * The data connection service provides a basic API for requesting and releasing a data connection.
23  *
24  * @note This interface does not support a data connection over a fixed link.
25  *
26  * @warning The dependency between the @c cellNetService and @c dataConnectionService has been
27  * removed. A data connection request will no longer ensure that the radio is on, or verify that the
28  * SIM is valid and unlocked.
29  *
30  * @section c_le_data_default Default Data Connection
31  *
32  * Default data connection is obtained using le_data_Request(). Before the data connection is
33  * requested, an application registers a connection state handler using
34  * le_data_AddConnectionStateHandler(). Once the data connection is established, the handler will
35  * be called indicating it's now connected. The interface name is sent only when the data connection
36  * is in connected state. If the state of the data connection changes, then the handler will be
37  * called with the new state. To release a data connection, an application can use le_data_Release().
38  *
39  * The technology of the established connection can be retrieved with le_data_GetTechnology().
40  *
41  * If the default data connection is not currently available when le_data_Request() is called, the
42  * data connection service first ensures all pre-conditions are satisfied (e.g., modem is registered
43  * on the network), before trying to start the data connection.
44  *
45  * If the default data connection is already available when le_data_Request() is called, a new
46  * connection will not be started. Instead, the existing data connection will be used. This happens
47  * if another application also requested the default data connection. This is how multiple
48  * applications can share the same data connection.
49  *
50  * Once an application makes a data connection request, it should monitor the connection state
51  * reported to the registered connection state handler. The application should only try
52  * transmitting data when the state is connected, and should stop transmitting data when the state
53  * is not connected. If the state is not connected, the data connection service will try to
54  * establish or re-establish the connection endlessly until le_data_Release() is called. There's no
55  * need for an application to issue a new connection request.
56  *
57  * The default data connection will not necessarily be released when an application calls
58  * le_data_Release(). The data connection will be released only after le_data_Release() is called by
59  * all applications that previously called le_data_Request().
60  *
61  * @note When using the cellular technology, the data connection service can use a specific cellular
62  * data profile if it has been set with the le_data_SetCellularProfileIndex() API or in the
63  * configuration tree. Otherwise the default cellular profile is used. The profile in use can be
64  * retrieved by le_data_GetCellularProfileIndex(). The profile to use is loaded when the first data
65  * connection is initiated. The cellular data profile can be configured by le_mdc APIs or
66  * cm data tool.
67  *
68  * @section le_data_sample Code sample
69  *
70  * A sample code that implements the establishment of a data connection service can be found in
71  * \b dcsTest.c file (please refer to @ref c_dataConnectionServiceSample page).
72  *
73  * @section c_le_data_routing Data Connection Routing
74  *
75  * @subsection c_le_data_defaultRoute Default Route
76  *
77  * By default, the default route is automatically configured by the data connection service using
78  * the modem parameters when the cellular technology is connected. If an application wishes to
79  * configure its own default route, it should deactivate it in the data connection service by
80  * setting the parameter @c useDefaultRoute to false in the configuration tree (see @ref
81  * c_le_data_configdb):
82  * @verbatim
83  $ config set dataConnectionService:/routing/useDefaultRoute false bool
84  @endverbatim
85  *
86  * @note The default route activation status can be retrieved with le_data_GetDefaultRouteStatus().
87  *
88  * @warning The default route activation status is only read at start-up and the change will only
89  * be effective after a Legato restart.
90  *
91  * A sample code showing how to set the modem default route if it isn't set by the data connection
92  * server is presented below:
93  * @snippet "apps/test/dataConnectionService/dataConnectionServiceRouteTest/dcsRouteTestComp/dcsRouteTest.c" DefaultRoute
94  *
95  * @subsection c_le_data_addRemoveRoute Add or remove a route
96  *
97  * Specific routes can be added for the cellular connection with le_data_AddRoute(), which is
98  * used to route IP packets to a specific address through the data connection service interface.
99  * When the routes are not necessary anymore, they can be removed with le_data_DelRoute().
100  * @code
101  * // Add a route to the 8.8.8.8 IP address for the cellular connection
102  * le_data_AddRoute("8.8.8.8");
103  *
104  * // Remove a route to the 8.8.8.8 IP address for the cellular connection
105  * le_data_DelRoute("8.8.8.8");
106  * @endcode
107  *
108  * @section c_le_data_rank Technology rank
109  *
110  * The technology to use for the default data connection can be chosen by the applications
111  * with an ordered list. If the connection becomes unavailable through a technology, the next
112  * one in the list is used for the default data connection. If the connection is also unavailable
113  * through the last technology of the list, the first technology will be used again.
114  * The default sequence is @ref LE_DATA_WIFI at rank #1 and @ref LE_DATA_CELLULAR at rank #2.
115  *
116  * @note
117  * - Only one list is available and therefore only one application should set the technology
118  * preferences for the default data connection.
119  * - The list should not be modified while the default data connection is established.
120  * .
121  *
122  *
123  * - le_data_SetTechnologyRank() sets the rank of the technology to use for the data connection
124  * service.
125  * le_data_SetTechnologyRank() inserts a technology into a list, so all the technologies
126  * previously set with ranks @c r and @c r+n are automatically shifted to ranks @c r+1
127  * and @c r+n+1. Technologies with ranks under @c r are not impacted. If the technology is already
128  * in the list, it is removed from its current rank and added to the new rank.
129  *
130  * - le_data_GetFirstUsedTechnology() and le_data_GetNextUsedTechnology() let you retrieve
131  * the different technologies of the ordered list to use for the default connection data.
132  *
133  * @section c_le_data_time Date and time
134  *
135  * When the data connection service is connected, the date and time can be retrieved from a distant
136  * server using le_data_GetDate() and le_data_GetTime(). The time protocol and time server to use
137  * are configured through the @ref c_le_data_configdb database:
138  * - Time protocol:
139  * - @ref LE_DATA_TP to use the Time Protocol, defined in
140  * <a href="https://tools.ietf.org/html/rfc868">RFC 868</a>.
141  * - @ref LE_DATA_NTP to use the Network Time Protocol, defined in
142  * <a href="https://tools.ietf.org/html/rfc5905">RFC 5905</a>.
143  * - Time server: address of the time server to connect to. If not set, the default value is
144  * <tt> time.nist.gov </tt> for @ref LE_DATA_TP and to <tt> pool.ntp.org </tt> for @ref LE_DATA_NTP.
145  *
146  * @note The configured time protocol needs to be supported by your platform to be used by the data
147  * connection service.
148  *
149  * @section c_le_data_configdb Configuration tree
150  * @copydoc c_le_data_configdbPage_Hide
151  *
152  * <HR>
153  *
154  * Copyright (C) Sierra Wireless Inc.
155  */
156 /**
157  * @interface c_le_data_configdbPage_Hide
158  *
159  * The configuration database of the @c dataConnectionService allows configuring:
160  * - the default routing
161  * - the Wi-Fi access point
162  * - the cellular profile
163  * - the time protocol and server.
164  *
165  * The configuration is stored under the following path:
166  * @verbatim
167  dataConnectionService:/
168  routing/
169  useDefaultRoute<bool> == true
170  wifi/
171  SSID<string> == TestSsid
172  secProtocol<int> == 3
173  passphrase<string> == Passw0rd
174  cellular/
175  profileIndex<int> == index
176  time/
177  protocol<int> == 0
178  server<string> == my.time.server.com
179  @endverbatim
180  *
181  * @note
182  * - The security protocol is one of the supported protocols defined in the
183  * @ref le_wifiClient_SecurityProtocol_t enumerator.
184  * - The time protocol is one of the supported protocols defined in the
185  * @ref le_data_TimeProtocol_t enumerator.
186  *
187  * @todo This solution is temporary, as the list of access points to connect to should be
188  * managed by the Wi-Fi client. Until its API is modified, the config tree is used to configure
189  * the only access point to use for the default data connection.
190  *
191  */
192 /**
193  * @file le_data_interface.h
194  *
195  * Legato @ref c_le_data include file.
196  *
197  * Copyright (C) Sierra Wireless Inc.
198  */
199 /**
200  * @page c_dataConnectionServiceSample Sample code for data connection service establishment
201  *
202  * @include "apps/test/dataConnectionService/dataConnectionServiceTest/dcsTestComp/dcsTest.c"
203  */
204 
205 #ifndef LE_DATA_INTERFACE_H_INCLUDE_GUARD
206 #define LE_DATA_INTERFACE_H_INCLUDE_GUARD
207 
208 
209 #include "legato.h"
210 
211 // Interface specific includes
212 #include "le_mdc_interface.h"
213 #include "le_dcs_interface.h"
214 
215 // Internal includes for this interface
216 #include "le_data_common.h"
217 //--------------------------------------------------------------------------------------------------
218 /**
219  * Type for handler called when a server disconnects.
220  */
221 //--------------------------------------------------------------------------------------------------
222 typedef void (*le_data_DisconnectHandler_t)(void *);
223 
224 //--------------------------------------------------------------------------------------------------
225 /**
226  *
227  * Connect the current client thread to the service providing this API. Block until the service is
228  * available.
229  *
230  * For each thread that wants to use this API, either ConnectService or TryConnectService must be
231  * called before any other functions in this API. Normally, ConnectService is automatically called
232  * for the main thread, but not for any other thread. For details, see @ref apiFilesC_client.
233  *
234  * This function is created automatically.
235  */
236 //--------------------------------------------------------------------------------------------------
238 (
239  void
240 );
241 
242 //--------------------------------------------------------------------------------------------------
243 /**
244  *
245  * Try to connect the current client thread to the service providing this API. Return with an error
246  * if the service is not available.
247  *
248  * For each thread that wants to use this API, either ConnectService or TryConnectService must be
249  * called before any other functions in this API. Normally, ConnectService is automatically called
250  * for the main thread, but not for any other thread. For details, see @ref apiFilesC_client.
251  *
252  * This function is created automatically.
253  *
254  * @return
255  * - LE_OK if the client connected successfully to the service.
256  * - LE_UNAVAILABLE if the server is not currently offering the service to which the client is
257  * bound.
258  * - LE_NOT_PERMITTED if the client interface is not bound to any service (doesn't have a binding).
259  * - LE_COMM_ERROR if the Service Directory cannot be reached.
260  */
261 //--------------------------------------------------------------------------------------------------
263 (
264  void
265 );
266 
267 //--------------------------------------------------------------------------------------------------
268 /**
269  * Set handler called when server disconnection is detected.
270  *
271  * When a server connection is lost, call this handler then exit with LE_FATAL. If a program wants
272  * to continue without exiting, it should call longjmp() from inside the handler.
273  */
274 //--------------------------------------------------------------------------------------------------
276 (
277  le_data_DisconnectHandler_t disconnectHandler,
278  void *contextPtr
279 );
280 
281 //--------------------------------------------------------------------------------------------------
282 /**
283  *
284  * Disconnect the current client thread from the service providing this API.
285  *
286  * Normally, this function doesn't need to be called. After this function is called, there's no
287  * longer a connection to the service, and the functions in this API can't be used. For details, see
288  * @ref apiFilesC_client.
289  *
290  * This function is created automatically.
291  */
292 //--------------------------------------------------------------------------------------------------
294 (
295  void
296 );
297 
298 
299 //--------------------------------------------------------------------------------------------------
300 /**
301  * Reference returned by Request function and used by Release function
302  */
303 //--------------------------------------------------------------------------------------------------
304 
305 
306 //--------------------------------------------------------------------------------------------------
307 /**
308  * Technologies.
309  */
310 //--------------------------------------------------------------------------------------------------
311 
312 
313 //--------------------------------------------------------------------------------------------------
314 /**
315  * Time protocols.
316  */
317 //--------------------------------------------------------------------------------------------------
318 
319 
320 //--------------------------------------------------------------------------------------------------
321 /**
322  * Handler for connection state changes
323  */
324 //--------------------------------------------------------------------------------------------------
325 
326 
327 //--------------------------------------------------------------------------------------------------
328 /**
329  * Reference type used by Add/Remove functions for EVENT 'le_data_ConnectionState'
330  */
331 //--------------------------------------------------------------------------------------------------
332 
333 
334 //--------------------------------------------------------------------------------------------------
335 /**
336  * Add handler function for EVENT 'le_data_ConnectionState'
337  *
338  * This event provides information on connection state changes
339  */
340 //--------------------------------------------------------------------------------------------------
341 le_data_ConnectionStateHandlerRef_t le_data_AddConnectionStateHandler
342 (
343  le_data_ConnectionStateHandlerFunc_t handlerPtr,
344  ///< [IN]
345  void* contextPtr
346  ///< [IN]
347 );
348 
349 //--------------------------------------------------------------------------------------------------
350 /**
351  * Remove handler function for EVENT 'le_data_ConnectionState'
352  */
353 //--------------------------------------------------------------------------------------------------
355 (
356  le_data_ConnectionStateHandlerRef_t handlerRef
357  ///< [IN]
358 );
359 
360 //--------------------------------------------------------------------------------------------------
361 /**
362  * Request the default data connection
363  *
364  * @return
365  * - Reference to the data connection (to be used later for releasing the connection)
366  * - NULL if the data connection requested could not be processed
367  */
368 //--------------------------------------------------------------------------------------------------
369 le_data_RequestObjRef_t le_data_Request
370 (
371  void
372 );
373 
374 //--------------------------------------------------------------------------------------------------
375 /**
376  * Release a previously requested data connection
377  */
378 //--------------------------------------------------------------------------------------------------
379 void le_data_Release
380 (
381  le_data_RequestObjRef_t requestRef
382  ///< [IN] Reference to a previously requested data connection
383 );
384 
385 //--------------------------------------------------------------------------------------------------
386 /**
387  * Set the rank of the technology used for the data connection service
388  *
389  * @return
390  * - @ref LE_OK if the technology is added to the list
391  * - @ref LE_BAD_PARAMETER if the technology is unknown
392  * - @ref LE_UNSUPPORTED if the technology is not available
393  */
394 //--------------------------------------------------------------------------------------------------
396 (
397  uint32_t rank,
398  ///< [IN] Rank of the used technology
399  le_data_Technology_t technology
400  ///< [IN] Technology
401 );
402 
403 //--------------------------------------------------------------------------------------------------
404 /**
405  * Get the first technology to use
406  * @return
407  * - One of the technologies from @ref le_data_Technology_t enumerator if the list is not empty
408  * - @ref LE_DATA_MAX if the list is empty
409  */
410 //--------------------------------------------------------------------------------------------------
411 le_data_Technology_t le_data_GetFirstUsedTechnology
412 (
413  void
414 );
415 
416 //--------------------------------------------------------------------------------------------------
417 /**
418  * Get the next technology to use
419  * @return
420  * - One of the technologies from @ref le_data_Technology_t enumerator if the list is not empty
421  * - @ref LE_DATA_MAX if the list is empty or the end of the list is reached
422  */
423 //--------------------------------------------------------------------------------------------------
424 le_data_Technology_t le_data_GetNextUsedTechnology
425 (
426  void
427 );
428 
429 //--------------------------------------------------------------------------------------------------
430 /**
431  * Get the technology of the currently connected data connection. In the absence of an actively
432  * connected data connection, @ref LE_DATA_MAX is returned.
433  *
434  * @return
435  * - One of the technologies from @ref le_data_Technology_t enumerator
436  * - @ref LE_DATA_MAX if not connected
437  */
438 //--------------------------------------------------------------------------------------------------
439 le_data_Technology_t le_data_GetTechnology
440 (
441  void
442 );
443 
444 //--------------------------------------------------------------------------------------------------
445 /**
446  * Get the default route activation status for the data connection service interface.
447  *
448  * @return
449  * - true: the default route is set by the data connection service
450  * - false: the default route is not set by the data connection service
451  */
452 //--------------------------------------------------------------------------------------------------
454 (
455  void
456 );
457 
458 //--------------------------------------------------------------------------------------------------
459 /**
460  * Add a route on the data connection service interface, if the data session is connected using
461  * the cellular technology and has an IPv4 or IPv6 address.
462  *
463  * @return
464  * - LE_OK on success
465  * - LE_UNSUPPORTED cellular technology not currently used
466  * - LE_BAD_PARAMETER incorrect IP address
467  * - LE_FAULT for all other errors
468  *
469  * @note Limitations:
470  * - only IPv4 is supported for the moment
471  * - route only added for a cellular connection
472  */
473 //--------------------------------------------------------------------------------------------------
475 (
476  const char* LE_NONNULL ipDestAddrStr
477  ///< [IN] The destination IP address in dotted
478  ///< format
479 );
480 
481 //--------------------------------------------------------------------------------------------------
482 /**
483  * Delete a route on the data connection service interface, if the data session is connected using
484  * the cellular technology and has an IPv4 or IPv6 address.
485  *
486  * @return
487  * - LE_OK on success
488  * - LE_UNSUPPORTED cellular technology not currently used
489  * - LE_BAD_PARAMETER incorrect IP address
490  * - LE_FAULT for all other errors
491  *
492  * @note Limitations:
493  * - only IPv4 is supported for the moment
494  * - route only removed for a cellular connection
495  */
496 //--------------------------------------------------------------------------------------------------
498 (
499  const char* LE_NONNULL ipDestAddrStr
500  ///< [IN] The destination IP address in dotted
501  ///< format
502 );
503 
504 //--------------------------------------------------------------------------------------------------
505 /**
506  * Get the cellular profile index used by the data connection service when the cellular technology
507  * is active.
508  *
509  * @return
510  * - Cellular profile index
511  */
512 //--------------------------------------------------------------------------------------------------
514 (
515  void
516 );
517 
518 //--------------------------------------------------------------------------------------------------
519 /**
520  * Set the cellular profile index used by the data connection service when the cellular technology
521  * is active.
522  *
523  * @return
524  * - LE_OK on success
525  * - LE_BAD_PARAMETER if the profile index is invalid
526  * - LE_BUSY the cellular connection is in use
527  */
528 //--------------------------------------------------------------------------------------------------
530 (
531  int32_t profileIndex
532  ///< [IN] Cellular profile index to be used
533 );
534 
535 //--------------------------------------------------------------------------------------------------
536 /**
537  * Get the date from the configured server using the configured time protocol.
538  *
539  * @warning An active data connection is necessary to retrieve the date.
540  *
541  * @return
542  * - LE_OK on success
543  * - LE_BAD_PARAMETER if a parameter is incorrect
544  * - LE_FAULT if an error occurred
545  */
546 //--------------------------------------------------------------------------------------------------
548 (
549  uint16_t* yearPtr,
550  ///< [OUT] UTC Year A.D. [e.g. 2017].
551  uint16_t* monthPtr,
552  ///< [OUT] UTC Month into the year [range 1...12].
553  uint16_t* dayPtr
554  ///< [OUT] UTC Days into the month [range 1...31].
555 );
556 
557 //--------------------------------------------------------------------------------------------------
558 /**
559  * Get the time from the configured server using the configured time protocol.
560  *
561  * @warning An active data connection is necessary to retrieve the time.
562  *
563  * @return
564  * - LE_OK on success
565  * - LE_BAD_PARAMETER if a parameter is incorrect
566  * - LE_FAULT if an error occurred
567  */
568 //--------------------------------------------------------------------------------------------------
570 (
571  uint16_t* hoursPtr,
572  ///< [OUT] UTC Hours into the day [range 0..23].
573  uint16_t* minutesPtr,
574  ///< [OUT] UTC Minutes into the hour [range 0..59].
575  uint16_t* secondsPtr,
576  ///< [OUT] UTC Seconds into the minute [range 0..59].
577  uint16_t* millisecondsPtr
578  ///< [OUT] UTC Milliseconds into the second [range 0..999].
579 );
580 
581 #endif // LE_DATA_INTERFACE_H_INCLUDE_GUARD
le_result_t le_data_GetDate(uint16_t *yearPtr, uint16_t *monthPtr, uint16_t *dayPtr)
void le_data_ConnectService(void)
le_result_t
Definition: le_basics.h:35
void le_data_Release(le_data_RequestObjRef_t requestRef)
LE_FULL_API void le_data_SetServerDisconnectHandler(le_data_DisconnectHandler_t disconnectHandler, void *contextPtr)
le_data_RequestObjRef_t le_data_Request(void)
void le_data_RemoveConnectionStateHandler(le_data_ConnectionStateHandlerRef_t handlerRef)
le_result_t le_data_SetTechnologyRank(uint32_t rank, le_data_Technology_t technology)
le_data_Technology_t le_data_GetNextUsedTechnology(void)
le_result_t le_data_AddRoute(const char *LE_NONNULL ipDestAddrStr)
int32_t le_data_GetCellularProfileIndex(void)
le_result_t le_data_TryConnectService(void)
void le_data_DisconnectService(void)
le_result_t le_data_GetTime(uint16_t *hoursPtr, uint16_t *minutesPtr, uint16_t *secondsPtr, uint16_t *millisecondsPtr)
le_result_t le_data_SetCellularProfileIndex(int32_t profileIndex)
le_data_Technology_t le_data_GetTechnology(void)
#define LE_FULL_API
Definition: le_basics.h:288
le_result_t le_data_DelRoute(const char *LE_NONNULL ipDestAddrStr)
void(* le_data_DisconnectHandler_t)(void *)
Definition: le_data_interface.h:222
bool le_data_GetDefaultRouteStatus(void)
le_data_Technology_t le_data_GetFirstUsedTechnology(void)
le_data_ConnectionStateHandlerRef_t le_data_AddConnectionStateHandler(le_data_ConnectionStateHandlerFunc_t handlerPtr, void *contextPtr)