int is_resource_content_ok(VPD_RESOURCE *pvr, unsigned char *chksum) { switch (VPD_RESOURCE_NAME(pvr)) { case ID_STR: *chksum = compute_chksum((unsigned char *)pvr, VPD_RESOURCE_SIZE(pvr) + VPD_RESOURCE_HDR_SIZE(pvr), *chksum); /*Nothing to check*/ return (TRUE); case VPD_R: *chksum = compute_chksum((unsigned char *)pvr, VPD_RESOURCE_HDR_SIZE(pvr), *chksum); return (is_vpd_r_content_ok(VPD_RESOURCE_DATA(pvr), VPD_RESOURCE_SIZE(pvr), chksum)); case VPD_W: return (is_vpd_w_content_ok(VPD_RESOURCE_DATA(pvr), VPD_RESOURCE_SIZE(pvr))); case END_TAG: if (VPD_RESOURCE_SIZE(pvr)!=0) { w_print("\nEND TAG resource size is not 0!\n"); return (FALSE); } return (TRUE); default: w_print("\nUnexpected resource name 0x%x!\n", VPD_RESOURCE_NAME(pvr)); } return (FALSE); }
int is_vpd_w_content_ok(unsigned char *res_data, int len) { VPD_HEADER *vph = (VPD_HEADER *)res_data; int last_kw = 0; unsigned char unused_chksum; while ((unsigned char *)vph - res_data < len) { if (last_kw==TRUE) { w_print("\nOne of the VPD_W resource size or the 'RW' " "keyword length is incorrect!\n"); return (FALSE); } if (!is_vpd_kw_ok(&vph,0,&unused_chksum,&last_kw)) { return (FALSE); } } if ((unsigned char *)vph - res_data != len) { w_print("\n'RW' keyword not found!\n"); w_print("\nSum of VPD keywords lengths %d is different from VPD_W " "resource length %d!\n", (unsigned char *)vph - res_data, len); return (FALSE); } return (TRUE); }
int parse_limit_arg (const char *str, int *what, long *value) { unsigned i; w_assert (str != NULL); w_assert (what != NULL); w_assert (value != NULL); if (!strcmp (str, "help")) { for (i = 0; i < w_lengthof (rlimit_specs); i++) { w_print ("$s -- $s\n", rlimit_specs[i].name, rlimit_specs[i].desc); } return -1; } for (i = 0; i < w_lengthof (rlimit_specs); i++) { unsigned nlen = strlen (rlimit_specs[i].name); if (!strncmp (str, rlimit_specs[i].name, nlen) && str[nlen] == '=') { *what = rlimit_specs[i].what; return ((*rlimit_specs[i].parse) (str + nlen + 1, value)); } } return 1; }
unsigned char *load_file(char *fn, unsigned long *size) { unsigned char *vpdr = 0; FILE *f; *size = 0; f = fopen(fn, "rb"); if (f) { fseek(f, 0, SEEK_END); *size = ftell(f); fseek(f, 0, SEEK_SET); vpdr = (unsigned char *)malloc(*size); if (vpdr) { fread(vpdr, *size, 1, f); } fclose(f); } else { w_print("Can not open file \"%s\": ", fn); perror(""); } return (vpdr); }
int main (int argc, char **argv){ Window wd; int col=5, row=1, width=68, height=1; union REGS regs; struct SREGS sregs; BYTE Unit; int rc; int handle; width= strlen( copyrite); col = (80-width)/2; wd = w_open(col, row, width, height); w_print(wd,copyrite); if (argc > 1){ if ((((argv[1][0] == '-') ||(argv[1][0] == '/'))&& (argv[1][1] == '?')) || (argv[1][0] == '?')){ printf ("CACHCECD [DriverName] \n"); goto done; } else cdDriver = argv[1]; } iso = (struct ISO_CD *) pdta; hsf = (struct HSF_CD *) pdta; do { if (GetValidDriver() == -1){ printf("No valid CD Driver. Aborted.\n"); goto done; } rc = GetCDLabel(); } while (rc < 0); Unit = rc; if (GetCacheName() == -1){ printf("User selected Quit.\n"); goto done; } CanonCacheName(CacheName); handle = open(CacheName, O_BINARY); if (handle != -1){ printf("%s already exists.\n",CacheName); printf("Delete file and re-run or re-run with different cache name.\n"); close(handle); } else CacheCD(Unit); done: w_close(wd); }
int is_resource_ok(VPD_RESOURCE **ppvr, unsigned char *chksum) { VPD_RESOURCE *pvr=(VPD_RESOURCE *)*ppvr; if (!is_resource_name_ok(VPD_RESOURCE_NAME(pvr))) { w_print("\nWrong resource name 0x%x found!\n",VPD_RESOURCE_NAME(pvr)); return (FALSE); } if (!is_resource_content_ok(pvr,chksum)) { w_print("\nWrong resource content detected!\n"); return (FALSE); } if (VPD_RESOURCE_NAME(*ppvr) == END_TAG) { *ppvr = 0; } else { *ppvr = (VPD_RESOURCE *)((unsigned char *)pvr + VPD_RESOURCE_SIZE(pvr) + VPD_RESOURCE_HDR_SIZE(pvr)); } return (TRUE); }
int PauseContinue(void){ int xkey; Window wd; int col=15, row=10, width=48, height=1; wd = w_open(col, row, width, height); w_umessage(wd,"Control Break "); w_print(wd," Press ESC to Quit, any other key to continue."); xkey=k_getkey(); w_close(wd); if (xkey==_ESC) return(-1); else return (0); }
static int state_get_fn(struct cmd *cmd, struct wimaxll_handle *wmx, int argc, char **argv) { int result; result = argp_parse(&cmd->argp, argc, argv, ARGP_IN_ORDER | ARGP_PARSE_ARGV0, 0, NULL); if (result < 0) goto error_argp_parse; w_cmd_need_if(wmx); result = wimaxll_state_get(wmx); if (result >= 0) w_print("%s\n", wimaxll_state_to_name(result)); error_argp_parse: return result; }
int check_vpd_buffer(unsigned char *file_buf, unsigned long len) { VPD_RESOURCE *vpdr = 0; vpdr = find_vpd_data(file_buf, len); if (!vpdr) { w_print("\nUnable to find valid VPD!\n"); return (1); } if (!vpd_data_valid(vpdr)) { return (2); } return (0); }
/* * reads a single byte or 4 bytes from the I2C device * * returns the word read */ SK_U32 SkI2cRead( SK_AC *pAC, /* Adapter Context */ SK_IOC IoC, /* I/O Context */ int I2cDev, /* I2C Device Address */ int I2cReg, /* I2C Device Register Address */ int I2cBurst) /* I2C Burst Flag ( 0 || I2C_BURST ) */ { SK_U32 Data; SK_OUT32(IoC, B2_I2C_DATA, 0); SK_I2C_CTL(IoC, I2C_READ, I2cDev, I2cReg, I2cBurst); if (SkI2cWait(pAC, IoC, I2C_READ)) { w_print("I2C Transfer Timeout!\n"); } SK_IN32(IoC, B2_I2C_DATA, &Data); return(Data); } /* SkI2cRead */
/* * reads a single byte or 4 bytes from the I2C device * * returns the word read */ SK_U32 SkI2cRead( SK_AC *pAC, /* Adapter Context */ SK_IOC IoC, /* I/O Context */ int I2cDev, /* I2C Device Address */ int I2cReg, /* I2C Device Register Address */ int I2cBurst) /* I2C Burst Flag */ { SK_U32 Data; SK_OUT32(IoC, B2_I2C_DATA, 0); SK_I2C_CTL(IoC, I2C_READ, I2cDev, I2cReg, I2cBurst); if (SkI2cWait(pAC, IoC, I2C_READ) != 0) { w_print("%s\n", SKERR_I2C_E002MSG); } SK_IN32(IoC, B2_I2C_DATA, &Data); return(Data); } /* SkI2cRead */
int ValidateCacheName(Field fd, int lastkey){ Window wd; int col=5, row=4, width=68, height=3; char tempCache[64]; if (lastkey == _ESC) return FD_OK; f_getstring(fd,tempCache); CanonCacheName(tempCache); if (open(tempCache, O_BINARY|O_RDONLY, S_IWRITE)!=-1){ close(tempCache); wd = w_open(col, row, width, height); w_umessage(wd,"Cache File Already Exists"); w_lmessage(wd,"Press a key to Continue"); w_print(wd,tempCache); k_getkey(); w_close(wd); return FD_ERR; } else return FD_OK; }
int is_vpd_kw_ok(VPD_HEADER **pvph, int ro, unsigned char *chksum, int *last_kw) { unsigned char *KEYWORDS_RO[] = { (unsigned char *)"PN", (unsigned char *)"EC", (unsigned char *)"FG", (unsigned char *)"LC", (unsigned char *)"MN", (unsigned char *)"PG", (unsigned char *)"SN", (unsigned char *)"Vx", (unsigned char *)"CP", (unsigned char *)"RV", (unsigned char *)0 }; unsigned char *KEYWORDS_RW[] = { (unsigned char *)"Vx", (unsigned char *)"Yx", (unsigned char *)"YA", (unsigned char *)"RW", (unsigned char *)0 }; unsigned char **p; int i = 0, kwok = FALSE; *last_kw = FALSE; p = KEYWORDS_RO; if (!ro) { p=KEYWORDS_RW; } while (p[i]) { if (*(unsigned short *)p[i]==(*pvph)->keyword) { kwok = TRUE; break; } if (p[i][1]=='x' && p[i][0]==((unsigned char *)&((*pvph)->keyword))[0]) { if (isalnum(((unsigned char *)&((*pvph)->keyword))[1])) { kwok = TRUE; break; } } i++; } if (!kwok) { w_print("\nUknown VPD KEYWORD \"%c%c\" (0x%01x 0x%01x) found!\n", ((unsigned char *)&((*pvph)->keyword))[0], ((unsigned char *)&((*pvph)->keyword))[1], ((unsigned char *)&((*pvph)->keyword))[0], ((unsigned char *)&((*pvph)->keyword))[1]); return (FALSE); } switch ((*pvph)->keyword) { case 'C' + 256 * 'P': *chksum = compute_chksum((unsigned char *)(*pvph), (*pvph)->length + 3, *chksum); break; case 'R' + 256 * 'V': *chksum = compute_chksum((unsigned char *)(*pvph), 4, *chksum); if (*chksum!=0) { w_print("\nVPD computed checksum 0x%02x different " "from exp. checksum 0x00!\n", *chksum); return (FALSE); } *last_kw = TRUE; break; case 'R' + 256 * 'W': *last_kw = TRUE; break; default: for (i = 0; i < (*pvph)->length; i++) { if (!isalnum((*pvph)->data[i]) && !isspace((*pvph)->data[i]) && !ispunct((*pvph)->data[i])) { w_print("\nKEYWORD \"%c%c\" data is not 100%% alpha-numeric!\n", ((unsigned char *)&((*pvph)->keyword))[0], ((unsigned char *)&((*pvph)->keyword))[1]); return (FALSE); } } *chksum = compute_chksum((unsigned char *)(*pvph), (*pvph)->length + 3, *chksum); break; } (*pvph) = (VPD_HEADER *)((unsigned char *)*pvph + (*pvph)->length + 3); return (TRUE); }