Re: Newbie: how to talk to NM by C or C++? Need some hints.



On Tuesday 30 of November 2010 10:27:14 inthawadee C. wrote:
> Hello all,
> 
> How can I get the current statuses such as signal strength and maximum bit
> rate (also connection status). of wireless access point from NetworkManager
> by programming in C/C++?
> I have read many pages recommended in archives such as
> 
> http://projects.gnome.org/NetworkManager/developers/spec.html#org.freedeskt
> op.NetworkManager.AccessPoint<http:///>
> http://projects.gnome.org/NetworkManager/developers/libnm-glib/08/NMActive
> Connection.html#NM-ACTIVE-CONNECTION-SERVICE-NAME--CAPS<http:///>
> 
> but still have no clue how to talk to NetworkManager.
> 
> I just want to use the mentioned parameters as input factors of my
> experiment implemented in C.
> Previously, I worked with iwconfig and iwlist but want to try the program
> through Network Manager.
> 
> Thanks in advance.
> 
> Papagei

As others pointed out, you can talk to NetworkManager via D-Bus protocol
(http://dbus.freedesktop.org/doc/dbus-tutorial.html).
NM D-Bus API description is available here 
http://projects.gnome.org/NetworkManager/developers/spec-08.html.

You can talk on D-Bus in many different ways according to 
tools/languages/libraries you choose.
1. command-line tools:
qdbus:
example (getting AP signal strength)
qdbus --system --literal org.freedesktop.NetworkManager 
/org/freedesktop/NetworkManager/AccessPoint/0 
org.freedesktop.NetworkManager.AccessPoint.Strength

dbus-send:
example (getting AP signal strength):
dbus-send --system --print-reply --dest=org.freedesktop.NetworkManager 
/org/freedesktop/NetworkManager/AccessPoint/0 
org.freedesktop.DBus.Properties.Get string:org.freedesktop.NetworkManager 
string:Strength

cnetworkManager:
e.g.: cnetworkmanager --ai=00:3A:98:A0:70:40

nmcli:
e.g.: mcli -f NAME,SSID,BSSID,SIGNAL dev wifi list 

2. python
see examples in 
http://cgit.freedesktop.org/NetworkManager/NetworkManager/tree/examples/python

3. C/C++
You can use low-level D-Bus library (part of dbus package) or some higher 
level libraries such as dbus-glib or  dbus-qt.
Moreover, NM comes with libnm-glib library that wraps direct D-Bus calls and 
makes the communication even more easy.
See examples in 
http://cgit.freedesktop.org/NetworkManager/NetworkManager/tree/examples/C
I've added 
http://cgit.freedesktop.org/NetworkManager/NetworkManager/tree/examples/C/get-
ap-info-libnm-glib.c, that will show you how to get info about APs (you are 
interested in).

Jirka


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