Skip to content
Snippets Groups Projects
Commit a0a0baf2 authored by Jakob Olsson's avatar Jakob Olsson
Browse files

new approach through ubus call, gets IP addr, incomplete

parent f45a2951
Branches
No related tags found
No related merge requests found
#include "common.h" #include "common.h"
int get_ip(char *if_name) /*
{ TODO:
struct ifaddrs *ifaddr, *ifa; Initial
1. system call //"ubus call router.net ipv4_routes | grep -B 7 \"usb0\" | grep \"flag.
*H\" -B 4 | grep destination"
2. grep for [H]ost flag
3. find IP
getifaddrs(&ifaddr); Once Successful
ifa = ifaddr; 1. Implement by invoking ubus
while (ifa != NULL) { */
if (strcmp(ifa->ifa_addr, if_name) != 0) int get_ip(char *if_name)
continue; {
char response[1024] = {0};
FILE *fp = popen("ubus call router.net ipv4_routes | grep -B 7 \"usb0\" | grep \"flag.*H\" -B 4 | grep destination | cut -d ' ' -f2 | cut -d '\"' -f2", "r");
if (ifa->ifa_addr && ifa->ifa_addr->sa_family == AF_INET) { fscanf(fp, "%s", response);
struct sockaddr_in *pAddr = (struct sockaddr_in *)ifa->ifa_addr; pclose(fp);
printf("ip: %s\n", inet_ntoa(pAddr->sin_addr)); printf("%s\n", response);
}
ifa = ifa->ifa_next;
}
freeififaddrs(ifaddr);
return 0; return 0;
} }
......
...@@ -12,14 +12,6 @@ ...@@ -12,14 +12,6 @@
#include <time.h> #include <time.h>
#include <limits.h> #include <limits.h>
#include <libubox/list.h> #include <libubox/list.h>
#include <ifaddrs.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <net/if.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netdb.h>
#include "libmobile.h" #include "libmobile.h"
#include <json-c/json.h> #include <json-c/json.h>
......
...@@ -2,11 +2,13 @@ ...@@ -2,11 +2,13 @@
static enum { static enum {
IP, IP,
DEV,
__IP_MAX __IP_MAX
}; };
static const struct blobmsg_policy ip_policy[__IP_MAX] = { static const struct blobmsg_policy ip_policy[__IP_MAX] = {
[IP] = {.name = "ip_addr", .type = BLOBMSG_TYPE_STRING} [IP] = {.name = "ip_addr", .type = BLOBMSG_TYPE_STRING},
[DEV] = {.name = "dev", .type = BLOBMSG_TYPE_STRING}
}; };
int get_signal_strength(struct ubus_context *ctx, struct ubus_object *obj, int get_signal_strength(struct ubus_context *ctx, struct ubus_object *obj,
...@@ -198,6 +200,23 @@ fail_unknown: ...@@ -198,6 +200,23 @@ fail_unknown:
return UBUS_STATUS_UNKNOWN_ERROR; return UBUS_STATUS_UNKNOWN_ERROR;
} }
int test_get_ip(struct ubus_context *ctx, struct ubus_object *obj,
struct ubus_request_data *req, const char *method,
struct blob_attr *msg)
{
struct blob_attr *tb[__IP_MAX];
char *dev;
blobmsg_parse(ip_policy, __IP_MAX, tb, blob_data(msg), blob_len(msg));
if (tb[DEV]) {
dev = (char *)blobmsg_data(tb[DEV]);
get_ip(dev);
}
return 0;
}
struct ubus_method network_object_methods[] = { struct ubus_method network_object_methods[] = {
UBUS_METHOD("signal_strength", get_signal_strength, ip_policy), UBUS_METHOD("signal_strength", get_signal_strength, ip_policy),
UBUS_METHOD("connect", connect_network, ip_policy), UBUS_METHOD("connect", connect_network, ip_policy),
...@@ -206,6 +225,7 @@ struct ubus_method network_object_methods[] = { ...@@ -206,6 +225,7 @@ struct ubus_method network_object_methods[] = {
UBUS_METHOD("enable_roaming", enable_roaming, ip_policy), UBUS_METHOD("enable_roaming", enable_roaming, ip_policy),
UBUS_METHOD("disable_roaming", disable_roaming, ip_policy), UBUS_METHOD("disable_roaming", disable_roaming, ip_policy),
UBUS_METHOD("roam_status", roam_status, ip_policy), UBUS_METHOD("roam_status", roam_status, ip_policy),
UBUS_METHOD("get_ip", test_get_ip, ip_policy)
}; };
struct ubus_object_type network_object_type = UBUS_OBJECT_TYPE("dongle", network_object_methods); struct ubus_object_type network_object_type = UBUS_OBJECT_TYPE("dongle", network_object_methods);
......
...@@ -562,6 +562,6 @@ struct json_object *mobile_unlock_sim(char *ip_addr, char *pin, char *puk) ...@@ -562,6 +562,6 @@ struct json_object *mobile_unlock_sim(char *ip_addr, char *pin, char *puk)
char query[1024] = {0}; char query[1024] = {0};
snprintf(query, 1023, "isTest=false&goformId=ENTER_PUK&PUKNumber=%s&PinNumber=%s&pin_save_flag=0", puk, pin); snprintf(query, 1023, "isTest=false&goformId=ENTER_PUK&PUKNumber=%s&PinNumber=%s&pin_save_flag=0", puk, pin);
printf("query %s\n"); printf("query %s\n", query);
return prepare_request(ip_addr, query, POST); return prepare_request(ip_addr, query, POST);
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment