This topic describes how to get a POSIX/Linux legacy app written in C running on a Legato device and using Legato APIs to access services like SMS, SIM, voice calling, and data connections.
bin/legs in the directory in which your framework is installed. The most basic way to get your legacy app running on a Legato target device is to recompile it using the provided cross-build tool chain and copy it onto the device using a tool like scp.
1. Build a legacy app executable for your target device using the cross tool chain provided.
2. Copy the legacy app executable onto the target using a tool like scp:
3. Run the legacy app from the target command-line:
By bundling your program as a Legato app, you gain access to a wealth of valuable features:
1. Create a .adef file (e.g., legacyProgram.adef) that bundles the cross-compiled executable into an application:
2. Run mkapp to generate an application bundle for your target:
3. Install the app bundle on the target using instapp:
4. From the target's command line, use app start to run the program:
5. Look for the program output in the target device's log using logread.
logread into grep.Many Legato services are provided through IPC-based APIs. The ifgen tool can generate the IPC code for you, along with a header (.h) file that you can #include to gain access to the service.
Here is how to use a Legato modem service API (e.g., le_info). The source code for this example can be found in apps/sample/legacy/useLegatoApi/ .
1. Run ifgen to generate the .c and .h files you need to access the interface.
–gen-interface option to generate the interface header (le_info_interface.h).–gen-client option to generate the client-side IPC implementation (le_info_client.c).–gen-local option to generate definitions that are shared by both the client side and server side IPC code (le_info_local.h).ifgen --gen-interface --gen-client --gen-local $LEGATO_ROOT/interfaces/modemServices/le_info.api
2. Include legato.h in your program.
3. Include the API's generated "interface" header file.
4. Connect to the service by calling le_info_ConnectService() (using legacy main function).
le_info service isn't available, this will block until it becomes available. In the meantime, you'll see your app in the WAITING CLIENTS list if you run sdir list.5. Add a call to one of the le_info API functions (e.g., le_info_GetDeviceModel() ).
6. Compile and link your executable with the code generated by ifgen:
7. Specify which instance of the le_info service your app should use by creating a binding in the .adef file:
le_info today, but if there were multiple, this would specify which one to use; and even when there's only one instance, we create a binding anyway to explicitly grant access permission so access is never unknowingly granted.9. Re-generate your application bundle, install it, and run it on target:
If you need asynchronous callbacks (i.e., handlers), you'll need to service the Legato event loop for your thread. To do this, use le_event_GetFd() and le_event_ServiceLoop(). See Integrating with Legacy POSIX Code for more details.
The sample app for this is found in apps/sample/legacy/useLegatoHandler.
Here's some sample code:
To tell the Supervisor to run your app inside a sandbox, remove the following line from your app's .adef file:
Or, you can change false to true:
Then re-bundle your app using mkapp.
The most commonly-used system libraries, such as libc and libpthread, will be visible inside your app's sandbox by default, but you may now find that your app won't run because some other files are missing from its sandbox.
Use the requires: section in the app's .adef file to add things to the sandbox.
Sample Legacy C apps are available in the Legato/apps/sample/legacy directory.
Copyright (C) Sierra Wireless Inc. Use of this work is subject to license.