summaryrefslogtreecommitdiffstats
path: root/binding-wifi/wifi-api.c
diff options
context:
space:
mode:
authorMatt Ranostay <matt.ranostay@konsulko.com>2017-08-08 11:50:42 -0700
committerMatt Ranostay <matt.ranostay@konsulko.com>2017-09-26 14:04:24 -0700
commit7298ce428f8857b9f08df41edfe794f179e3d7e3 (patch)
treeabc46437c214b44a5b019d875280de76158b52fa /binding-wifi/wifi-api.c
parenta286b854cbbf315edd2c26889b7d81d502f9b619 (diff)
binding: wifi: switch to v2 binding formatdab_4.0.3dab_4.0.2dab/4.0.3dab/4.0.24.0.34.0.2dab
Update functions and structure to use the new version 2 of the afm binder framework Bug-AGL: SPEC-816 SPEC-913 Change-Id: I4fafc4e2302991dc895a1938f88754ace1a6360e Signed-off-by: Matt Ranostay <matt.ranostay@konsulko.com>
Diffstat (limited to 'binding-wifi/wifi-api.c')
-rw-r--r--binding-wifi/wifi-api.c88
1 files changed, 39 insertions, 49 deletions
diff --git a/binding-wifi/wifi-api.c b/binding-wifi/wifi-api.c
index 30552e8..aa008ce 100644
--- a/binding-wifi/wifi-api.c
+++ b/binding-wifi/wifi-api.c
@@ -27,6 +27,8 @@
#include <stdlib.h>
#include <unistd.h>
#include <json-c/json.h>
+
+#define AFB_BINDING_VERSION 2
#include <afb/afb-binding.h>
#include "wifi-api.h"
@@ -61,7 +63,7 @@ static void insertpasskey(struct afb_req request) {
/* retrieves the argument, expects passkey string */
passkey_from_user = afb_req_value(request, "passkey");
- NOTICE(afbitf, "Passkey inserted: %s\n", passkey_from_user);
+ AFB_NOTICE("Passkey inserted: %s\n", passkey_from_user);
sendPasskey(passkey_from_user);
@@ -70,7 +72,7 @@ static void insertpasskey(struct afb_req request) {
registerPasskey(passkey);
} else {
- NOTICE(afbitf, "Please enter the passkey first\n");
+ AFB_NOTICE("Please enter the passkey first\n");
}
}
@@ -148,8 +150,8 @@ static void eventpush (struct afb_req request)
*
*/
void ask_for_passkey(int number, const char* asciidata) {
- NOTICE(afbitf, "Passkey for %s network needed.", asciidata);
- NOTICE(afbitf, "Sending event.");
+ AFB_NOTICE("Passkey for %s network needed.", asciidata);
+ AFB_NOTICE("Sending event.");
json_object *jresp = json_object_new_object();
@@ -357,7 +359,7 @@ static void scan_result(struct afb_req request) /*AFB_SESSION_CHECK*/
json_object_object_add(jresp, "IPAddress", jstring3);
json_object_object_add(jresp, "State", jstring4);
- DEBUG(afbitf, "The object json: %s\n", json_object_to_json_string(jresp));
+ AFB_DEBUG("The object json: %s\n", json_object_to_json_string(jresp));
/*input each scan result into my_array*/
json_object_array_add(my_array, jresp);
@@ -432,7 +434,7 @@ static void connect(struct afb_req request) {
else {
network_index = atoi(network);
- NOTICE(afbitf,"Joining network number %d\n", network_index);
+ AFB_NOTICE("Joining network number %d\n", network_index);
}
@@ -442,14 +444,14 @@ static void connect(struct afb_req request) {
if (item == NULL) {
//Index starts from 1
- ERROR(afbitf, "Network with number %d not found.\n", network_index + 1);
+ AFB_ERROR("Network with number %d not found.\n", network_index + 1);
//TODO:better error message
afb_req_fail(request, "failed", "bad arguments");
}
else {
wifiProfileToConnect = (struct wifi_profile_info *) item;
- INFO(afbitf, "Name: %s, strength: %d, %s\n", wifiProfileToConnect->ESSID,
+ AFB_INFO("Name: %s, strength: %d, %s\n", wifiProfileToConnect->ESSID,
wifiProfileToConnect->Strength,
wifiProfileToConnect->NetworkPath);
}
@@ -498,7 +500,7 @@ static void disconnect(struct afb_req request) {
else {
network_index = atoi(network);
- NOTICE(afbitf, "Joining network number %d\n", network_index);
+ AFB_NOTICE("Joining network number %d\n", network_index);
}
@@ -507,14 +509,14 @@ static void disconnect(struct afb_req request) {
if (item == NULL) {
//Index starts from 1
- ERROR(afbitf,"Network with number %d not found.\n", network_index + 1);
+ AFB_ERROR("Network with number %d not found.\n", network_index + 1);
//TODO:better error message
afb_req_fail(request, "failed", "bad arguments");
}
else {
wifiProfileToConnect = (struct wifi_profile_info *) item;
- INFO(afbitf, "Name: %s, strength: %d, %s\n", wifiProfileToConnect->ESSID,
+ AFB_INFO("Name: %s, strength: %d, %s\n", wifiProfileToConnect->ESSID,
wifiProfileToConnect->Strength,
wifiProfileToConnect->NetworkPath);
}
@@ -546,18 +548,18 @@ static void status(struct afb_req request) {
json_object_object_add(jresp, "Power",
json_object_new_string("OFF"));
//json_object_object_add(jresp, "Connection", json_object_new_string("Disconnected"));
- DEBUG(afbitf, "Wi-Fi OFF\n");
+ AFB_DEBUG("Wi-Fi OFF\n");
} else {/*Wi-Fi is ON*/
json_object_object_add(jresp, "Power",
json_object_new_string("ON"));
if (status->connected == 0) {/*disconnected*/
json_object_object_add(jresp, "Connection",
json_object_new_string("Disconnected"));
- DEBUG(afbitf, "Wi-Fi ON - Disconnected \n");
+ AFB_DEBUG("Wi-Fi ON - Disconnected \n");
} else {/*Connected*/
json_object_object_add(jresp, "Connection",
json_object_new_string("Connected"));
- DEBUG(afbitf, "Wi-Fi ON - Connected \n");
+ AFB_DEBUG("Wi-Fi ON - Connected \n");
}
}
afb_req_success(request, jresp, "Wi-Fi - Connection Status Checked");
@@ -622,7 +624,7 @@ static int event_add(const char *tag, const char *name)
strcpy(e->tag, tag);
/* make the event */
- e->event = afb_daemon_make_event(afbitf->daemon, name);
+ e->event = afb_daemon_make_event(name);
if (!e->event.closure) { free(e); return -1; }
/* link */
@@ -747,43 +749,31 @@ static void eventunsub (struct afb_req request)
/*
* array of the verbs exported to afb-daemon
*/
-static const struct afb_verb_desc_v1 binding_verbs[] = {
+static const struct afb_verb_v2 binding_verbs[] = {
/* VERB'S NAME SESSION MANAGEMENT FUNCTION TO CALL SHORT DESCRIPTION */
-{ .name = "activate", .session = AFB_SESSION_NONE, .callback = activate, .info = "Activate Wi-Fi" },
-{ .name = "deactivate", .session = AFB_SESSION_NONE, .callback = deactivate, .info ="Deactivate Wi-Fi" },
-{ .name = "scan", .session = AFB_SESSION_NONE, .callback = scan, .info ="Scanning Wi-Fi" },
-{ .name = "scan_result", .session = AFB_SESSION_NONE, .callback = scan_result, .info = "Get scan result Wi-Fi" },
-{ .name = "connect", .session = AFB_SESSION_NONE, .callback = connect, .info ="Connecting to Access Point" },
-{ .name = "status", .session = AFB_SESSION_NONE, .callback = status, .info ="Check connection status" },
-{ .name = "disconnect", .session = AFB_SESSION_NONE, .callback = disconnect, .info ="Disconnecting connection" },
-{ .name = "reconnect", .session = AFB_SESSION_NONE, .callback = reconnect, .info ="Reconnecting to Access Point" },
-{ .name = "insertpasskey",.session = AFB_SESSION_NONE, .callback = insertpasskey, .info ="inputs the passkey after it has been requsted"},
-{ .name = "eventadd", .session = AFB_SESSION_NONE, .callback = eventadd, .info ="adds the event of 'name' for the 'tag'"},
-{ .name = "eventsub", .session = AFB_SESSION_NONE, .callback = eventsub, .info ="unsubscribes to the event of 'tag'"},
-{ .name = "eventpush", .session = AFB_SESSION_NONE, .callback = eventpush, .info ="pushes the event of 'tag' with the 'data'"},
-{ .name = "eventunsub", .session = AFB_SESSION_NONE, .callback = eventunsub, .info ="unsubscribes to the event of 'tag'"},
-{ .name = "eventdel", .session = AFB_SESSION_NONE, .callback = eventdel, .info ="deletes the event of 'tag'"},
-
-{ .name = NULL } /* marker for end of the array */
+{ .verb = "activate", .session = AFB_SESSION_NONE, .callback = activate, .info = "Activate Wi-Fi" },
+{ .verb = "deactivate", .session = AFB_SESSION_NONE, .callback = deactivate, .info ="Deactivate Wi-Fi" },
+{ .verb = "scan", .session = AFB_SESSION_NONE, .callback = scan, .info ="Scanning Wi-Fi" },
+{ .verb = "scan_result", .session = AFB_SESSION_NONE, .callback = scan_result, .info = "Get scan result Wi-Fi" },
+{ .verb = "connect", .session = AFB_SESSION_NONE, .callback = connect, .info ="Connecting to Access Point" },
+{ .verb = "status", .session = AFB_SESSION_NONE, .callback = status, .info ="Check connection status" },
+{ .verb = "disconnect", .session = AFB_SESSION_NONE, .callback = disconnect, .info ="Disconnecting connection" },
+{ .verb = "reconnect", .session = AFB_SESSION_NONE, .callback = reconnect, .info ="Reconnecting to Access Point" },
+{ .verb = "insertpasskey",.session = AFB_SESSION_NONE, .callback = insertpasskey, .info ="inputs the passkey after it has been requsted"},
+{ .verb = "eventadd", .session = AFB_SESSION_NONE, .callback = eventadd, .info ="adds the event of 'name' for the 'tag'"},
+{ .verb = "eventsub", .session = AFB_SESSION_NONE, .callback = eventsub, .info ="unsubscribes to the event of 'tag'"},
+{ .verb = "eventpush", .session = AFB_SESSION_NONE, .callback = eventpush, .info ="pushes the event of 'tag' with the 'data'"},
+{ .verb = "eventunsub", .session = AFB_SESSION_NONE, .callback = eventunsub, .info ="unsubscribes to the event of 'tag'"},
+{ .verb = "eventdel", .session = AFB_SESSION_NONE, .callback = eventdel, .info ="deletes the event of 'tag'"},
+
+{ } /* marker for end of the array */
};
/*
* description of the binding for afb-daemon
*/
-static const struct afb_binding binding_description = {
-/* description conforms to VERSION 1 */
-.type = AFB_BINDING_VERSION_1, .v1 = { /* fills the v1 field of the union when AFB_BINDING_VERSION_1 */
-.prefix = "wifi-manager", /* the API name (or binding name or prefix) */
-.info = "wifi API", /* short description of of the binding */
-.verbs = binding_verbs /* the array describing the verbs of the API */
-} };
-
-/*
- * activation function for registering the binding called by afb-daemon
- */
-const struct afb_binding *afbBindingV1Register(
- const struct afb_binding_interface *itf) {
- afbitf = itf; // records the interface for accessing afb-daemon
- return &binding_description; // returns the description of the binding
-}
-
+const struct afb_binding_v2 afbBindingV2 = {
+ .api = "wifi-manager", /* the API name (or binding name or prefix) */
+ .specification = "wifi API", /* short description of of the binding */
+ .verbs = binding_verbs /* the array describing the verbs of the API */
+};