~kvalo/connman/bug-734339

« back to all changes in this revision

Viewing changes to src/manager.c

  • Committer: Bazaar Package Importer
  • Author(s): Mathieu Trudel, Alexander Sack, Mathieu Trudel
  • Date: 2009-10-14 23:59:04 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20091014235904-xbulmde9bfcx0wuk
Tags: 0.42+dfsg-0ubuntu1
* new upstream release 0.42 with FFe (LP: #444172)

[ Alexander Sack <asac@ubuntu.com> ]
* LP: #402998 - homepage used in package is outdated; updated to
  http://www.connman.net
  - update debian/control
* LP: #402999 - add Vcs-Browser to debian/control and change Vcs-Bzr
  to read/write location
  - update debian/control
* LP: #400576 - Please use compatible mode to provide NetworkManager
  dbus interface; ship a /etc/default/connman which enables NM
  compatibility mode; also include example how to enable debugging
  - add debian/connman.default
* explicitly install init script
  - debian/connnman.install
* set --only-scripts parameter for dh_installinit (cdbs)
  - update debian/rules

[ Mathieu Trudel <mathieu.tl@gmail.com> ]
* bump Standards-Version to 3.8.3
  - update debian/control 
* add GIT_BRANCH, GIT_BRANCH_NAME, DEB_MAJOR_VERSION to support daily builds
  - update debian/rules
* Add update-local-branch code to work with local git copies
  - update debian/rules 
* Revise get-orig-source code, add get-current-source and GET_SOURCE snippets
  - update debian/rules
* Handle dfsg special case, add MAKE_DFSG_COMPLIANT snippet
  - update debian/rules
* Add pre-build, clean targets
  - update debian/rules 
* Patch init script to add LSB headers (Closes: #543869)
  - add debian/patches/01-init-script-lsb-headers.patch
  - update debian/patches/series

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
 
28
28
#include "connman.h"
29
29
 
30
 
static connman_bool_t global_offlinemode = FALSE;
31
 
 
32
30
static void append_profiles(DBusMessageIter *dict)
33
31
{
34
32
        DBusMessageIter entry, value, iter;
202
200
{
203
201
        DBusMessage *reply;
204
202
        DBusMessageIter array, dict;
 
203
        connman_bool_t offlinemode;
205
204
        const char *str;
206
205
 
207
206
        DBG("conn %p", conn);
240
239
        connman_dbus_dict_append_variant(&dict, "State",
241
240
                                                DBUS_TYPE_STRING, &str);
242
241
 
 
242
        offlinemode = __connman_profile_get_offlinemode();
243
243
        connman_dbus_dict_append_variant(&dict, "OfflineMode",
244
 
                                DBUS_TYPE_BOOLEAN, &global_offlinemode);
 
244
                                        DBUS_TYPE_BOOLEAN, &offlinemode);
245
245
 
246
246
        append_available_technologies(&dict);
247
247
        append_enabled_technologies(&dict);
262
262
{
263
263
        DBusMessageIter iter, value;
264
264
        const char *name;
 
265
        int type;
265
266
 
266
267
        DBG("conn %p", conn);
267
268
 
276
277
                                        CONNMAN_SECURITY_PRIVILEGE_MODIFY) < 0)
277
278
                return __connman_error_permission_denied(msg);
278
279
 
 
280
        type = dbus_message_iter_get_arg_type(&value);
 
281
 
279
282
        if (g_str_equal(name, "OfflineMode") == TRUE) {
280
283
                connman_bool_t offlinemode;
281
284
 
 
285
                if (type != DBUS_TYPE_BOOLEAN)
 
286
                        return __connman_error_invalid_arguments(msg);
 
287
 
282
288
                dbus_message_iter_get_basic(&value, &offlinemode);
283
289
 
284
 
                if (global_offlinemode == offlinemode)
285
 
                        return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
286
 
 
287
 
                global_offlinemode = offlinemode;
288
 
 
289
 
                __connman_device_set_offlinemode(offlinemode);
 
290
                __connman_profile_set_offlinemode(offlinemode);
 
291
 
 
292
                __connman_profile_save_default();
290
293
        } else if (g_str_equal(name, "ActiveProfile") == TRUE) {
291
294
                const char *str;
292
295
 
319
322
                                                DBUS_TYPE_INVALID);
320
323
}
321
324
 
322
 
static DBusMessage *add_profile(DBusConnection *conn,
 
325
static DBusMessage *create_profile(DBusConnection *conn,
323
326
                                        DBusMessage *msg, void *data)
324
327
{
325
 
        const char *name;
 
328
        const char *name, *path;
 
329
        int err;
326
330
 
327
331
        DBG("conn %p", conn);
328
332
 
329
333
        dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &name,
330
334
                                                        DBUS_TYPE_INVALID);
331
335
 
332
 
        return __connman_error_not_supported(msg);
 
336
        if (__connman_security_check_privilege(msg,
 
337
                                        CONNMAN_SECURITY_PRIVILEGE_MODIFY) < 0)
 
338
                return __connman_error_permission_denied(msg);
 
339
 
 
340
        err = __connman_profile_create(name, &path);
 
341
        if (err < 0)
 
342
                return __connman_error_failed(msg, -err);
 
343
 
 
344
        return g_dbus_create_reply(msg, DBUS_TYPE_OBJECT_PATH, &path,
 
345
                                                        DBUS_TYPE_INVALID);
333
346
}
334
347
 
335
348
static DBusMessage *remove_profile(DBusConnection *conn,
336
349
                                        DBusMessage *msg, void *data)
337
350
{
338
351
        const char *path;
 
352
        int err;
339
353
 
340
354
        DBG("conn %p", conn);
341
355
 
342
356
        dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
343
357
                                                        DBUS_TYPE_INVALID);
344
358
 
345
 
        return __connman_error_not_supported(msg);
 
359
        if (__connman_security_check_privilege(msg,
 
360
                                        CONNMAN_SECURITY_PRIVILEGE_MODIFY) < 0)
 
361
                return __connman_error_permission_denied(msg);
 
362
 
 
363
        err = __connman_profile_remove(path);
 
364
        if (err < 0)
 
365
                return __connman_error_failed(msg, -err);
 
366
 
 
367
        return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
346
368
}
347
369
 
