I need to following using Raspberry Pi using only C program (or C++)

  • start and stop access point

  • connect to a particular access point(with username and password)

  • disconnect from access point
  • stop and start WiFi
  • 1
    Are you looking for direct "low-level" APIs for Linux wireless manipulation, or would wrapping existing command line tools in C be sufficient? You could easily wrap iw via popen()and pclose() in C and it would be a tenth the amount of work. – Hydranix Nov 7 '16 at 8:42

If you are looking out for ways to interact with any wpa_supplicant then you can use the control interface exposed by it. wpa_supplicant source itself has two files wpa_ctrl.c and wpa_ctrl.h you can create a library on top of this file, the following link will provide the necessary details on how to use the control interface to interact with wpa_supplicant.

Control interface reference

Also wpa_cli itself uses this control interface to talk with wpa_supplicant you can checkout wpa_cli code for reference as well.

| improve this answer | |

WPA Supplicant exposes its API via D-Bus interface typically called fi.epitest.hostap.WPASupplicant or fi.w1.wpa_supplicant1, so you can use that. The advantage of D-Bus is that you can connect to it with debug tools like dbus-monitor and test the API before you start writing code.

Here are some useful sources:

  • Documentation of WPA Supplicant API
  • D-Bus modules reference (I suggest you start by reading about DBusConnection and DBusMessage).
  • A tutorial explaining how to connect to D-Bus and send/receive messages in C.
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.