From 2fa13f737b6595b909833bfdbe2656293f59c80a Mon Sep 17 00:00:00 2001 From: Jakob Olsson <jakobols@kth.se> Date: Tue, 5 Jun 2018 11:31:32 +0200 Subject: [PATCH] prepared for compilation - still few items to add --- Makefile | 19 +++++++++---------- common.h | 10 +++++++++- dongle.c | 4 ++-- dongle_apn.h | 6 ++++++ dongle_infrastructure.c | 35 +++-------------------------------- dongle_infrastructure.h | 8 -------- dongle_network.h | 28 ++++++++++++++++++++++++++++ stack_operations.c | 2 +- 8 files changed, 58 insertions(+), 54 deletions(-) create mode 100644 dongle_apn.h create mode 100644 dongle_network.h diff --git a/Makefile b/Makefile index f38c1ce..b8c7caf 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,9 @@ -CC = gcc +CC = gcc CWFLAGS = -g -Wall CFLAGS += "-I$(STAGING_DIR)/usr/include/libxml2/" -LIBS = -ljson-c -lubox -lubus -lcurl -lmobile_zte -lmobile_hilink -lblobmsg_json - -all: libmobile1_zte libmobile2_zte libmobile1_hilink libmobile2_hilink common_hilink common_zte stack dongle_infrastructure dongle +LIBS = -ljson-c -lubox -lubus -lcurl -lblobmsg_json -lxml2 +# -lmobile_zte -lmobile_hilink +all: libmobile1_zte libmobile2_zte libmobile1_hilink libmobile2_hilink common stack_operations dongle_infrastructure dongle ZOBJS = libmobile_zte.o ZSRCS = libmobile_zte.c @@ -24,27 +24,26 @@ libmobile2_hilink: ${HLOBJS} COBJS = common.o CSRCS = common.c common: ${COBJS} - ${CC} -c ${CFLAGS} ${CSRCS} -o ${COBJS} + ${CC} -c ${CFLAGS} ${CSRCS} -o ${COBJS} -lmobile_zte STOBJS = stack_operations.o STSRCS = stack_operations.c stack_operations: ${STOBJS} - ${CC} -c ${STSRCS} -o ${STOBJS} + ${CC} -c ${CFLAGS} ${STSRCS} -o ${STOBJS} DIOBJS = dongle_infrastructure.o DISRCS = dongle_infrastructure.c dongle_infrastructure: ${DIOBJS} - ${CC} -c ${CWFLAGS} ${DISRCS} ${STOBJS} ${COBJS} -o ${DIOBJS} -L . ${LIBS} + ${CC} -c ${CWFLAGS} ${CFLAGS} ${DISRCS} ${STOBJS} ${COBJS} -o ${DIOBJS} -L . ${LIBS} -lmobile_zte dongle: dongle.o - ${CC} ${CWFLAGS} dongle.o ${ZCOBJS} ${DIOBJS} ${STOBJS} -o dongle -L . ${LIBS} + ${CC} ${CWFLAGS} ${CFLAGS} dongle.o ${DIOBJS} ${STOBJS} ${COBJS} -o dongle -L . ${LIBS} -lmobile_zte clean: - rm -f dongle *.o *.so + rm -f dongle_apn dongle_pin dongle_network *.o *.so codingstyle: checkpatch.pl --no-tree -f *.c --terse cppcheck: cppcheck --enable=all *.c - diff --git a/common.h b/common.h index f9bc760..9d447c7 100644 --- a/common.h +++ b/common.h @@ -23,7 +23,7 @@ #include <libxml/xpath.h> #include <libxml/xpathInternals.h> -#include "libmobile_hilink.h" +//#include "libmobile_hilink.h" #include "libmobile_zte.h" extern int debug; @@ -36,6 +36,14 @@ extern struct ubus_context *global_ctx; fprintf(stderr, __VA_ARGS__); \ } while (0) +#define TAG_CONTENT_SIZE 100 + +struct write_result +{ + char *data; + int pos; +}; + char *get_ip(char *if_name); /** * Function: print_to_ubus diff --git a/dongle.c b/dongle.c index cb7ab4d..3ed2e8a 100644 --- a/dongle.c +++ b/dongle.c @@ -25,10 +25,10 @@ static struct option long_options[] = { {0, 0, 0, 0} }; -enum { +/*enum { DEV, __DEV_MAX -}; +};*/ const struct blobmsg_policy dev_policy[__DEV_MAX] = { [DEV] = {.name = "dev", .type = BLOBMSG_TYPE_STRING}, diff --git a/dongle_apn.h b/dongle_apn.h new file mode 100644 index 0000000..1a4fb65 --- /dev/null +++ b/dongle_apn.h @@ -0,0 +1,6 @@ +#ifndef DONGLE_APN_H +#define DONGLE_APN_H +#include "common.h" + +int expose_apn_object(struct ubus_context *ctx); +#endif diff --git a/dongle_infrastructure.c b/dongle_infrastructure.c index 9ac7616..deb7e9c 100644 --- a/dongle_infrastructure.c +++ b/dongle_infrastructure.c @@ -18,38 +18,6 @@ #include "dongle.h" #include "stack_operations.h" -struct ubus_object *dongle_create_dynamic_object(struct device *dev_instance); -int publish_ubus_object(struct ubus_context *ctx, struct ubus_object *obj); -int unpublish_ubus_object(struct ubus_context *ctx, struct ubus_object *obj); -void dongle_destroy_dynamic_object(struct ubus_object *obj); -int get_devices(void); -char *get_device_ip(char *device_name); -char *get_device_ip_alt(char *device_name); -int tag_missing_devices(void); -int add_device(struct device *node); -int delete_device_all_devices(void); -int delete_device_by_name(char *name); -int delete_device(struct device *dev); -void free_device(struct device *dev); -void free_usb(struct USB *usb); -struct device *search_list(char *name); - - - - -int expose_infrastructure_object(struct ubus_context *ctx) -{ - int rv; - - rv = ubus_add_object(ctx, &infrastructure_object); - if (rv) { - debug_print("failed to add dongle.pin to ubus!\n"); - return -1; - } - - return 0; -} - //dynamic object policies.. const struct blobmsg_policy set_pin_policy[__SET_PIN_MAX] = { [NEW_PIN] = {.name = "new_pin", .type = BLOBMSG_TYPE_STRING}, @@ -460,6 +428,9 @@ int unlock_sim(struct ubus_context *ctx, struct ubus_object *obj, if (json_object_get_int(rv_json) > 0) goto fail_unknown; */ + + blobmsg_parse(pin_policy, __PIN_MAX, tb, blob_data(msg), blob_len(msg)); + if (!tb[PUK] || !tb[UNLOCK_PIN]) { debug_print("Please enter both a pin and a puk code!\n"); goto fail_input; diff --git a/dongle_infrastructure.h b/dongle_infrastructure.h index 3fb0282..22b32cd 100644 --- a/dongle_infrastructure.h +++ b/dongle_infrastructure.h @@ -46,14 +46,6 @@ enum { }; -struct USB { - char *product; - char *product_id; - char *vendor_id; - char *if_name; -}; - - int devices_status(struct uloop_timeout *t); struct ubus_object *dongle_create_dynamic_object(struct device *dev_instance); int publish_ubus_object(struct ubus_context *ctx, struct ubus_object *obj); diff --git a/dongle_network.h b/dongle_network.h new file mode 100644 index 0000000..8fd12af --- /dev/null +++ b/dongle_network.h @@ -0,0 +1,28 @@ +#ifndef NETWORK_H +#define NETWORK_H +#include "common.h" + +int expose_network_object(struct ubus_context *ctx); + +int get_signal_strength(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg); +int connect_network(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg); +int disconnect(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg); +int modem_state(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg); +int enable_roaming(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg); +int disable_roaming(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg); +int roam_status(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg); +#endif diff --git a/stack_operations.c b/stack_operations.c index 3116d1c..25add58 100644 --- a/stack_operations.c +++ b/stack_operations.c @@ -1,4 +1,4 @@ -#include "stack.h" +#include "stack_operations.h" void push(struct directory *dr, struct list_head *list) { -- GitLab