Node dbus-native - Passing Passphrase while connecting to WiFi service using connMan

1k views Asked by At

Hi I have been having this problem for the last couple of days, while trying to connect to a protected WiFi network using dbus. So the code I have developed so far is:

Register Agent

var dbus = require('dbus-native');
var bus = dbus.systemBus();
bus.invoke({
        destination: 'net.connman',
        path: '/',
        'interface': 'net.connman.Manager',
        member: 'RegisterAgent',
        type: dbus.messageType.methodCall,
        signature: 'o',
        body: [
                '/test/agent'
        ]
}, function(error, response) {
        if (error) {
                console.error('Error', error);
                //process.exit(1);
        } else {
                console.info('Success', response);
               // process.exit(0);
        }
});

Output

> Success

Scan Wifi

var dbus = require('dbus-native');
var bus = dbus.systemBus();
bus.invoke({
        destination: 'net.connman',
        path: '/net/connman/technology/wifi',
        'interface': 'net.connman.Technology',
        member: 'Scan',
        type: dbus.messageType.methodCall,
}, function(error, response) {
        if (error) {
                console.error('Error', error);
                //process.exit(1);
        } else {
                console.info('Success', response);
                //process.exit(0);
        }
});

Output

> Success

Connect to WiFi Service

var dbus = require('dbus-native');
var bus = dbus.systemBus();
bus.invoke({
        destination: 'net.connman',
        path: '/net/connman/service/wifi_00e04c81923e_4469676957494649_managed_psk',
        'interface': 'net.connman.Service',
        member: 'Connect',
        type: dbus.messageType.methodCall,
}, function(error, response) {
        if (error) {
                console.error('Error', error);
                //process.exit(1);
        } else {
                console.info('Success', response);
                //process.exit(0);
        }
});

Output

> Error ['Invalid Arguments']

Output fropm connMan logs

connmand[1899]: src/agent.c:agent_receive_message() agent 0x55640fe8 req 0x55644378

connmand[1899]: src/service.c:request_input_cb() RequestInput return, 0x55649ad0

connmand[1899]:src/service.c:request_input_cb()error:org.freedesktop.DBus.Error.UnknownService

connmand[1899]: src/service.c:__connman_service_return_error() service 0x55649ad0 error 22 user_data (nil)

connmand[1899]: src/service.c:__connman_service_set_hidden_data() service 0x55649ad0 pending (nil)

connmand[1899]: src/service.c:service_save() service 0x55649ad0 new 1

connmand[1899]: src/connection.c:update_order()

connmand[1899]: src/service.c:__connman_service_get_order() service 0x55640a08 name Wired order 1 split 0

connmand[1899]: src/connection.c:find_default_gateway() default 0x5563b250 order 1

connmand[1899]: src/connection.c:__connman_connection_update_gateway() default 0x5563b250

connmand[1899]: src/service.c:connman_service_unref_debug() 0x55649ad0 ref 1 by src/service.c:6945:agent_context_unref()

So basically, I would greatly appreciate it if someone could show me how to pass back the user data containing the passphrase for the WiFi network.

Any help would be greatly appreciated? (connMan version 1.20)

Thanks

1

There are 1 answers

0
Philip On

I was unable to get dbus-native to work.

My solution was to create a wifi.config file in /lib/connman/ which contains the passphrase for each service:

wifi.config example

[service_wifi_00e04c819295_4469679972434649_managed_psk] 
Type = wifi
Security = wpa2 
Name = [service_] 
Type = wifi 
Security = wpa2 
Name = WiFiAP
Passphrase = 12345

Then simply used dbus-native to connect to the WiFi service:

Connect

var dbus = require('dbus-native');
var bus = dbus.systemBus();
bus.invoke({
        destination: 'net.connman',
        path: '/net/connman/service/wifi_48022aca514f_4469676957494649_managed_psk',
        'interface': 'net.connman.Service',
        member: 'Connect',
        type: dbus.messageType.methodCall,
}, function(error, response) {
        if (error) {
                console.error('Error', error);
                //process.exit(1);
        } else {
                console.info('Success', response);
                //process.exit(0);
        }
});