348
370
static DBusMessage *request_scan(DBusConnection *conn,
349
371
                                        DBusMessage *msg, void *data)
350
372
{
351
 
        enum connman_device_type type;
 
373
        enum connman_service_type type;
352
374
        const char *str;
353
375
        int err;
354
376
 
358
380
                                                        DBUS_TYPE_INVALID);
359
381
 
360
382
        if (g_strcmp0(str, "") == 0)
361
 
                type = CONNMAN_DEVICE_TYPE_UNKNOWN;
 
383
                type = CONNMAN_SERVICE_TYPE_UNKNOWN;
362
384
        else if (g_strcmp0(str, "wifi") == 0)
363
 
                type = CONNMAN_DEVICE_TYPE_WIFI;
 
385
                type = CONNMAN_SERVICE_TYPE_WIFI;
364
386
        else if (g_strcmp0(str, "wimax") == 0)
365
 
                type = CONNMAN_DEVICE_TYPE_WIMAX;
 
387
                type = CONNMAN_SERVICE_TYPE_WIMAX;
366
388
        else
367
389
                return __connman_error_invalid_arguments(msg);
368
390
 
379
401
        return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
380
402
}
381
403
 
 
404
static DBusConnection *connection = NULL;
 
405
 
 
406
static enum connman_service_type technology_type;
 
407
static connman_bool_t technology_enabled;
 
408
static DBusMessage *technology_pending = NULL;
 
409
static guint technology_timeout = 0;
 
410
 
 
411
static void technology_reply(int error)
 
