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