Skip to content
Snippets Groups Projects
dslmngr.c 64.3 KiB
Newer Older
  • Learn to ignore specific revisions
  • {
    	struct uci_context *ctx;
    	struct uci_package *pkg;
    	struct uci_element *e;
    	const char *value;
    
    	ctx = uci_alloc_context();
    	if (!ctx)
    		return -1;
    
    	if (uci_load(ctx, "dsl", &pkg)) {
    		uci_free_context(ctx);
    		return -1;
    	}
    
    	uci_foreach_element(&pkg->sections, e) {
    		struct uci_section *s = uci_to_section(e);
    		if (!strcmp(s->type, "oem-parameters")) {
    			value = uci_lookup_option_string(ctx, s, "country_code");
    			if (value)
    				sscanf(value, "%2hhX%2hhX", vendor_id, vendor_id + 1);
    			value = uci_lookup_option_string(ctx, s, "vendor_id");
    			if (value)
    				strncpy(vendor_id + 2, value, 4);
    			value = uci_lookup_option_string(ctx, s, "vendor_suffix");
    			if (value)
    				sscanf(value, "%2hhX%2hhX", vendor_id + 6, vendor_id + 7);
    			value = uci_lookup_option_string(ctx, s, "sw_version");
    			if (value)
    				strncpy(sw_version, value, 16);
    			value = uci_lookup_option_string(ctx, s, "serial_nr");
    			if (value)
    				strncpy(serial_nr, value, 32);
    		}
    	}
    
    	uci_free_context(ctx);
    	return 0;
    }
    
    int dsl_oem_init()
    {
    	if (xdsl_ops.set_oem_parameter) {
    		char vendor_id[8] = { 0 };  // 2 byte hex country code + 4 byte string id + 2 byte hex suffix
    		char sw_version[16] =  { 0 };
    		char serial_nr[32] = { 0 };
    		char zero[32] = { 0 };
    
    		if (uci_get_oem_params(vendor_id, sw_version, serial_nr) != 0) {
    			DSLMNGR_LOG(LOG_ERR, "Unable to read OEM parameters from config, skipping OEM init\n");
    			return -1;
    		}
    		// Note: These are BRCM specific parameters from bcmadsl.h
    		if (memcmp(vendor_id, zero, 8) != 0) {
    			(*xdsl_ops.set_oem_parameter)(4, (void *)vendor_id, 8);
    		}
    		if (memcmp(sw_version, zero, 16) != 0) {
    			(*xdsl_ops.set_oem_parameter)(5, (void *)sw_version, 16);
    		}
    		if (memcmp(serial_nr, zero, 32) != 0) {
    			(*xdsl_ops.set_oem_parameter)(6, (void *)serial_nr, 32);
    		}
    	}
    	return 0;
    }