412
{
 
413
        DBG("");
 
414
 
 
415
        if (technology_timeout > 0) {
 
416
                g_source_remove(technology_timeout);
 
417
                technology_timeout = 0;
 
418
        }
 
419
 
 
420
        if (technology_pending != NULL) {
 
421
                if (error > 0) {
 
422
                        DBusMessage *reply;
 
423
 
 
424
                        reply = __connman_error_failed(technology_pending,
 
425
                                                                error);
 
426
                        if (reply != NULL)
 
427
                                g_dbus_send_message(connection, reply);
 
428
                } else
 
429
                        g_dbus_send_reply(connection, technology_pending,
 
430
                                                        DBUS_TYPE_INVALID);
 
431
 
 
432
                dbus_message_unref(technology_pending);
 
433
                technology_pending = NULL;
 
434
        }
 
435
 
 
436
        technology_type = CONNMAN_SERVICE_TYPE_UNKNOWN;
 
437
}
 
438
 
 
439
static gboolean technology_abort(gpointer user_data)
 
440
{
 
441
        DBG("");
 
442
 
 
443
        technology_timeout = 0;
 
444
 
 
445
        technology_reply(ETIMEDOUT);
 
446
 
 
447
        return FALSE;
 
448
}
 
449
 
 
450
static void technology_notify(enum connman_service_type type,
 
451
                                                connman_bool_t enabled)
 
452
{
 
453
        DBG("type %d enabled %d", type, enabled);
 
454
 
 
455
        if (type == technology_type && enabled == technology_enabled)
 
456
                technology_reply(0);
 
457
}
 
458
 
 
459
static struct connman_notifier technology_notifier = {
 
460
        .name           = "manager",
 
461
        .priority       = CONNMAN_NOTIFIER_PRIORITY_HIGH,
 
462
        .service_enabled= technology_notify,
 
463
};
 
464
 
382
465
static DBusMessage *enable_technology(DBusConnection *conn,
383
466
                                        DBusMessage *msg, void *data)
384
467
{
385
 
        enum connman_device_type type;
 
468
        enum connman_service_type type;
386
469
        const char *str;
387
470
        int err;
388
471
 
389
472
        DBG("conn %p", conn);
390
473
 
 
474
        if (technology_pending != NULL)
 
475
                return __connman_error_in_progress(msg);
 
476
 
391
477
        dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &str,
392
478
                                                        DBUS_TYPE_INVALID);
393
479
 
394
480
        if (g_strcmp0(str, "ethernet") == 0)
395
 
                type = CONNMAN_DEVICE_TYPE_ETHERNET;
 
481
                type = CONNMAN_SERVICE_TYPE_ETHERNET;
396
482
        else if (g_strcmp0(str, "wifi") == 0)
397
 
                type = CONNMAN_DEVICE_TYPE_WIFI;
 
483
                type = CONNMAN_SERVICE_TYPE_WIFI;
398
484
        else if (g_strcmp0(str, "wimax") == 0)
399
 
                type = CONNMAN_DEVICE_TYPE_WIMAX;
 
485
                type = CONNMAN_SERVICE_TYPE_WIMAX;
400
486
        else if (g_strcmp0(str, "bluetooth") == 0)
401
 
                type = CONNMAN_DEVICE_TYPE_BLUETOOTH;
402
 
        else if (g_strcmp0(str, "gps") == 0)
403
 
                type = CONNMAN_DEVICE_TYPE_GPS;
 
487
                type = CONNMAN_SERVICE_TYPE_BLUETOOTH;
 
488
        else if (g_strcmp0(str, "cellular") == 0)
 
489
                type = CONNMAN_SERVICE_TYPE_CELLULAR;
404
490
        else
405
491
                return __connman_error_invalid_arguments(msg);
406
492
 
 
493
        if (__connman_notifier_is_enabled(type) == TRUE)
 
494
                return __connman_error_already_enabled(msg);
 
495
 
 
496
        technology_type = type;
 
497
        technology_enabled = TRUE;
 
498
        technology_pending = dbus_message_ref(msg);
 
499
 
407
500
        err = __connman_element_enable_technology(type);
408
 
        if (err < 0) {
409
 
                if (err == -EINPROGRESS) {
410
 
                        connman_error("Invalid return code from enable");
411
 
                        err = -EINVAL;
412
 
                }
413
 
 
414
 
                return __connman_error_failed(msg, -err);
415
 
        }
416
 
 
417
 
        return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
 
501
        if (err < 0 && err != -EINPROGRESS)
 
502
                technology_reply(-err);
 
503
        else
 
