/******************************************************************************* * wl_adapter_open() ******************************************************************************* * * DESCRIPTION: * * Open the device. * * PARAMETERS: * * dev - a pointer to a net_device structure representing the network * device to open. * * RETURNS: * * 0 on success * errno value otherwise * ******************************************************************************/ int wl_adapter_open(struct net_device *dev) { struct wl_private *lp = wl_priv(dev); struct pcmcia_device *link = lp->link; int result = 0; int hcf_status = HCF_SUCCESS; /*--------------------------------------------------------------------*/ DBG_FUNC("wl_adapter_open"); DBG_ENTER(DbgInfo); DBG_PRINT("%s\n", VERSION_INFO); DBG_PARAM(DbgInfo, "dev", "%s (0x%p)", dev->name, dev); if (!pcmcia_dev_present(link)) { DBG_LEAVE(DbgInfo); return -ENODEV; } link->open++; hcf_status = wl_open(dev); if (hcf_status != HCF_SUCCESS) { link->open--; result = -ENODEV; } DBG_LEAVE(DbgInfo); return result; } /* wl_adapter_open */
int check_restriction(long idx_article) { int fd; int len; char restriction_pass2[20]; SHA1Context sha; char title[MAX_TITLE_ACTUAL]; init_filtering = 0; if (restriction_filter_off == -1) { fd = wl_open("wiki.pas", WL_O_RDONLY); if (fd >= 0) { len = wl_read(fd, restriction_pass1, 20); if (len < 20) memset(restriction_pass1, 0, 20); memset(restriction_pass2, 0, 20); if (memcmp(restriction_pass1, restriction_pass2, 20)) // all 0's for no password saved { len = wl_read(fd, restriction_pass2, 20); if (len < 20) memset(restriction_pass2, 0, 20); SHA1Reset(&sha); SHA1Input(&sha, (const unsigned char *) restriction_pass1, 20); SHA1Result(&sha); if (!memcmp(sha.Message_Digest, restriction_pass2, 20)) restriction_filter_off = 1; else restriction_filter_off = 0; } wl_close(fd); } } if (restriction_filter_off == -1) { get_article_title_from_idx(saved_idx_article, title); memset(&framebuffer[0], 0, (BLACK_SPACE_START - 1)* LCD_VRAM_WIDTH_PIXELS / 8); render_string(TITLE_FONT_IDX, LCD_LEFT_MARGIN, LCD_TOP_MARGIN, title, strlen(title), 0); first_time_password(0); return -1; } else if (restriction_filter_off) return 0; // ok else { get_article_title_from_idx(saved_idx_article, title); memset(&framebuffer[0], 0, (BLACK_SPACE_START - 1)* LCD_VRAM_WIDTH_PIXELS / 8); render_string(TITLE_FONT_IDX, LCD_LEFT_MARGIN, LCD_TOP_MARGIN, title, strlen(title), 0); password_str_len = 0; check_password(); return -1; } }
int init_article_filter(void) { int fd; int len; char restriction_pass2[20]; SHA1Context sha; unsigned char *pText; if (restriction_filter_off == -1) { fd = wl_open("wiki.pas", WL_O_RDONLY); if (fd >= 0) { len = wl_read(fd, restriction_pass1, 20); if (len < 20) memset(restriction_pass1, 0, 20); memset(restriction_pass2, 0, 20); if (memcmp(restriction_pass1, restriction_pass2, 20)) // all 0's for no password saved { len = wl_read(fd, restriction_pass2, 20); if (len < 20) memset(restriction_pass2, 0, 20); SHA1Reset(&sha); SHA1Input(&sha, (const unsigned char *) restriction_pass1, 20); SHA1Result(&sha); if (!memcmp(sha.Message_Digest, restriction_pass2, 20)) restriction_filter_off = 1; else restriction_filter_off = 0; } wl_close(fd); } } if (restriction_filter_off == -1) { init_filtering = 1; memset(&framebuffer[0], 0, (BLACK_SPACE_START - 1)* LCD_VRAM_WIDTH_PIXELS / 8); pText = get_nls_text("parental_controls"); render_string(TITLE_FONT_IDX, LCD_LEFT_MARGIN, LCD_TOP_MARGIN, pText, strlen(pText), 0); first_time_password(1); return -1; } else return 0; }
void history_list_init(void) { unsigned int len; int fd_hst; memset((void *)history_list, 0, sizeof(history_list)); history_count = 0; fd_hst = wl_open("wiki.hst", WL_O_RDONLY); if (fd_hst >= 0) { while ((len = wl_read(fd_hst, (void *)&history_list[history_count], sizeof(HISTORY))) >= sizeof(HISTORY) && history_count < MAX_HISTORY) { if (history_list[history_count].idx_article) history_count++; else break; } wl_close(fd_hst); } }
void save_password(int flag) { int fd; SHA1Context sha; fd = wl_open("wiki.pas", WL_O_CREATE); if (fd >= 0) { if (password_str_len > 0) { SHA1Reset(&sha); SHA1Input(&sha, (const unsigned char *) password_string, password_str_len); SHA1Result(&sha); memcpy(restriction_pass1, sha.Message_Digest, 20); } else memset(restriction_pass1, 0, 20); wl_write(fd, restriction_pass1, 20); if (password_str_len > 0 && flag > 1) { SHA1Reset(&sha); SHA1Input(&sha, (const unsigned char *) restriction_pass1, 20); SHA1Result(&sha); wl_write(fd, sha.Message_Digest, 20); } else { char buf[20]; memset(buf, 0, 20); wl_write(fd, buf, 20); } wl_close(fd); #ifdef INCLUDED_FROM_KERNEL delay_us(200000); // for some reason, save may not work if no delay #endif } }
int history_list_save(int level) { int fd_hst; int rc = 0; if (history_changed != HISTORY_SAVE_NONE) { if (level == HISTORY_SAVE_POWER_OFF || history_changed == HISTORY_SAVE_NORMAL) { fd_hst = wl_open("wiki.hst", WL_O_CREATE); if (fd_hst >= 0) { wl_write(fd_hst, (void *)history_list, sizeof(HISTORY) * MAX_HISTORY); wl_close(fd_hst); } history_changed = HISTORY_SAVE_NONE; rc = 1; } else rc = -1; } return rc; }
void perf_test(void) { char *mem_src = NULL, *mem_dst = NULL, *file = NULL; int fd = -1, read; unsigned int file_size; mem_src = malloc_simple(MB, MEM_TAG_PERF_M1); if (!mem_src) { msg(MSG_INFO, "no mem_src: out of mem ?\n"); malloc_status_simple(); goto out; } mem_dst = malloc_simple(MB, MEM_TAG_PERF_M2); if (!mem_dst) { msg(MSG_INFO, "no mem_dst: out of mem ?\n"); malloc_status_simple(); goto out; } file = malloc_simple(MB, MEM_TAG_PERF_M3); if (!file) { msg(MSG_INFO, "no file: out of mem ?\n"); malloc_status_simple(); goto out; } prof_start(PROF_memset); memset(mem_src, 1, MB); prof_stop(PROF_memset); prof_start(PROF_memcpy); memcpy(mem_dst, mem_src, MB); prof_stop(PROF_memcpy); prof_start(PROF_memcmp); memcmp(mem_src, mem_dst, MB); prof_stop(PROF_memcmp); prof_start(PROF_sd_read); for (fd = 0; fd < 8; fd++) { read = disk_read(0, file + (fd * 512 * 256), fd * 255, 255); if (read != RES_OK) { prof_stop(PROF_sd_read); msg(MSG_INFO, "Could not read sd card: %i\n", read); goto out; } } prof_stop(PROF_sd_read); fd = wl_open("8dcec2", WL_O_RDONLY); if (fd < 0) { msg(MSG_INFO, "Could not read file '8dcec2': file not found\n"); goto out; } wl_fsize(fd, &file_size); if (file_size > MB) { msg(MSG_INFO, "Could not read file '8dcec2': file size bigger than %i bytes\n", MB); goto out; } prof_start(PROF_fread); read = wl_read(fd, file, file_size); prof_stop(PROF_fread); if (read != file_size) { msg(MSG_INFO, "Could not read file '8dcec2': read process aborted after %i bytes\n", read); goto out; } msg(MSG_INFO, "memcpy speed: 1MB/%dms, SD card: 1MB/%dms, fatfs: 1MB/%dms\n", (prof_container[PROF_memcpy].calls == 0 ? 0 : ((prof_container[PROF_memcpy].total_time / MCLK_MHz) / prof_container[PROF_memcpy].calls / 1000)), (prof_container[PROF_sd_read].calls == 0 ? 0 : ((prof_container[PROF_sd_read].total_time / MCLK_MHz) / prof_container[PROF_sd_read].calls / 1000)), (prof_container[PROF_fread].calls == 0 ? 0 : ((prof_container[PROF_fread].total_time / MCLK_MHz) / prof_container[PROF_fread].calls / (file_size / 100 / KB) / 100))); out: if (fd) wl_close(fd); if (file) free_simple(file, MEM_TAG_PERF_F3); if (mem_dst) free_simple(mem_dst, MEM_TAG_PERF_F4); if (mem_src) free_simple(mem_src, MEM_TAG_PERF_F5); return; }