/** * Load non-volatile stored options from non-volatile storage device * * @v nvo Non-volatile options block * @ret rc Return status code */ static int nvo_load ( struct nvo_block *nvo ) { uint8_t *options_data = nvo->dhcpopts.data; int rc; /* Skip reading zero-length NVO fields */ if ( nvo->len == 0 ) { DBGC ( nvo, "NVO %p is empty; skipping load\n", nvo ); return 0; } /* Read data */ if ( ( rc = nvs_read ( nvo->nvs, nvo->address, nvo->data, nvo->len ) ) != 0 ) { DBGC ( nvo, "NVO %p could not read %zd bytes at %#04x: %s\n", nvo, nvo->len, nvo->address, strerror ( rc ) ); return rc; } /* If checksum fails, or options data starts with a zero, * assume the whole block is invalid. This should capture the * case of random initial contents. */ if ( ( nvo_checksum ( nvo ) != 0 ) || ( options_data[0] == 0 ) ) { DBGC ( nvo, "NVO %p has checksum %02x and initial byte %02x; " "assuming empty\n", nvo, nvo_checksum ( nvo ), options_data[0] ); memset ( nvo->data, 0, nvo->len ); } /* Rescan DHCP option block */ dhcpopt_update_used_len ( &nvo->dhcpopts ); DBGC ( nvo, "NVO %p loaded from non-volatile storage\n", nvo ); return 0; }
static ssize_t acer_code_read_proc(char *page, char **start, off_t off, int count, int *eof, void *data){ if(off > 0){ *eof = 1; return 0; } nvs_read(); return sprintf(page, "%s\n", nvs->acer_code) + 1; }
static ssize_t bt_mac_addr_read_proc(char *page, char **start, off_t off, int count, int *eof, void *data){ if(off > 0){ *eof = 1; return 0; } nvs_read(); return sprintf(page, "%s\n", nvs->bt_mac_addr) + 1; }
static ssize_t wifi_country_code_read_proc(char *page, char **start, off_t off, int count, int *eof, void *data){ if(off > 0){ *eof = 1; return 0; } nvs_read(); return sprintf(page, "0x%x%x\n", nvs->wifi_country_code[1], nvs->wifi_country_code[0]) + 1; }
static ssize_t rf_version_read_proc(char *page, char **start, off_t off, int count, int *eof, void *data){ char messages[RF_VER_SIZE] = {0}; int rf_ver0 = 1; //gpioExt27 int rf_ver1 = 1; //gpioExt28 static int init = 0; if(!init){ mt_set_gpio_mode(GPIOEXT27, GPIO_MODE_00); mt_set_gpio_dir(GPIOEXT27, GPIO_DIR_IN); mt_set_gpio_pull_enable(GPIOEXT27, GPIO_PULL_DISABLE); //mt_set_gpio_pull_select(GPIOEXT27, GPIO_PULL_UP); mt_set_gpio_mode(GPIOEXT28, GPIO_MODE_00); mt_set_gpio_dir(GPIOEXT28, GPIO_DIR_IN); mt_set_gpio_pull_enable(GPIOEXT28, GPIO_PULL_DISABLE); //mt_set_gpio_pull_select(GPIOEXT28, GPIO_PULL_UP); msleep(100); init = 1; } rf_ver0 = mt_get_gpio_in(GPIOEXT27); rf_ver1 = mt_get_gpio_in(GPIOEXT28); if(rf_ver0 == 0 && rf_ver1 == 0){ sprintf(messages, "%s", "3G"); } else if(rf_ver0 == 1 && rf_ver1 == 0){ sprintf(messages, "%s", "LTE"); } else if(rf_ver0 == 0 && rf_ver1 == 1){ sprintf(messages, "%s", "WIFI"); } else if(rf_ver0 == 1 && rf_ver1 == 1){ sprintf(messages, "%s", "MV"); } else sprintf(messages, "%s", "N/A"); messages[RF_VER_SIZE-1] = 0x0; nvs_read(); sprintf(nvs->rf_version, "%s", messages); nvs_write(); if(off > 0){ *eof = 1; return 0; } return sprintf(page, "%s\n", messages) + 1; }
static ssize_t serial_sys_read_proc(char *page, char **start, off_t off, int count, int *eof, void *data){ if(off > 0){ *eof = 1; return 0; } nvs_read(); return sprintf(page, "%s\n", nvs->sn_sys) + 1; }
/** * Verify content of non-volatile storage device * * @v nvs NVS device * @v address Address from which to read * @v data Data to compare against * @v len Length of data buffer * @ret rc Return status code */ static int nvs_verify ( struct nvs_device *nvs, unsigned int address, const void *data, size_t len ) { uint8_t read_data[len]; int rc; /* Read data into temporary buffer */ if ( ( rc = nvs_read ( nvs, address, read_data, len ) ) != 0 ) return rc; /* Compare data */ if ( memcmp ( data, read_data, len ) != 0 ) { DBG ( "NVS %p verification failed at %#04x+%zd\n", nvs, address, len ); return -EIO; } return 0; }
/** * Load non-volatile stored options from non-volatile storage device * * @v nvo Non-volatile options block * @ret rc Return status code */ static int nvo_load ( struct nvo_block *nvo ) { void *data = nvo->data; struct nvo_fragment *frag; int rc; /* Read data a fragment at a time */ for ( frag = nvo->fragments ; frag->len ; frag++ ) { if ( ( rc = nvs_read ( nvo->nvs, frag->address, data, frag->len ) ) != 0 ) { DBGC ( nvo, "NVO %p could not read %zd bytes at " "%#04x\n", nvo, frag->len, frag->address ); return rc; } data += frag->len; } DBGC ( nvo, "NVO %p loaded from non-volatile storage\n", nvo ); return 0; }
static ssize_t imei_write_proc(struct file *filp, const char *buff, size_t len, loff_t *off) { char messages[IMEI_SIZE] = {0}; if(len >= (IMEI_SIZE - 1)) len = IMEI_SIZE -1; else len -=1; //ignore "\n" if (copy_from_user(messages, buff, len)) return -EFAULT; messages[IMEI_SIZE-1] = 0x0; sprintf(nvs->imei, "%s", messages); nvs_write(); nvs_read(); return strlen(buff); }
static ssize_t pcb_version_read_proc(char *page, char **start, off_t off, int count, int *eof, void *data){ char messages[PCB_VER_SIZE] = {0}; int pcb_ver0 = 1; //gpioExt29 // SB/SC int pcb_ver1 = 1; //gpioExt30 // SB/SC int pcb_ver2 = 0; //gpioExt40 // SC only static int init = 0; if(!init){ mt_set_gpio_mode(GPIOEXT29, GPIO_MODE_00); mt_set_gpio_dir(GPIOEXT29, GPIO_DIR_IN); mt_set_gpio_pull_enable(GPIOEXT29, GPIO_PULL_DISABLE); //mt_set_gpio_pull_select(GPIOEXT29, GPIO_PULL_UP); mt_set_gpio_mode(GPIOEXT30, GPIO_MODE_00); mt_set_gpio_dir(GPIOEXT30, GPIO_DIR_IN); mt_set_gpio_pull_enable(GPIOEXT30, GPIO_PULL_DISABLE); //mt_set_gpio_pull_select(GPIOEXT30, GPIO_PULL_UP); mt_set_gpio_mode(GPIOEXT40, GPIO_MODE_00); mt_set_gpio_dir(GPIOEXT40, GPIO_DIR_IN); mt_set_gpio_pull_enable(GPIOEXT40, GPIO_PULL_DISABLE); //mt_set_gpio_pull_select(GPIOEXT40, GPIO_PULL_UP); msleep(100); init = 1; } pcb_ver0 = mt_get_gpio_in(GPIOEXT29); pcb_ver1 = mt_get_gpio_in(GPIOEXT30); pcb_ver2 = mt_get_gpio_in(GPIOEXT40); if(pcb_ver0 == 0 && pcb_ver1 == 0 && pcb_ver2 == 0){ sprintf(messages, "%s", "SA"); } else if(pcb_ver0 == 1 && pcb_ver1 == 0 && pcb_ver2 == 0){ sprintf(messages, "%s", "-2"); } else if(pcb_ver0 == 0 && pcb_ver1 == 1 && pcb_ver2 == 0){ sprintf(messages, "%s", "-1M"); } else if(pcb_ver0 == 1 && pcb_ver1 == 1 && pcb_ver2 == 0){ sprintf(messages, "%s", "SD"); } else if(pcb_ver0 == 0 && pcb_ver1 == 0 && pcb_ver2 == 1){ sprintf(messages, "%s", "SC"); } else if(pcb_ver0 == 1 && pcb_ver1 == 0 && pcb_ver2 == 1){ sprintf(messages, "%s", "-3"); } else if(pcb_ver0 == 0 && pcb_ver1 == 1 && pcb_ver2 == 1){ sprintf(messages, "%s", "-4"); } else if(pcb_ver0 == 1 && pcb_ver1 == 1 && pcb_ver2 == 1){ sprintf(messages, "%s", "-5"); } else sprintf(messages, "%s", "N/A"); messages[PCB_VER_SIZE-1] = 0x0; nvs_read(); sprintf(nvs->pcb_version, "%s", messages); nvs_write(); if(off > 0){ *eof = 1; return 0; } return sprintf(page, "%s\n", messages) + 1; }