504
                technology_timeout = g_timeout_add_seconds(15,
 
505
                                                technology_abort, NULL);
 
506
 
 
507
        return NULL;
418
508
}
419
509
 
420
510
static DBusMessage *disable_technology(DBusConnection *conn,
421
511
                                        DBusMessage *msg, void *data)
422
512
{
423
 
        enum connman_device_type type;
 
513
        enum connman_service_type type;
424
514
        const char *str;
425
515
        int err;
426
516
 
427
517
        DBG("conn %p", conn);
428
518
 
 
519
        if (technology_pending != NULL)
 
520
                return __connman_error_in_progress(msg);
 
521
 
429
522
        dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &str,
430
523
                                                        DBUS_TYPE_INVALID);
431
524
 
432
525
        if (g_strcmp0(str, "ethernet") == 0)
433
 
                type = CONNMAN_DEVICE_TYPE_ETHERNET;
 
526
                type = CONNMAN_SERVICE_TYPE_ETHERNET;
434
527
        else if (g_strcmp0(str, "wifi") == 0)
435
 
                type = CONNMAN_DEVICE_TYPE_WIFI;
 
528
                type = CONNMAN_SERVICE_TYPE_WIFI;
436
529
        else if (g_strcmp0(str, "wimax") == 0)
437
 
                type = CONNMAN_DEVICE_TYPE_WIMAX;
 
530
                type = CONNMAN_SERVICE_TYPE_WIMAX;
438
531
        else if (g_strcmp0(str, "bluetooth") == 0)
439
 
                type = CONNMAN_DEVICE_TYPE_BLUETOOTH;
440
 
        else if (g_strcmp0(str, "gps") == 0)
441
 
                type = CONNMAN_DEVICE_TYPE_GPS;
 
532
                type = CONNMAN_SERVICE_TYPE_BLUETOOTH;
 
533
        else if (g_strcmp0(str, "cellular") == 0)
 
534
                type = CONNMAN_SERVICE_TYPE_CELLULAR;
442
535
        else
443
536
                return __connman_error_invalid_arguments(msg);
444
537
 
 
538
        if (__connman_notifier_is_enabled(type) == FALSE)
 
539
                return __connman_error_already_disabled(msg);
 
540
 
 
541
        technology_type = type;
 
542
        technology_enabled = FALSE;
 
543
        technology_pending = dbus_message_ref(msg);
 
544
 
445
545
        err = __connman_element_disable_technology(type);
446
 
        if (err < 0) {
447
 
                if (err == -EINPROGRESS) {
448
 
                        connman_error("Invalid return code from disable");
449
 
                        err = -EINVAL;
450
 
                }
451
 
 
452
 
                return __connman_error_failed(msg, -err);
453
 
        }
454
 
 
455
 
        return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
 
546
        if (err < 0 && err != -EINPROGRESS)
 
547
                technology_reply(-err);
 
548
        else
 
549
                technology_timeout = g_timeout_add_seconds(10,
 
550
                                                technology_abort, NULL);
 
551
 
 
552
        return NULL;
456
553
}
457
554
 
458
555
static DBusMessage *connect_service(DBusConnection *conn,
482
579
static DBusMessage *register_agent(DBusConnection *conn,
483
580
                                        DBusMessage *msg, void *data)
484
581
{
485
 
        DBusMessage *reply;
486
582
        const char *sender, *path;
 
583
        int err;
487
584
 
488
585
        DBG("conn %p", conn);
489
586
 
492
589
        dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
493
590
                                                        DBUS_TYPE_INVALID);
494
591
 
495
 
        reply = dbus_message_new_method_return(msg);
496
 
        if (reply == NULL)
497
 
                return NULL;
498
 
 
499
 
        dbus_message_append_args(reply, DBUS_TYPE_INVALID);
500
 
 
501
 
        __connman_agent_register(sender, path);
502
 
 
503
 
        return reply;
 
592
        err = __connman_agent_register(sender, path);
 
593
        if (err < 0)
 
594
                return __connman_error_failed(msg, -err);
 
595
 
 
596
        return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
504
597
}
505
598
 
