Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use dbus-native to call NetworkManager #59

Closed
zhangtianye opened this issue Mar 26, 2015 · 3 comments
Closed

Use dbus-native to call NetworkManager #59

zhangtianye opened this issue Mar 26, 2015 · 3 comments
Labels

Comments

@zhangtianye
Copy link

I've meet some problem when I try to use dbus-native with nodejs to call to NetworkManager and let NetworkManager connect to a SSID(WIFI).
I use the connection is :

con = [ //a
  ['802-11-wireless', [
    ['mode', ['s','infrastructure']],
    ['security', ['s','802-11-wireless-security']],
    ['ssid', ['y',stringToArrayOfBytes('TP-LINK_10DC')]]
  ]],
  ['802-11-wireless-security', [
    ['auth-alg', ['s','open']], 
    ['key-mgmt', ['s','wpa-psk']],
    ['psk', ['s','0123456789']]
  ]],
  ['connection',[
    ['id', ['s','TP-LINK_10DC']],
    ['type', ['s','802-11-wireless']],
    ['uuid', ['s',uuid.v1().toString()]]
  ]],
    ['ipv4', [
        ['method', ['s','auto']]
    ]],
    ['ipv6', [
    ['method', ['s','auto']]
        ]]
]

and my code is:

var dbus = require('dbus-native');
var systemBus = dbus.systemBus();
var uuid = require('uuid');

var stringToArrayOfBytes = function (str) {
  var bytes = [];
  for (var i = 0; i < str.length; ++i) {
      bytes.push(str.charCodeAt(i));
  }
  return bytes;
};
con = [ //a
  ['802-11-wireless', [
    ['mode', ['s','infrastructure']],
    ['security', ['s','802-11-wireless-security']],
    ['ssid', ['ai',stringToArrayOfBytes('TP-LINK_10DC')]]
  ]],
  ['802-11-wireless-security', [
    ['auth-alg', ['s','open']], 
    ['key-mgmt', ['s','wpa-psk']],
    ['psk', ['s','0123456789']]
  ]],
  ['connection',[
    ['id', ['s','TP-LINK_10DC']],
    ['type', ['s','802-11-wireless']],
    ['uuid', ['s',uuid.v1().toString()]]
  ]],
 ['ipv4', [
 ['method', ['s','auto']]
 ]],
 ['ipv6', [
    ['method', ['s','auto']]
        ]]
]
systemBus.getService('org.freedesktop.NetworkManager').getInterface(
 '/org/freedesktop/NetworkManager',
 'org.freedesktop.NetworkManager', function(err, Device) {
// console.log(Device);
 Device.AddAndActivateConnection(con,'/org/freedesktop/NetworkManager/Devices/0','/',function(err,id){
 console.log(id);
 });

});

In my code,SSID is the name of WIFI,and psk is my password.ID is also the name of WIFI.But id can use the form of string,ssid should use the form of bytes.
What can I do to help me Connect to a SSID?
Thanks.

@sidorares
Copy link
Owner

currently when you serialise/deserialise variant, it's always a struct no matter if underlying type is simple or compound. Examples:

   // sv where v is "ai
   [ "string", [ "ai" [ [ 1, 2, 3 ] ] ]

   // av , first is ai, second is "sai"
   [  [ "ai", [ [1, 2, 3 ] ] ],   [ "sai", [ "test", [ 1, 2, 3 ] ] ]

so your code should be

var dbus = require('dbus-native');
var systemBus = dbus.systemBus();
var uuid = require('uuid');

var stringToArrayOfBytes = function (str) {
  var bytes = [];
  for (var i = 0; i < str.length; ++i) {
      bytes.push(str.charCodeAt(i));
  }
  return bytes;
};
con = [ //a
  ['802-11-wireless', [
    ['mode', ['s','infrastructure']],
    ['security', ['s','802-11-wireless-security']],
    ['ssid', ['ai', [ stringToArrayOfBytes('TP-LINK_10DC') ] ]]  // note that array itself is element of struct
  ]],
  ['802-11-wireless-security', [
    ['auth-alg', ['s','open']], 
    ['key-mgmt', ['s','wpa-psk']],
    ['psk', ['s','0123456789']]
  ]],
  ['connection',[
    ['id', ['s','TP-LINK_10DC']],
    ['type', ['s','802-11-wireless']],
    ['uuid', ['s',uuid.v1().toString()]]
  ]],
 ['ipv4', [
 ['method', ['s','auto']]
 ]],
 ['ipv6', [
    ['method', ['s','auto']]
        ]]
]
systemBus.getService('org.freedesktop.NetworkManager').getInterface(
 '/org/freedesktop/NetworkManager',
 'org.freedesktop.NetworkManager', function(err, Device) {
// console.log(Device);
 Device.AddAndActivateConnection(con,'/org/freedesktop/NetworkManager/Devices/0','/',function(err,id){
 console.log(id);
 });

});

@zhangtianye
Copy link
Author

The Ssid which I want to send to NetworkManager is a " GByteArray " data structure.
I tried to use the form of 'ai' ,but I get error : " ["A 'wireless' setting with a valid SSID is required if no AP path was given."] ",Maybe the Data Structure is not right.
Can you give me some more advices?

@sidorares
Copy link
Owner

#62

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants