[gnome-network] Some problems of NetworkManager



HI,
I'm tring to work with nodejs to send a connection to NetworkManger.
I tried to send SSID with node-dbus,but failed.
NetworkManager returned me :

​and the connection I used is :
con = [ //a
  ['802-11-wireless', [
    ['mode', ['s','infrastructure']],
    ['security', ['s','802-11-wireless-security']],
    ['ssid', ['ai',  [[84, 80, 45, 76, 73, 78, 75, 95, 49, 48, 68, 67 ]] ]]
//    ['ssid', ['s',  'TP-LINK_10DC' ]]
//    ['ssid', ['aai',  [[84, 80, 45, 76, 73, 78, 75, 95, 49, 48, 68, 67 ]] ]]  // 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']]
        ]]
]

The code which I use 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;
};
console.log( stringToArrayOfBytes('TP-LINK_10DC'));
con = [ //a
  ['802-11-wireless', [
    ['mode', ['s','infrastructure']],
    ['security', ['s','802-11-wireless-security']],
    ['ssid', ['ai',  [[84, 80, 45, 76, 73, 78, 75, 95, 49, 48, 68, 67 ]] ]]
//    ['ssid', ['s',  'TP-LINK_10DC' ]]
//    ['ssid', ['aai',  [[84, 80, 45, 76, 73, 78, 75, 95, 49, 48, 68, 67 ]] ]]  // 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(err);
// console.log(id);
 });
});

In my code,
"  ['ssid', ['ai',  [[84, 80, 45, 76, 73, 78, 75, 95, 49, 48, 68, 67 ]] ]] "is my ssid,
"  ['psk', ['s','0123456789']]  " is my password.
Module "dbus-native" and "uuid" need to be npm installed.
I tried to use stringToArrayOfBytes('TP-LINK_10DC') to replace [84, 80, 45, 76, 73, 78, 75, 95, 49, 48, 68, 67 ],but failed.
All ways I know had been tried.
Can you give me some help?
Thanks.




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]