int RcvMsgQ() { int infolen; int bAskQuit = 0; msgbuf send_buf; msgbuf receive_buf; if((infolen=msgrcv(m_msqid_to_d,&receive_buf,MAX_IPC_MSG_BUF,0,0))<0) { if (errno == EINTR) { return 0; } else { myprintf("TP_INIT:msgrcv err\n"); return -1; } } else { //printf("msgrcv ok\n"); int bSendResp = 1; if (IPC_CLIENT_MSG_Q_ID == receive_buf.mtype) { int* pInt; pInt=(int*)(&receive_buf.mtext[0]); myprintf("TP_INIT:IPC_CLIENT_MSG_Q_ID\n"); m_msqid_from_d = *pInt; myprintf("%d\n",m_msqid_from_d); bSendResp = 0; } else if (IPC_START_AUTO_DET == receive_buf.mtype) { myprintf("TP_INIT:IPC_START_AUTO_DET\n"); // delete timer disable_polling(); // wait timer function exit wait_polling_stop(); send_buf.mtype=IPC_START_AUTO_DET; strcpy(send_buf.mtext,"Start Done"); } else if (IPC_ADD_PVC == receive_buf.mtype) { unsigned short idx; unsigned short vlan_id; unsigned short vpi; unsigned short vci; unsigned short encap; unsigned short mode; unsigned short* pWord; pWord=(unsigned short*)(&receive_buf.mtext[0]); int add_ret; myprintf("TP_INIT:IPC_ADD_PVC\n"); idx = *pWord++; vlan_id = *pWord++; vpi = *pWord++; vci = *pWord++; encap = *pWord++; mode = *pWord; myprintf("ADDPVC:%d %d %d %d %d %d\n",idx,vlan_id,vpi,vci,encap,mode); add_ret = AddPvc(idx,vlan_id,vpi,vci,encap,mode); send_buf.mtype=IPC_ADD_PVC; if (add_ret == 0) strcpy(send_buf.mtext,"OK"); else strcpy(send_buf.mtext,"FAIL"); } else if (IPC_DEL_ALL_PVC == receive_buf.mtype) { int del_ret; myprintf("TP_INIT:IPC_DEL_ALL_PVC\n"); del_ret = DelAllPvc(); send_buf.mtype=IPC_DEL_ALL_PVC; if (del_ret == 0) strcpy(send_buf.mtext,"OK"); else strcpy(send_buf.mtext,"FAIL"); } /* Paul add 2012/8/7 */ else if (IPC_ATE_ADSL_RESTORE_DEFAULT == receive_buf.mtype) { int rst_ret; myprintf("TP_INIT:IPC_ATE_ADSL_RESTORE_DEFAULT\n"); rst_ret = RestoreDefault(); send_buf.mtype=IPC_ATE_ADSL_RESTORE_DEFAULT; if (rst_ret == 0) strcpy(send_buf.mtext,"OK"); else strcpy(send_buf.mtext,"FAIL"); } //Ren.B else if (IPC_ATE_ADSL_GET_BITS_PER_CARRIER == receive_buf.mtype) { int rst_ret; myprintf("TP_INIT:IPC_ATE_ADSL_GET_BITS_PER_CARRIER\n"); rst_ret = getBitsPerCarrier(); send_buf.mtype=IPC_ATE_ADSL_GET_BITS_PER_CARRIER; if (rst_ret == 0) strcpy(send_buf.mtext,"OK"); else strcpy(send_buf.mtext,"FAIL"); } else if (IPC_ATE_ADSL1_GET_SNR == receive_buf.mtype) { int rst_ret; myprintf("TP_INIT:IPC_ATE_ADSL1_GET_SNR\n"); rst_ret = getSNR_ADSL1(); send_buf.mtype=IPC_ATE_ADSL1_GET_SNR; if (rst_ret == 0) strcpy(send_buf.mtext,"OK"); else strcpy(send_buf.mtext,"FAIL"); } else if (IPC_ATE_ADSL2_PLUS_GET_SNR == receive_buf.mtype) { int rst_ret; myprintf("TP_INIT:IPC_ATE_ADSL2_PLUS_GET_SNR\n"); rst_ret = getSNR_ADSL2_PLUS(); send_buf.mtype=IPC_ATE_ADSL2_PLUS_GET_SNR; if (rst_ret == 0) strcpy(send_buf.mtext,"OK"); else strcpy(send_buf.mtext,"FAIL"); } //Ren.E else if (IPC_LINK_STATE == receive_buf.mtype) { char LinkSts[30]; myprintf("TP_INIT:IPC_LINK_STATE\n"); GetLinkSts(LinkSts, sizeof(LinkSts)); send_buf.mtype=IPC_LINK_STATE; if (!strcmp(LinkSts,"wait for initializing")) { // nvram could not allow space character strcpymax(send_buf.mtext,"wait_for_init",MAX_IPC_MSG_BUF); } else { strcpymax(send_buf.mtext,LinkSts,MAX_IPC_MSG_BUF); } } else if (IPC_STOP_AUTO_DET == receive_buf.mtype) { myprintf("TP_INIT:IPC_STOP_AUTO_DET\n"); send_buf.mtype=IPC_STOP_AUTO_DET; strcpy(send_buf.mtext,"Stop Done"); enable_polling(); } else if (IPC_ATE_ADSL_SHOW == receive_buf.mtype) { myprintf("TP_INIT:IPC_ATE_ADSL_SHOW\n"); UpdateAllAdslSts(0,1); send_buf.mtype=IPC_ATE_ADSL_SHOW; strcpy(send_buf.mtext,"AteSetDone"); } else if (IPC_ATE_ADSL_QUIT_DRV == receive_buf.mtype) { myprintf("TP_INIT:IPC_ATE_ADSL_QUIT_DRV\n"); bAskQuit = 1; send_buf.mtype=IPC_ATE_ADSL_QUIT_DRV; strcpy(send_buf.mtext,"AteSetDone"); } else if (IPC_ATE_ADSL_DISP_PVC == receive_buf.mtype) { myprintf("TP_INIT:IPC_ATE_ADSL_DISP_PVC\n"); DispAllPvc(); send_buf.mtype=IPC_ATE_ADSL_DISP_PVC; strcpy(send_buf.mtext,"AteSetDone"); } else if (IPC_ATE_SET_ADSL_MODE == receive_buf.mtype) { unsigned short mode; unsigned short type; unsigned short* pWord; pWord=(unsigned short*)(&receive_buf.mtext[0]); int set_ret_mode, set_ret_type; myprintf("TP_INIT:IPC_ATE_SET_ADSL_MODE\n"); mode = *pWord++; type = *pWord++; myprintf("SET MODE:%d %d\n",mode,type); set_ret_mode = SetAdslMode(mode,1); set_ret_type = SetAdslType(type,1); send_buf.mtype=IPC_ATE_SET_ADSL_MODE; if (set_ret_mode == 0 && set_ret_type) strcpy(send_buf.mtext,"OK"); else strcpy(send_buf.mtext,"FAIL"); } else if (IPC_RELOAD_PVC == receive_buf.mtype) { int del_ret; myprintf("TP_INIT:IPC_RELOAD_PVC\n"); del_ret = DelAllPvc(); reload_pvc(); send_buf.mtype=IPC_RELOAD_PVC; strcpy(send_buf.mtext,"OK"); } if (bSendResp) { if(msgsnd(m_msqid_from_d,&send_buf,MAX_IPC_MSG_BUF,0)<0) { myprintf("msgsnd fail\n"); return -1; } } } if (bAskQuit == 1) return 1; return 0; }
int init_processor_name(void) { /* variable names taken from fam10 revision guide for clarity */ u32 BrandId; /* CPUID Fn8000_0001_EBX */ u8 String1; /* BrandID[14:11] */ u8 String2; /* BrandID[3:0] */ u8 Model; /* BrandID[10:4] */ u8 Pg; /* BrandID[15] */ u8 PkgTyp; /* BrandID[31:28] */ u8 NC; /* CPUID Fn8000_0008_ECX */ const char *processor_name_string = unknown; char program_string[48]; u32 *p_program_string = (u32 *)program_string; msr_t msr; int i, j = 0, str2_checkNC = 1; const struct str_s *str, *str2; /* Find out which CPU brand it is */ BrandId = cpuid_ebx(0x80000001); String1 = (u8)((BrandId >> 11) & 0x0F); String2 = (u8)((BrandId >> 0) & 0x0F); Model = (u8)((BrandId >> 4) & 0x7F); Pg = (u8)((BrandId >> 15) & 0x01); PkgTyp = (u8)((BrandId >> 28) & 0x0F); NC = (u8)(cpuid_ecx(0x80000008) & 0xFF); /* null the string */ memset(program_string, 0, sizeof(program_string)); if (!Model) { processor_name_string = Pg ? thermal : sample; goto done; } switch (PkgTyp) { case 0: /* F1207 */ str = String1_socket_F; str2 = String2_socket_F; str2_checkNC = 0; break; case 1: /* AM2 */ str = String1_socket_AM2; str2 = String2_socket_AM2; break; case 5: /* C32 */ str = String1_socket_C32; str2 = String2_socket_C32; break; default: goto done; } /* String1 */ for (i = 0; str[i].value; i++) { if ((str[i].Pg == Pg) && (str[i].NC == NC) && (str[i].String == String1)) { processor_name_string = str[i].value; break; } } if (!str[i].value) goto done; j = strcpymax(program_string, processor_name_string, sizeof(program_string)); /* Translate Model from 01-99 to ASCII and put it on the end. * Numbers less than 10 should include a leading zero, e.g., 09.*/ if (Model < 100 && j < sizeof(program_string) - 2) { program_string[j++] = (Model / 10) + '0'; program_string[j++] = (Model % 10) + '0'; } processor_name_string = unknown2; /* String 2 */ for(i = 0; str2[i].value; i++) { if ((str2[i].Pg == Pg) && ((str2[i].NC == NC) || !str2_checkNC) && (str2[i].String == String2)) { processor_name_string = str2[i].value; break; } } done: strcpymax(&program_string[j], processor_name_string, sizeof(program_string) - j); printk(BIOS_DEBUG, "CPU model: %s\n", program_string); for (i = 0; i < 6; i++) { msr.lo = p_program_string[(2 * i) + 0]; msr.hi = p_program_string[(2 * i) + 1]; wrmsr_amd(0xC0010030 + i, msr); } return 0; }
/* AUDIT biege: this code is really tricky and may lead to BOFs in email[] and/or name[] */ void getname(char *line, char **namep, char **emailp) { int i; int len; char *c; int comment_fnd; char email[MAILSTRLEN]; char name[NAMESTRLEN]; len = MAILSTRLEN - 1; comment_fnd = 0; /* ** Zero out data storage. */ memset(email, 0, MAILSTRLEN); memset(name, 0, NAMESTRLEN); *namep = NULL; *emailp = NULL; /* EMail Processing First: ** First, is there an '@' sign we can use as an anchor ? */ if ((c = hm_strchr(line, '@')) == NULL) { /* ** No '@' sign here so ... */ if (strchr(line, '(')) { /* From: bob (The Big Guy) */ c = strchr(line, ':') + 1; while (*c == ' ' || *c == '\t') c++; for (i = 0; *c && *c != '(' && *c != ' ' && *c != '\t' && *c != '\n' && i < len; c++) email[i++] = *c; email[i] = '\0'; } else if ((c = strchr(line, '<'))) { /* From: <kent> */ c++; for (i = 0; *c && *c != '>' && *c != ' ' && *c != '\t' && *c != '\n' && i < len; c++) email[i++] = *c; email[i] = '\0'; } else { /* ** - check to see if the From: line is blank, (taken care of) ** - check if From: uu.net!kent formatted line ** - check if "From: kent" formatted line */ c = strchr(line, ':') + 1; while (*c == ' ' || *c == '\t') c++; for (i = 0; *c && *c != ' ' && *c != '\t' && *c != '\n' && *c != ',' && i < len; c++) email[i++] = *c; email[i] = '\0'; } if (email[0] == '\0') /* Was it a junk From line ? */ strcpymax(email, NOEMAIL, MAILSTRLEN); else if (use_domainaddr) { /* * check if site domainizes addresses * but don't modify uucp addresses */ if ((c = strchr(email, '!')) == NULL) { if (strlen(email) < len) { strcat(email, "@"); strncat(email, set_domainaddr, len-strlen(email)); } } } } else { while (*c != ' ' && *c != '\t' && *c != '<' && *c != '"' && *c != ':') c--; c++; for (i = 0; *c && *c != '>' && *c != ' ' && *c != '\t' && *c != '"' && *c != '\n' && *c != ']' && *c != ',' && i < len; c++) email[i++] = *c; email[i] = '\0'; } /* * NAME Processing - Boy are there a bunch of funky formats here. * No promises... I'll do my best. Let me know * what I missed... */ if (strchr(line, '<')) { c = strchr(line, ':') + 1; while (*c == ' ' || *c == '\t') c++; /* if a comment then just look for the end point */ if (*c == '\"') { int rmparen = 0; ++c; if (*c == '(') { ++c; rmparen = 1; } for (i = 0, len = NAMESTRLEN - 1; *c && *c != '\"' && *c != '\n' && i < len; c++) name[i++] = *c; if (rmparen && name[(i - 1)] == ')') --i; /* get rid of "(name-comment)" parens */ comment_fnd = 1; } else if (hm_strchr(line, '(')) { c = hm_strchr(line, '(') + 1; if (*c == '"') /* is there a comment in the comment ? */ c++; } else if (*c == '<') { /* Comment may be on the end */ /* From: <*****@*****.**> Bill Campbell */ c = strchr(line, '>') + 1; for (i = 0, len = NAMESTRLEN - 1; *c && *c != '\n' && i < len; c++) name[i++] = *c; comment_fnd = 1; } } else if (strchr(line, '(')) { c = strchr(line, '('); c++; if (*c == '"') /* is there a comment in the comment ? */ c++; while (*c == ' ' || *c == '\t') c++; } else if (strchr(line, '[')) { c = strchr(line, ':') + 1; while (*c == ' ' || *c == '\t') c++; for (i = 0, len = NAMESTRLEN - 1; *c && *c != '\"' && *c != '[' && *c != '\n' && i < len; c++) name[i++] = *c; name[--i] = '\0'; comment_fnd = 1; } else { /* * Is there an email address available * that we can use for the name ? */ if (!strcmp(email, NOEMAIL)) /* No */ strcpymax(name, NONAME, NAMESTRLEN); else { c = email + strlen(email) - 1; while (isspace(*c)) *c-- = '\0'; strcpymax(name, email, NAMESTRLEN); /* Yes */ } *namep = strsav(name); *emailp = strsav(email); return; } if (!comment_fnd) { int in_ascii = TRUE, esclen = 0; for (i = 0, len = NAMESTRLEN - 1; *c && *c != '<' && *c != '\"' && *c != ')' && *c != '(' && *c != '\n' && i < len; c++) { if (set_iso2022jp) { iso2022_state(c, &in_ascii, &esclen); if (esclen) { for (; esclen; esclen--, c++) name[i++] = *c; for (; in_ascii == FALSE && i < len; c++, iso2022_state(c, &in_ascii, &esclen)) { name[i++] = *c; } c--; } else { name[i++] = *c; } } else { name[i++] = *c; } } } if (i > 0 && name[i - 1] == ' ' && (*c == '<' || *c == '(')) name[--i] = '\0'; else name[i] = '\0'; /* * Is the name string blank ? If so then * force it to get filled with something. */ if (blankstring(name)) name[0] = '\0'; /* Bailing and taking the easy way out... */ if (name[0] == '\0') { if (email[0] == '\0') strcpymax(name, NONAME, NAMESTRLEN); else strcpymax(name, email, NAMESTRLEN); } /* * need to strip spaces off the end of * the email and name strings */ c = email + (strlen(email) - 1); while (c > email && isspace(*c)) *c-- = '\0'; *namep = strsav(name); *emailp = strsav(email); }