Skip to content
Snippets Groups Projects
Select Git revision
  • 6e15cda270a060cf87c6c643a1cc3da65ffb242d
  • ex400 default
  • airoha-for-upstream
  • openwrt-24.10-airoha-uboot-fixes
  • airoha-for-upstream-en7523
  • iop-mediatek-20250604
  • ubi-fastmap
  • add-dtb-rescan
  • agnau-blorgoda
  • agnau-scratch
  • mediatek-20250604
  • iop-mediatek-20250304
  • iop-mediatek-20250304-loc
  • agnau-mtk-back
  • iop-mediatek-20250304-back
  • iop-mediatek-20220630
  • jani-multi-dtb
  • jani-multi-dtb-spl
  • mediatek-20220630
  • iop-mediatek-20220606
  • jani-env-update-mtk
  • jani-env-update-mtk-txt
  • v2025.10-rc4
  • v2025.10-rc3
  • v2025.10-rc2
  • v2025.10-rc1
  • v2025.07
  • v2025.07-rc5
  • v2025.07-rc4
  • v2025.07-rc3
  • v2025.07-rc2
  • v2025.07-rc1
  • v2025.04
  • v2025.04-rc5
  • v2025.04-rc4
  • v2025.04-rc3
  • v2025.04-rc2
  • v2025.04-rc1
  • v2025.01
  • v2025.01-rc6
  • v2025.01-rc5
  • v2025.01-rc4
42 results

README.bcm7xxx

Blame
  • dongle_apn.c 3.37 KiB
    #include <stdlib.h>
    #include <stdio.h>
    #include <stdbool.h>
    #include <unistd.h>
    #include <getopt.h>
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <fcntl.h>
    #include <signal.h>
    #include <time.h>
    #include <limits.h>
    
    #include <libubox/list.h>
    
    #include "common.h"
    
    struct ubus_context *ctx;
    
    enum {
    	APN,
    	__APN_MAX,
    };
    
    const struct blobmsg_policy apn_policy[__APN_MAX] = {
    	[APN] = {.name = "apn", .type = BLOBMSG_TYPE_STRING},
    };
    
    int list_apn_profiles(struct ubus_context *ctx, struct ubus_object *obj,
    			   struct ubus_request_data *req, const char *method,
    			   struct blob_attr *msg)
    {
    	char *response = mobile_get_apn_profiles();
    	struct json_object *parsed_response = parse_apn_profiles(response);
    
    	write_to_ubus(parsed_response, ctx, req);
    	json_object_put(parsed_response);
    	return 0;
    	//return parse_and_print(response, ctx, req);
    }
    
    int delete_apn_profile(struct ubus_context *ctx, struct ubus_object *obj,
    			   struct ubus_request_data *req, const char *method,
    			   struct blob_attr *msg)
    {
    	struct blob_attr *tb[__APN_MAX];
    	char name[1024] = {0}; //what is max available name length in dongle?
    
    	blobmsg_parse(apn_policy, __APN_MAX, tb, blob_data(msg), blob_len(msg));
    	strncpy(name, (char *)blobmsg_data(tb[APN]), 1023);
    	char *response = mobile_delete_apn(name);
    
    	return parse_and_print(response, ctx, req);
    }
    
    int set_apn_profile(struct ubus_context *ctx, struct ubus_object *obj,
    					   struct ubus_request_data *req, const char *method,
    					   struct blob_attr *msg)
    {
    	struct blob_attr *tb[__APN_MAX];
    	char name[1024] = {0}; //STR_MAX or something from limits.h
    
    	blobmsg_parse(apn_policy, __APN_MAX, tb, blob_data(msg), blob_len(msg));
    	strncpy(name, (char *)blobmsg_data(tb[APN]), 1023);
    
    	char *response = mobile_set_apn_profile(name);
    
    	return parse_and_print(response, ctx, req);
    }
    
    int create_apn_profile(struct ubus_context *ctx, struct ubus_object *obj,
    				struct ubus_request_data *req, const char *method,
    				struct blob_attr *msg)
    {
    	struct blob_attr *tb[__APN_MAX];
    	char name[1024] = {0}; //STR_MAX or something from limits.h
    
    	blobmsg_parse(apn_policy, __APN_MAX, tb, blob_data(msg), blob_len(msg));
    
    	strncpy(name, (char *)blobmsg_data(tb[APN]), 1023);
    	char *response = mobile_create_apn_profile(name);
    
    	return parse_and_print(response, ctx, req);
    }
    
    int show_current_apn(struct ubus_context *ctx, struct ubus_object *obj,
    				 struct ubus_request_data *req, const char *method,
    				 struct blob_attr *msg)
    {
    	//char *wan_apn = mobile_get_request("wan_apn");
    	char *response = mobile_get_wan_apn();
    
    	return parse_and_print(response, ctx, req);
    }
    
    struct ubus_method dongle_object_methods[] = {
    	UBUS_METHOD_NOARG("list", list_apn_profiles),
    	UBUS_METHOD("create", create_apn_profile, apn_policy),
    	UBUS_METHOD("delete", delete_apn_profile, apn_policy),
    	UBUS_METHOD("set_profile", set_apn_profile, apn_policy),
    	UBUS_METHOD_NOARG("current", show_current_apn),
    };
    
    struct ubus_object_type dongle_object_type = UBUS_OBJECT_TYPE("dongle", dongle_object_methods);
    
    struct ubus_object dongle_object = {
    	.name = "dongle.apn",
    	.type = &dongle_object_type,
    	.methods = dongle_object_methods,
    	.n_methods = ARRAY_SIZE(dongle_object_methods),
    };
    
    void init_ubus(void)
    {
    	ctx = ubus_connect(NULL);
    	if (!ctx) {
    		perror("ubus");
    		exit(1);
    	}
    	ubus_add_uloop(ctx);
    }
    
    int main(int argc, char **argv)
    {
    	uloop_init();
    	init_ubus();
    	ubus_add_object(ctx, &dongle_object);
    	uloop_run();
    
    	return 0;
    }