url: address_str
onTextMessageReceived: {
var message_json = JSON.parse(message)
- //console.log("Raw response: " + message)
- //console.log("JSON response: " + message_json)
+ console.debug("Raw response: " + message)
/* server is not happy with our request, ignore it */
if ((message_json[0] === msgid_enu.reterr)) {
- console.log("Return value is not ok !")
- console.log("Raw response: " + message)
+ console.error("Return value is not OK!")
+ console.error("Raw response: " + message)
return
} else if ((message_json[0] === msgid_enu.event)) {
var eventContent = JSON.parse(JSON.stringify(message_json[2]))
- console.log("Return value is EVENT: " + eventContent.event)
+ console.log("Received EVENT: " + eventContent.event)
if (eventContent.event === "wifi-manager/networkListUpdated") {
- console.log("Event data:" + eventContent.data.data1 + ", " + eventContent.data.data2 )
+ console.debug("Event data:" + eventContent.data.data1 + ", " + eventContent.data.data2 )
console.log("Network List was updated, sending scan_result request")
//update network list
else if (eventContent.event === "wifi-manager/passwordQuery") {
- console.log("Event data:" + eventContent.data.data1 + ", " + eventContent.data.data2 )
-
+ console.debug("Event data:" + eventContent.data.data1 + ", " + eventContent.data.data2 )
console.log("Passkey requested")
dialog.visible = true
}
} else
- console.log("ELSE msgid", message_json[0])
+ console.log("Unhadled websocket message", message_json[0])
}
onStatusChanged: {
var parameterJson = 0
var requestJson = 0
- console.log("Status changed")
if (websocket.status == WebSocket.Error) {
status_str = "Error: " + websocket.errorString
//subscribe for events
-
//network list updated event
verb_str = "eventadd"
parameterJson = {
}
console.log(status_str)
- console.log(websocket.status)
}
active: false
}
} else {
- console.log("Connect to", index, " ,", name)
+ console.log("Requesting connection to network #", index, ", ", name, ".")
view.currentIndex = model.index
//make some indication that connection is in progress
//MyObject *myobj = user_data;
if (g_strcmp0(method_name, "RequestInput") == 0) {
- printf("Input requested\n");
+ DEBUG(afbitf,"RequestInput method on Agent interface has been called\n");
invocation_passkey = invocation;
)
]
*/
- printf("Passphrase requested for network : %s\n", object_path);
+ NOTICE(afbitf,"Passphrase requested for network : %s\n", object_path);
(*password_callback)(0, object_path);
}
if (g_strcmp0(method_name, "ReportError") == 0) {
- printf("Error reported\n");
+ ERROR(afbitf,"ReportError method on Agent interface has een called\n");
gchar *error_string; // = NULL;
gchar * object_path;
g_variant_get(parameters, "(os)", &object_path, &error_string);
- printf("Error %s for %s\n", error_string, object_path);
+ ERROR(afbitf, "Error %s for %s\n", error_string, object_path);
if (g_strcmp0(error_string, "invalid-key") == 0) {
- printf("Passkey is not correct.\n");
+ WARNING(afbitf, "Passkey is not correct.\n");
(*password_callback)(1, "invalid-key");
}
GVariantBuilder *builder;
GVariant *value = NULL;
- printf("Passkey to send: %s\n", passkey);
+ NOTICE(afbitf, "Passkey to send: %s\n", passkey);
builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
static void test_signal_handler (GDBusConnection *connection, const gchar *sender_name, const gchar *object_path, const gchar *interface_name, const gchar *signal_name, GVariant *parameters, gpointer user_data) {
- //openlog("WIFI Binder", LOG_PID | LOG_CONS, LOG_USER);
-
-
//do not parse, just check what has changed and make callback -
// we need to refresh completelist anyway..
if (g_strcmp0(signal_name, "PropertiesChanged") == 0) {
- //syslog(LOG_INFO, "PropertiesChanged");
(*wifiListChanged_callback)(1, "PropertiesChanged");
}
else if (g_strcmp0(signal_name, "BSSRemoved") == 0) {
- //syslog(LOG_INFO, "BSSRemoved" );
(*wifiListChanged_callback)(2, "BSSRemoved");
}
- else if (g_strcmp0(signal_name, "BSSAdded") == 0) {
- //syslog(LOG_INFO, "BSSAdded" );
+ else if (g_strcmp0(signal_name, "BSSAdded") == 0) {
(*wifiListChanged_callback)(2, "BSSAdded");
}
- else printf ("unhandled signal %s %s %s, %s", sender_name, object_path, interface_name, signal_name);//syslog(LOG_INFO, "unhandled signal %s %s %s, %s", sender_name, object_path, interface_name, signal_name);
-
-
-
- //closelog();
-
-
+ else WARNING(afbitf,"unhandled signal %s %s %s, %s", sender_name, object_path, interface_name, signal_name);
}
void* register_agent(void *data) {
- printf("Loop start\n");
-
guint owner_id;
guint networkChangedID;
//sleep(10);
g_main_loop_run(loop);
- printf("Loop running\n");
-
g_bus_unown_name(owner_id);
g_dbus_node_info_unref(introspection_data);
//g_object_unref(myobj);
- //printf("Loop end\n");
-
return NULL;
}
err = pthread_create((&tid[0]), NULL, register_agent, NULL);
if (err != 0) {
- printf("\ncan't create thread :[%d]", err);
- printf("Fatal error!\n\n");
+ ERROR(afbitf,"\ncan't create thread :[%d]", err);
+ ERROR(afbitf,"Fatal error!\n\n");
return NULL;
}
DBUS_REPLY_TIMEOUT, NULL, &error);
if (error) {
- printf("error: %d:%s\n", error->code, error->message);
+ ERROR(afbitf,"error: %d:%s\n", error->code, error->message);
return error;
} else {
- printf("Agent registered\n");
+ INFO(afbitf,"Agent registered\n");
return NULL;
}
DBUS_REPLY_TIMEOUT, NULL, &error);
if (error) {
- printf("error: %d:%s\n", error->code, error->message);
+ ERROR(afbitf, "error: %d:%s\n", error->code, error->message);
return error;
} else {
- printf("Agent unregistered\n");
+ DEBUG(afbitf,"Agent unregistered\n");
return NULL;
}
#include "wifi-api.h"
#include "wifi-connman.h"
-/*
- * the interface to afb-daemon
- */
-const struct afb_binding_interface *afbitf;
+
static int need_password_flag = 0;
static int password_not_correct_flag = 0;
/* retrieves the argument, expects password string */
passkey_from_user = afb_req_value(request, "passkey");
- printf("Passkey inserted: %s\n", passkey_from_user);
+ NOTICE(afbitf, "Passkey inserted: %s\n", passkey_from_user);
sendPasskey(passkey_from_user);
registerPasskey(passkey);
} else {
- printf("Please enter the password first\n");
+ NOTICE(afbitf, "Please enter the password first\n");
}
}
*
* */
void ask_for_passkey(int number, const char* asciidata) {
- //TODO: show network we are asking password for
- printf("Insert passkey.\n");
- ERROR(afbitf, "Insert passkey.");
+ NOTICE(afbitf, "Passkey for %s network needed.", asciidata);
+ NOTICE(afbitf, "Sending event.");
json_object *jresp = json_object_new_object();
if (ptr_my_callback == NULL) {
- printf("Registering callback\n");
-
ptr_my_callback = ask_for_passkey;
register_callbackSecurity(ptr_my_callback);
if (wifiListChanged_clbck == NULL) {
- printf("Registering callback wifiListChanged_clbck \n");
-
wifiListChanged_clbck = wifiListChanged;
register_callbackWiFiList(wifiListChanged_clbck);
json_object_object_add(jresp, "IPAddress", jstring3);
json_object_object_add(jresp, "State", jstring4);
- //printf("The object json: %s\n", json_object_to_json_string(jresp));
+ DEBUG(afbitf, "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);
number += 1;
}
while (list != NULL) {
- printf("Should be freed");
holdMe = list->next;
g_free(list);
list = holdMe;
else {
network_index = atoi(network);
- printf("Joining network number %d\n", network_index);
+ NOTICE(afbitf,"Joining network number %d\n", network_index);
+
}
if (item == NULL) {
//Index starts from 1
- printf("Network with number %d not found.\n", network_index + 1);
+ ERROR(afbitf, "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;
- printf("Name: %s, strength: %d, %s\n", wifiProfileToConnect->ESSID,
+ INFO(afbitf, "Name: %s, strength: %d, %s\n", wifiProfileToConnect->ESSID,
wifiProfileToConnect->Strength,
wifiProfileToConnect->NetworkPath);
- //printf ("Connecting to %s\n", wifiProfileToConnect->NetworkPath);
}
error = do_connectNetwork(wifiProfileToConnect->NetworkPath);
else {
network_index = atoi(network);
- printf("Joining network number %d\n", network_index);
+ NOTICE(afbitf, "Joining network number %d\n", network_index);
}
if (item == NULL) {
//Index starts from 1
- printf("Network with number %d not found.\n", network_index + 1);
+ ERROR(afbitf,"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;
- printf("Name: %s, strength: %d, %s\n", wifiProfileToConnect->ESSID,
+ INFO(afbitf, "Name: %s, strength: %d, %s\n", wifiProfileToConnect->ESSID,
wifiProfileToConnect->Strength,
wifiProfileToConnect->NetworkPath);
- //printf ("Connecting to %s\n", wifiProfileToConnect->NetworkPath);
}
error = do_disconnectNetwork(wifiProfileToConnect->NetworkPath);
json_object_object_add(jresp, "Power",
json_object_new_string("OFF"));
//json_object_object_add(jresp, "Connection", json_object_new_string("Disconnected"));
- printf("Wi-Fi OFF\n");
+ DEBUG(afbitf, "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"));
- printf("Wi-Fi ON - Disconnected \n");
+ DEBUG(afbitf, "Wi-Fi ON - Disconnected \n");
} else {/*Connected*/
json_object_object_add(jresp, "Connection",
json_object_new_string("Connected"));
- printf("Wi-Fi ON - Connected \n");
+ DEBUG(afbitf, "Wi-Fi ON - Connected \n");
}
}
afb_req_success(request, jresp, "Wi-Fi - Connection Status Checked");
const char *tag = afb_req_value(request, "tag");
const char *name = afb_req_value(request, "name");
- printf ("Name: %s\n", name);
- printf ("Tag: %s\n", tag);
-
json_object *query = afb_req_json(request);
if (tag == NULL || name == NULL)
#include "wifi-api.h"
#include "wifi-connman.h"
-//#include "syslog.h"
-
static __thread struct security_profile Security = { NULL, NULL, NULL, NULL, 0,
0 };
}
}
}
- //printf ("SSID= %s, security= %s, Strength= %d, wps support= %d\n", wifiProfile->ESSID, wifiProfile->Security.sec_type, wifiProfile->Strength, wifiProfile->Security.wps_support);
return 0;
}
connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
if (connection == NULL) {
- printf("GDBusconnection is NULL");
+ ERROR(afbitf,"Cannot connect to D-Bus, %s", error->message);
return -1;
}
message = g_dbus_connection_call_sync(connection, CONNMAN_SERVICE,
NULL, NULL, G_DBUS_CALL_FLAGS_NONE,
DBUS_REPLY_TIMEOUT, NULL, &error);
if (message == NULL) {
- printf("message is NULL");
- return -1;
+ ERROR(afbitf,"Error %s while calling GetProperties method", error->message);
+ return -1;
}
g_variant_get(message, "(a{sv})", &array);
while (g_variant_iter_loop(array, "{sv}", &key, &var)) {
connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
if (connection == NULL) {
- printf("GDBusconnection is NULL");
- return error;
+ ERROR(afbitf,"Cannot connect to D-Bus, %s", error->message);
+ return error;
}
//create the agent to handle security
params, NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, &error);
if (error) {
- printf("error: %d:%s\n", error->code, error->message);
+ ERROR(afbitf,"Error %s while calling SetProperty method", error->message);
return error;
}
else {
- printf("Power ON succeeded\n");
+ NOTICE(afbitf,"Power ON succeeded\n");
return NULL;
}
/*connection = gdbus_conn->connection;*/
connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
if (connection == NULL) {
- printf("GDBusconnection is NULL");
- return error;
+ ERROR(afbitf,"Cannot connect to D-Bus, %s", error->message);
+ return error;
}
//create the agent to handle security
error = stop_agent(connection);
if (error) {
- printf("Error while unregistering the agent, ignoring.");
+ WARNING(afbitf, "Error while unregistering the agent, ignoring.");
}
params, NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, &error);
if (error) {
- printf("error: %d:%s\n", error->code, error->message);
+ ERROR(afbitf,"Error %s while calling SetProperty method", error->message);
return error;
}
else {
- printf("Power OFF succeeded\n");
+ NOTICE(afbitf, "Power OFF succeeded\n");
return NULL;
}
}
/*connection = gdbus_conn->connection;*/
connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
if (connection == NULL) {
- printf("GDBusconnection is NULL");
- return error;
+ ERROR(afbitf,"Cannot connect to D-Bus, %s", error->message);
+ return error;
}
g_dbus_connection_call(connection, CONNMAN_SERVICE,
CONNMAN_WIFI_TECHNOLOGY_PREFIX, CONNMAN_TECHNOLOGY_INTERFACE, "Scan", NULL,
NULL, G_DBUS_CALL_FLAGS_NONE, DBUS_REPLY_TIMEOUT, NULL, NULL, &error);
if (error) {
- printf("error: %d:%s\n", error->code, error->message);
+ ERROR(afbitf,"Error %s while calling Scan method", error->message);
return error;
}
else {
- printf("Scan succeeded\n");
+ INFO(afbitf, "Scan succeeded\n");
return NULL;
}
}
/*connection = gdbus_conn->connection;*/
connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
if (connection == NULL) {
- printf("GDBusconnection is NULL");
- return error;
+ ERROR(afbitf,"Cannot connect to D-Bus, %s", error->message);
+ return error;
}
message = g_dbus_connection_call_sync(connection, CONNMAN_SERVICE,
CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE, "GetServices", NULL, NULL,
G_DBUS_CALL_FLAGS_NONE,
DBUS_REPLY_TIMEOUT, NULL, &error);
if (message == NULL) {
- printf("message is NULL");
- return error;
+ ERROR(afbitf,"Error %s while calling GetServices method", error->message);
+ return error;
}
g_variant_get(message, "(a(oa{sv}))", &array);
while (g_variant_iter_loop(array, "(oa{sv})", &object, &content)) {
extract_values(content, wifiProfile);
wifiProfile->NetworkPath = g_try_malloc0(strlen(object));
strcpy(wifiProfile->NetworkPath, object);
- /*printf(
+ DEBUG(afbitf,
"SSID= %s, security= %s, path= %s, Strength= %d, wps support= %d\n",
wifiProfile->ESSID, wifiProfile->Security.sec_type,
wifiProfile->NetworkPath, wifiProfile->Strength,
wifiProfile->Security.wps_support);
- printf("method= %s, ip address= %s, netmask= %s\n",
+ DEBUG(afbitf, "method= %s, ip address= %s, netmask= %s\n",
wifiProfile->wifiNetwork.method,
wifiProfile->wifiNetwork.IPaddress,
- wifiProfile->wifiNetwork.netmask);*/
+ wifiProfile->wifiNetwork.netmask);
*wifi_list = g_slist_append(*wifi_list,
(struct wifi_profile_info *) wifiProfile);
}
GError* do_connectNetwork(gchar *networkPath) {
- printf("Connecting to: %s\n", networkPath);
+ NOTICE(afbitf, "Connecting to: %s\n", networkPath);
GVariant *message = NULL;
GError *error = NULL;
G_DBUS_CALL_FLAGS_NONE,
DBUS_REPLY_TIMEOUT_SHORT, NULL, &error);
- //printf("message error %s\n", message);
//TODO: do we need retunrn value in message
if (error) {
- printf("do_connectNetwork error: %s\n", error->message);
- return error;
+ ERROR(afbitf,"Error %s while calling Connect method", error->message);
+ return error;
} else {
- printf("Connection succeeded\n");
+ INFO(afbitf,"Connection succeeded\n");
return NULL;
}
GError* do_disconnectNetwork(gchar *networkPath) {
- printf("Connecting to: %s\n", networkPath);
+ NOTICE(afbitf, "Connecting to: %s\n", networkPath);
GVariant *message = NULL;
GError *error = NULL;
connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+ if (connection == NULL) {
+ ERROR(afbitf,"Cannot connect to D-Bus, %s", error->message);
+ return error;
+ }
+
message = g_dbus_connection_call_sync(connection, CONNMAN_SERVICE,
networkPath, CONNMAN_SERVICE_INTERFACE, "Disconnect", NULL, NULL,
G_DBUS_CALL_FLAGS_NONE,
//TODO: do we need return value in message
if (error) {
- printf("error: %s\n", error->message);
- return error;
+ ERROR(afbitf,"Error %s while calling Disconnect method", error->message);
+ return error;
} else {
- printf("Disconnected\n");
- return NULL;
+ INFO(afbitf,"Disconnection succeeded\n");
+ return NULL;
}
}
void registerPasskey(gchar *passkey) {
- printf("Passkey: %s\n", passkey);
+ INFO(afbitf,"Passkey: %s\n", passkey);
sendPasskey(passkey);
GVariant *message = NULL;
GError *error = NULL;
- //openlog("WIFI Binder", LOG_PID | LOG_CONS, LOG_USER);
-
if (state==BAR_NO) iconString = "qrc:/images/Status/HMI_Status_Wifi_NoBars-01.png";
else if (state==BAR_1) iconString = "qrc:/images/Status/HMI_Status_Wifi_1Bar-01.png";
else if (state==BAR_2) iconString = "qrc:/images/Status/HMI_Status_Wifi_2Bars-01.png";
else if (state==BAR_3) iconString = "qrc:/images/Status/HMI_Status_Wifi_3Bars-01.png";
else if (state==BAR_FULL) iconString = "qrc:/images/Status/HMI_Status_Wifi_Full-01.png";
- //else {syslog(LOG_ERR, "Default value for wifi HMI icon, should not happened.. : %d", state);
- // iconString = "qrc:/images/Status/HMI_Status_Wifi_NoBars-01.png";
- //}
-
- //syslog(LOG_INFO, "%s", iconString);
connection = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
+ if (connection == NULL) {
+ ERROR(afbitf,"Cannot connect to D-Bus, %s", error->message);
+ return error;
+ }
+
params = g_variant_new("(is)", HOMESCREEN_WIFI_ICON_POSITION, iconString);
message = g_dbus_connection_call_sync(connection, HOMESCREEN_SERVICE,
DBUS_REPLY_TIMEOUT, NULL, &error);
if (error) {
- printf("error: %s\n", error->message);
+ ERROR(afbitf,"Error %s while setting up the status icon", error->message);
return error;
} else {
return NULL;
}
- //closelog();
-
}
* limitations under the License.
*/
+#define _GNU_SOURCE
+
//#include <dlog.h>
#include <glib.h>
#include <stdlib.h>
#include <gio/gio.h>
#include <glib-object.h>
+#include <afb/afb-binding.h>
+
#ifdef __cplusplus
extern "C" {
#endif
+//
+
+
+/*
+ * the interface to afb-daemon
+ */
+const struct afb_binding_interface *afbitf;
+
/** Maximum Profile Count */
#define CONNMAN_MAX_BUFLEN 512