506
599
static DBusMessage *unregister_agent(DBusConnection *conn,
507
600
                                        DBusMessage *msg, void *data)
508
601
{
509
 
        DBusMessage *reply;
510
602
        const char *sender, *path;
 
603
        int err;
511
604
 
512
605
        DBG("conn %p", conn);
513
606
 
516
609
        dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
517
610
                                                        DBUS_TYPE_INVALID);
518
611
 
519
 
        reply = dbus_message_new_method_return(msg);
520
 
        if (reply == NULL)
521
 
                return NULL;
522
 
 
523
 
        dbus_message_append_args(reply, DBUS_TYPE_INVALID);
524
 
 
525
 
        __connman_agent_unregister(sender, path);
526
 
 
527
 
        return reply;
 
612
        err = __connman_agent_unregister(sender, path);
 
613
        if (err < 0)
 
614
                return __connman_error_failed(msg, -err);
 
615
 
 
616
        return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
528
617
}
529
618
 
530
619
static GDBusMethodTable manager_methods[] = {
531
620
        { "GetProperties",     "",      "a{sv}", get_properties     },
532
621
        { "SetProperty",       "sv",    "",      set_property       },
533
622
        { "GetState",          "",      "s",     get_state          },
534
 
        { "AddProfile",        "s",     "o",     add_profile        },
 
623
        { "CreateProfile",     "s",     "o",     create_profile     },
535
624
        { "RemoveProfile",     "o",     "",      remove_profile     },
536
625
        { "RequestScan",       "s",     "",      request_scan       },
537
 
        { "EnableTechnology",  "s",     "",      enable_technology  },
538
 
        { "DisableTechnology", "s",     "",      disable_technology },
 
626
        { "EnableTechnology",  "s",     "",      enable_technology,
 
627
                                                G_DBUS_METHOD_FLAG_ASYNC },
 
628
        { "DisableTechnology", "s",     "",      disable_technology,
 
629
                                                G_DBUS_METHOD_FLAG_ASYNC },
539
630
        { "ConnectService",    "a{sv}", "o",     connect_service,
540
631
                                                G_DBUS_METHOD_FLAG_ASYNC },
541
632
        { "RegisterAgent",     "o",     "",      register_agent     },
601
692
        if (reply == NULL)
602
693
                return NULL;
603
694
 
604
 
        state = NM_STATE_DISCONNECTED;
 
695
        if (__connman_element_count(NULL, CONNMAN_ELEMENT_TYPE_CONNECTION) > 0)
 
696
                state = NM_STATE_CONNECTED;
 
697
        else
 
698
                state = NM_STATE_DISCONNECTED;
605
699
 
606
700
        dbus_message_append_args(reply, DBUS_TYPE_UINT32, &state,
607
701
                                                        DBUS_TYPE_INVALID);
616
710
        { },
617
711
};
618
712
 
619
 
static DBusConnection *connection = NULL;
620
713
static gboolean nm_compat = FALSE;
621
714
 
622
 
int __connman_manager_init(DBusConnection *conn, gboolean compat)
 
715
int __connman_manager_init(gboolean compat)
623
716
{
624
 
        DBG("conn %p", conn);
 
717
        DBG("");
625
718
 
626
 
        connection = dbus_connection_ref(conn);
 
719
        connection = connman_dbus_get_connection();
627
720
        if (connection == NULL)
628
721
                return -1;
629
722
 
 
723
        if (connman_notifier_register(&technology_notifier) < 0)
 
724
                connman_error("Failed to register technology notifier");
 
725
 
630
726
        g_dbus_register_interface(connection, CONNMAN_MANAGER_PATH,
631
727
                                        CONNMAN_MANAGER_INTERFACE,
632
728
                                        manager_methods,
644
740
 
645
741
void __connman_manager_cleanup(void)
646
742
{
647
 
        DBG("conn %p", connection);
 
743
        DBG("");
 
744
 
 
745
        connman_notifier_unregister(&technology_notifier);
 
746
 
 
747
        if (connection == NULL)
 
748
                return;
648
749
 
649
750
        if (nm_compat == TRUE) {
650
751
                g_dbus_unregister_interface(connection, NM_PATH, NM_INTERFACE);