7268adc1e7241592c4e680460b55e900c57d8c51
[platform/upstream/connman.git] / doc / overview-api.txt
1 Application programming interface
2 *********************************
3
4
5 Service basics
6 ==============
7
8 Inside Connection Manager there exists one advanced interface to allow the
9 user interface an easy access to networking details and user chosen
10 preferences. This is the service list and interface.
11
12 The basic idea is that Connection Manager maintains a single flat and sorted
13 list of all available, preferred or previously used services. A service here
14 can be either a Ethernet device, a WiFi network or a remote Bluetooth device
15 (for example a mobile phone).
16
17 This list of service is sorted by Connection Manager and there is no need
18 for the user interface to implement its own sorting. User decisions will
19 need to be done via Connection Manager and it is then responsible to update
20 the order of services in this list.
21
22         +---------------------------------------+
23         | Ethernet                              |
24         +---------------------------------------+
25         | Bluetooth phone                       |
26         +---------------------------------------+
27         | Guest            (strength 90, none)  |
28         +---------------------------------------+
29         | My WiFi AP       (strength 80, rsn)   |
30         +---------------------------------------+
31         | Other AP         (strength 70, rsn)   |
32         +---------------------------------------+
33         | Friends AP       (strength 70, wep)   |
34         +---------------------------------------+
35
36 If none of the services has been used before the sorting order will be done
37 with these priorities:
38
39         1. Ethernet     (lower index numbers first)
40         2. Bluetooth    (last used devices first)
41         3. GSM/UTMS/3G  (if SIM card is present, activated and not roaming)
42         3. WiFi         (signal strength first, then more secure network
43                         first)
44
45 The Ethernet devices are always sorted first since they are physically built
46 into the system and will be always present. In cases they are switched off
47 manually they will not be showing in this list.
48
49 Since every Bluetooth device has to be configured/paired first, the user
50 already made a choice here that these are important. Connection Manager will
51 only show devices with PAN or DUN profile support. While Bluetooth devices
52 do have a signal strength, it is mostly unknown since background scanning
53 in Bluetooth is too expensive. The choice here is to sort the last used
54 Bluetooth device before the others.
55
56 WiFi networks closer in the proximity should be shown first since it is more
57 likely they are selected. The signal strength value is normalized to 0-100
58 (effectively a percentage) and allows an easy sorting.
59
60 WiFi networks with the same signal strength are then sorted by their security
61 setting. WPA2 encrypted networks should be preferred over WPA/WEP and also
62 unencrypted ones. After that they will be sorted by the SSID in alphabetical
63 order.
64
65 In the case the WiFi network uses WPS for setup and it is clearly detectable
66 that a network waits for Connection Manager to connect to it (for example via
67 a push-to-connect button press on the AP), then this network should be shown
68 first before any other WiFi networks. The reason here is that the user already
69 made a choice via the access point. However this depends on technical details
70 if it is possible to detect these situations.
71
72
73 Service order
74 =============
75
76 All unused services will have the internal order number of 0 and then will
77 be sorted according to the rules above. For Bluetooth the user already made
78 the decision to setup their device and by that means select it. However
79 until the first connection attempt it might have been setup for total
80 different reason (like audio usage) and thus it still counts as unused from
81 a networking point of view.
82
83 Selecting the "My WiFi AP" and successfully connecting to it makes it a
84 favorite device and it will become an order number bigger than 0. All
85 order numbers are internally. They are given only to service that are marked
86 as favorite. For WiFi and Bluetooth a successful connection attempt makes
87 these services automatically a favorite. For Ethernet the plugging of a cable
88 makes it a favorite. Disconnecting from a network doesn't remove the favorite
89 setting. It is a manual operation and is equal to users pressing
90 delete/remove button.
91
92         +---------------------------------------+
93         | My WiFi AP       (strength 80, rsn)   |  order=1 - favorite=yes
94         +---------------------------------------+
95         | Ethernet                              |  order=0
96         +---------------------------------------+
97         | Guest            (strength 90, none)  |  order=0
98         +---------------------------------------+
99         |                                       |
100
101 Ethernet is special here since the unplugging of the network cable will
102 remove the favorite selection.
103
104         +---------------------------------------+
105         | Ethernet with cable                   |  order=1 - favorite=yes
106         +---------------------------------------+
107         | Ethernet without cable                |  order=0 - favorite=no
108         +---------------------------------------+
109         | Guest            (strength 90, none)  |  order=0
110         +---------------------------------------+
111         |                                       |
112
113 This means that all services with an order > 0 have favorite=yes and all
114 others have favorite=no setting. The favorite setting is exposed via a
115 property over the service interface. As mentioned above, the order number
116 is only used internally.
117
118 Within Connection Manager many services can be connected at the same time and
119 also have an IP assignment. However only one can have the default route. The
120 service with the default route will always be sorted at the top of the
121 list.
122
123         +---------------------------------------+
124         | Ethernet                              |  order=2 - connected=yes
125         +---------------------------------------+
126         | My WiFi AP       (strength 80, rsn)   |  order=1 - connected=yes
127         +---------------------------------------+
128         | Guest            (strength 90, none)  |  order=0
129         +---------------------------------------+
130         |                                       |
131
132 To change the default connection to your access point, the user needs to
133 manually drag the access point service to the top of the list. Connection
134 Manager will not take down default routes if there is no reason to do so.
135 A working connection is considered top priority.
136
137         +---------------------------------------+
138         | My WiFi AP       (strength 80, rsn)   |  order=2 - connected=yes
139         +---------------------------------------+
140         | Ethernet                              |  order=1 - connected=yes
141         +---------------------------------------+
142         | Guest            (strength 90, none)  |  order=0
143         +---------------------------------------+
144         |                                       |
145
146 Another possible user interaction would be to unplug the Ethernet cable and
147 in this case the favorite setting will be removed and the service falls back
148 down in the list.
149
150         +---------------------------------------+
151         | My WiFi AP       (strength 80, rsn)   |  order=1 - connected=yes
152         +---------------------------------------+
153         | Ethernet                              |  order=0
154         +---------------------------------------+
155         | Guest            (strength 90, none)  |  order=0
156         +---------------------------------------+
157         |                                       |
158
159 If the service on the top of the list changes the default route will be
160 automatically adjusted as needed. The user can trigger this by disconnecting
161 from a network, if the network becomes unavailable (out of range) or if the
162 cable gets unplugged.
163
164 As described above, the pure case of disconnecting from a network will not
165 remove the favorite setting. So previously selected networks are still present
166 and are sorted above all others.
167
168         +---------------------------------------+
169         | Ethernet                              |  order=2 - connected=yes
170         +---------------------------------------+
171         | My WiFi AP       (strength 80, rsn)   |  order=1 - connected=no
172         +---------------------------------------+
173         | Guest            (strength 90, none)  |  order=0
174         +---------------------------------------+
175         |                                       |
176
177 Unplugging the Ethernet cable will remove the favorite setting, but due to
178 the basic ordering of services it will be at the top of the services with an
179 order number of 0 (directly after all favorite services).
180
181         +---------------------------------------+
182         | My WiFi AP       (strength 80, rsn)   |  order=1 - connected=no
183         +---------------------------------------+
184         | Ethernet                              |  order=0 - connected=no
185         +---------------------------------------+
186         | Guest            (strength 90, none)  |  order=0
187         +---------------------------------------+
188         |                                       |
189
190
191 Service tweaks
192 ==============
193
194 The interfaces of Connection Manager will always export all services that are
195 currently known. The Ethernet devices with no cable plugged are actually not
196 included in this list. They will only show up once a carrier is detected.
197
198 The service interface is not meant for basic device configuration task. So
199 switching a device on and off (via RFKILL for example) should be done via
200 the technology interface.
201
202 Due to limited screen size of small devices and the big amount of WiFi
203 access points that are deployed right now it might be sensible to not show
204 certain WiFi networks in the user interface.
205
206 The choice to hide a WiFi network from the user interface should be purely
207 done by the signal strength. The optimal cut-off value here still has to be
208 determined, but in the end that is a user interface policy.
209
210
211 Service naming
212 ==============
213
214 Every service will have a name property that allows the user interface to
215 display them directly. All names will be already converted into UTF-8. It
216 derives from the netork details.
217
218 In case of WiFi this will be the SSID value. The SSID is a binary array and
219 will be converted into printable form. Unprintable characters are replaced
220 with spaces.
221
222 In addition to WiFi naming, WiFi networks are subject to a grouping policy
223 performed around SSID and security type. This means that one service will be
224 seen for N WiFi networks providing the same SSID and the same security metod.
225 For instance, if 5 APs are servicing an SSID called "TEST" with WPA2
226 authentication and 3 APs are servicing the same SSID with open authentication
227 method, the user will see only two services listed with the name "TEST"
228 differentiated by their security type, which are "psk" and "none". Such
229 policy is also applied to hidden networks, where hidden services will have an
230 empty name and will be differentiated by the security type. The user has then
231 to select the one with the right security and the Agent API will request any
232 required information such as the SSID for the network (See "Application
233 basics" below).
234
235 For Bluetooth the device alias is used. The alias is different since it
236 can be overwritten by the user via the Bluetooth service. The identification
237 is still done based on its address, but the display name might change. In
238 most cases the alias is equal to the Bluetooth remote friendly name.
239
240 For Ethernet device no name will be provided. The type property will indicate
241 that this service is Ethernet and then it is up to the user interface to
242 provide a proper localized name for it.
243
244
245 Service states
246 ==============
247
248 Every service can have multiple states that indicate what is currently
249 going on with it. The choice to have multiple states instead of a simple
250 connected yes/no value comes from the fact that it is important to let the
251 user interface name if a service is in process of connecting/disconnecting.
252
253 The basic state of every service is "idle". This means that this service
254 is not in use at all at the moment. It also is not attempting to connect
255 or do anything else.
256
257 The "association" state indicates that this service tries to establish a
258 low-level connection to the network. For example associating/connecting
259 with a WiFi access point.
260
261 With the "configuration" state the service indicates that it is trying
262 to retrieve/configure IP settings.
263
264 The "ready" state signals a successful connected device. This doesn't mean
265 it has the default route, but basic IP operations will succeed.
266
267 With the "disconnect" state a service indicates that it is going to terminate
268 the current connection and will return to the "idle" state.
269
270 In addition a "failure" state indicates a wrong behavior. It is similar to
271 the "idle" state since the service is not connected.
272
273                 +---------------+
274                 | idle          |<-------------------------------+
275                 +---------------+                                |
276                       |                                          |
277                       |                      +-------------+     |
278                       +----------------------| failure     |     |
279                       | service.Connect()    +-------------+     |
280                       V                           A              |
281                 +---------------+                 |              |
282                 | association   |-----------------+              |
283                 +---------------+      error      |              |
284                       |                           |              |
285                       | success                   |              |
286                       V                           |              |
287                 +---------------+                 |              |
288                 | configuration |-----------------+              |
289                 +---------------+      error                     |
290                       |                                          |
291                       | success                                  |
292                       V                                          |
293                 +---------------+                                |
294                 | ready         |                                |
295                 +---------------+                                |
296                       |                                          |
297                       | success                                  |
298                       |                                          |
299                       V                                          |
300                 +---------------+                                |
301                 | online        |<----------------+              |
302                 +---------------+                 |              |
303                       |                           |              |
304                       | service.Disconnect()      |              |
305                       V                           |              |
306                 +---------------+                 |              |
307                 | disconnect    |-----------------+              |
308                 +---------------+      error                     |
309                       |                                          |
310                       +------------------------------------------+
311
312 The different states should no be used by the user interface to trigger
313 advanced actions. The state transitions are provided for the sole purpose
314 to give the user feedback on what is currently going on. Especially in
315 cases where networks are flaky or DHCP servers take a long time these
316 information are helpful for the user.
317
318 Some services might require special authentication procedure like a web
319 based confirmation. The LoginRequired property should be used to check
320 for this.
321
322
323 Application basics
324 ==================
325
326 All applications should use D-Bus to communicate with Connection Manager. The
327 main entry point is the manager object. Currently the manager object is
328 located at "/", but this might change to allow full namespacing of the API
329 in the future. The manager interface is documented in manager-api.txt and
330 contains a set of global properties and methods.
331
332 A simple way to retrieve all global properties looks like this:
333
334         bus = dbus.SystemBus()
335
336         manager = dbus.Interface(bus.get_object("net.connman", "/"),
337                                                 "net.connman.Manager")
338
339         properties = manager.GetProperties()
340
341 Changing a global property is also pretty simple. For example enabling the
342 so called offline mode (aka flight mode) it is enough to just set that
343 property:
344
345         manager.SetProperty("OfflineMode", dbus.Boolean(1))
346
347 The manager object contains references to profiles, devices, services and
348 connections. All these references represent other interfaces that allow
349 detailed control of Connection Manager. The profiles and devices interfaces
350 are more for advanced features and most applications don't need them at all.
351
352 The services are represented as a list of object paths. Every of these object
353 paths contains a service interface. A service is a global collection for
354 Ethernet devices, WiFi networks, Bluetooth services etc. and all these
355 different types are treated equally.
356
357 Every local Ethernet card will show up as exactly one service. WiFi networks
358 will be grouped by SSID, mode and security setting. Bluetooth PAN and DUN
359 service will show up per remote device. This creates a simple list that can
360 be directly displayed to the users since these are the exact details users
361 should care about.
362
363         properties = manager.GetProperties()
364
365         for path in properties["Services"]:
366                 service = dbus.Interface(bus.get_object("net.connman", path),
367                                                         "net.connman.Service")
368
369                 service_properties = service.GetProperties()
370
371 The service interface is documented in service-api.txt and contains common
372 properties valid for all services. It also contains method to connect or
373 disconnect a specific service. This allows users to select a specific service.
374 Connection Manager can also auto-connect services based on his policies or
375 via external events (like plugging in an Ethernet cable).
376
377 Connecting (or disconnecting) a specific service manually is as simple as
378 just telling it to actually connect:
379
380         service.Connect()  or  service.Disconnect()
381
382 It is possible to connect multiple services if the underlying technology
383 allows it. For example it would be possible to connect to a WiFi network
384 and a Bluetooth service at the same time. Trying to connect to a second WiFi
385 network with the same WiFi hardware would result in an automatic disconnect
386 of the currently connected network. Connection Manager handles all of this
387 for the applications in the background. Trying to connect an Ethernet service
388 will result in an error if no cable is plugged in. All connection attempts
389 can fail for one reason or another. Application should be able to handle
390 such errors and will also be notified of changes via signals.
391
392 Connection Manager will interact with an agent via the Agent API to confirm
393 certain transactions with the user. If Connection Manager needs extra
394 information, it will ask the user for exactly the information it requires,
395 i.e. passphrase, network's name (for hidden WiFi networks) and more depending
396 on the use case (e.g. WPS, EAP). Therefore an application environment using
397 Connection Manager should implement one dedicated Connection Manager agent
398 according to the Agent API in order to interact with the user. Please see
399 agent-api.txt for implementation details.
400
401 To monitor the current status of a service the state property can be used. It
402 gives detailed information about the current progress.
403
404         properties = service.GetProperties()
405
406         print properties["State"]
407
408 All state changes are also sent via the PropertyChanged signal on the
409 service interface. This allows asynchronous monitoring without having to poll
410 Connection Manager for changes.