Skip to content
Snippets Groups Projects
dongle.c 1.25 KiB
Newer Older
  • Learn to ignore specific revisions
  • #include "common.h"
    #include "dongle_apn.h"
    #include "dongle_pin.h"
    #include "dongle_network.h"
    
    struct ubus_context *ctx;
    
    
    static struct option long_options[] =
    {
        {"debug", required_argument, NULL, 'd'}
    };
    
    int parse_args(int argc, char **argv)
    {
    	while ((ch = getopt_long(argc, argv, ":d:", long_options, NULL)) != -1) {
    	int flag;
    
    		switch (ch) {
    		case 'd':
    			flag = atoi(ch);
    			if (flag > 1 || flag < 0) {
    				debug_print("%s: option '-%c' is invalid.\n", argv[0], optopt);
    				goto fail;
    			}
    			debug = flag;
    			break;
    		case ':':
    			debug_print(stderr, "%s: option '-%c' requires an argument\n", argv[0], optopt);
    			goto fail;
    			break;
    		case '?':
    			debug_print(stderr, "%s: option '-%c' is invalid: ignored\n", argv[0], optopt);
    			goto fail;
    			break;
    		}
    	}
    	return 0;
    fail:
    	return -1;
    }
    
    
    
    void init_ubus(void)
    {
    	ctx = ubus_connect(NULL);
    	if (!ctx) {
    		perror("ubus");
    		exit(1);
    	}
    	ubus_add_uloop(ctx);
    }
    
    int main(int argc, char **argv)
    {
    
    	int rv;
    
    	rv = parse_args(argc, argv);
    	if (rv < 0)
    		goto fail;
    
    
    
    	rv = expose_apn_object(ctx);
    	if (rv < 0)
    		goto fail;
    
    	rv = expose_pin_object(ctx);
    	if (rv < 0)
    		goto fail;
    
    	rv = expose_network_object(ctx);
    	if (rv < 0)
    		goto fail;