static int label_instructions (MonoCompile *cfg) { MonoBasicBlock *bb; int instruction_count = 0; for (bb = cfg->bb_entry; bb; bb = bb->next_bb) { cfg_debug ("bb: %d (in: %d, out: %d)", bb->block_num, bb->in_count, bb->out_count); MonoInst *insn; for (insn = bb->code; insn; insn = insn->next) { instruction_count++; void *id = g_hash_table_lookup (cfg->gdump_ctx->insn2id, insn); if (id != NULL) // already in the table. continue; int *new_id = (int *) mono_mempool_alloc0 (cfg->mempool, sizeof (int)); *new_id = cfg->gdump_ctx->next_insn_id++; g_hash_table_insert (cfg->gdump_ctx->insn2id, insn, new_id); #ifdef CFG_DEBUG GString *insndesc = mono_print_ins_index_strbuf (-1, insn); cfg_debug ("> insn%002d: %s", *new_id, insndesc->str); g_string_free (insndesc, TRUE); #endif } } return instruction_count; }
static int get_real_netmask (char *nmode, char *mask) { int sock; struct ifreq ifr; char *IPV6_FLAG=NULL; IPV6_FLAG = cfg_get_param_string(F_CFG_IPV6); if (strcmp (IPV6_FLAG, "0") == 0){ sock = socket (AF_INET, SOCK_DGRAM, 0); if (sock == -1) { strcpy (mask, ""); } strncpy (ifr.ifr_name, nmode, 16); ifr.ifr_name[15] = 0; if (mask != NULL) { if (ioctl (sock, SIOCGIFNETMASK, &ifr) < 0) { strcpy (mask, ""); } strcpy (mask, inet_ntoa (((struct sockaddr_in *)&ifr.ifr_netmask)->sin_addr)); cfg_debug ("iface %s's netmask is %s\n", nmode, mask); } if (sock >= 0) { close (sock); } }else{ strcpy (mask, ""); } return 0; }
static int get_real_ip (char *nmode, char *ip) { int sock; struct sockaddr_in sin; struct ifreq ifr; sock = socket (AF_INET, SOCK_DGRAM, 0); if (sock == -1) { strcpy (ip, ""); } strncpy (ifr.ifr_name, nmode, 16); ifr.ifr_name[15] = 0; if (ip != NULL) { if (ioctl (sock, SIOCGIFADDR, &ifr) < 0) { strcpy (ip, ""); } memcpy (&sin, &ifr.ifr_addr, sizeof (sin)); strncpy (ip, inet_ntoa (sin.sin_addr), 16); cfg_debug ("iface %s's ipaddress is %s\n", nmode, ip); } if (sock >= 0) { close (sock); } return 0; }
static int change_to_usb_config(char *stb_inipath) { int j = 0; dictionary *ini = NULL; cfg_debug("%s\n", stb_inipath); ini = iniparser_load(stb_inipath); for (j = 0; j < g_usb_config_line_count; j++) { if (strstr(stb_inipath, g_usb_config_name[j])) { cfg_debug("set %s to %s in %s\n", g_usb_config_cmd[j], g_usb_config_value[j], stb_inipath); iniparser_set(ini, g_usb_config_cmd[j], g_usb_config_value[j]); } } ini_dump(ini, stb_inipath); return FV_OK; }
int cfg_service_read_usb_ini(char *usb_ini_file_path) { FILE *f = NULL; int i = 0; cfg_debug("usb_ini_file_path=%s\n", usb_ini_file_path); f = fopen(usb_ini_file_path, "r"); if (NULL == f) { cfg_error("open usb ini failed!\n"); return -1; } while (fscanf(f, "%s %s %s", g_usb_config_name[i], g_usb_config_cmd[i], g_usb_config_value[i]) != EOF) { if (i >= MAX_INI_LINE_COUNT) { cfg_error("too many line of config.txt!\n"); break; } cfg_debug("%s %s %s\n", g_usb_config_name[i], g_usb_config_cmd[i], g_usb_config_value[i]); i++; g_usb_config_line_count = i; } fclose(f); check_ini_in_usb_config(); if (g_usb_config_config_inifile_found == FV_TRUE) { change_to_usb_config(N_STB_PARAM_PATH "/" CONFIG_INIFILE); } if (g_usb_config_product_inifile_found == FV_TRUE) { change_to_usb_config(N_STB_PARAM_PATH "/" PRODUCT_INIFILE); } if (g_usb_config_iptv_inifile_found == FV_TRUE) { change_to_usb_config(N_STB_PARAM_PATH "/" IPTV_INIFILE); } if (g_usb_config_stb_inifile_found == FV_TRUE) { change_to_usb_config(N_STB_PARAM_PATH "/" STB_INIFILE); } return FV_OK; }
void cfg_recv_int(int sig) { cfg_debug("---- receive exit signal %d\n", sig); switch (sig) { case SIGINT: cfg_dispatch_stop(); break; default: break; } }
static int check_ini_in_usb_config() { int i = 0; for (i = 0; i < g_usb_config_line_count; i++) { if (strncmp(g_usb_config_name[i], CONFIG_INIFILE, sizeof(CONFIG_INIFILE)) == 0) { cfg_debug("set CONFIG_INIFILE\n"); g_usb_config_config_inifile_found = FV_TRUE; } else if (strncmp(g_usb_config_name[i], PRODUCT_INIFILE, sizeof(PRODUCT_INIFILE)) == 0) { cfg_debug("set PRODUCT_INIFILE\n"); g_usb_config_product_inifile_found = FV_TRUE; } else if (strncmp(g_usb_config_name[i], IPTV_INIFILE, sizeof(IPTV_INIFILE)) == 0) { cfg_debug("set IPTV_INIFILE\n"); g_usb_config_iptv_inifile_found = FV_TRUE; } else if (strncmp(g_usb_config_name[i], STB_INIFILE, sizeof(STB_INIFILE)) == 0) { cfg_debug("set STB_INIFILE\n"); g_usb_config_stb_inifile_found = FV_TRUE; } } return FV_TRUE; }
int cfg_service_get_net_config(int config_cmd, int config_size, char *config_value) { int found = 0; char *value = NULL; char *find = NULL; switch (config_cmd) { case F_CFG_IPAddressReal: { cfg_get_real_ip(config_value, &found); break; } case F_CFG_SubnetMaskReal: { cfg_get_real_subnetmask(config_value, &found); break; } case F_CFG_DefaultGatewayReal: { cfg_get_real_gateway(config_value, &found); break; } case F_CFG_DNSServer0Real: { cfg_get_real_dns(config_value, &found, 0); break; } case F_CFG_DNSServer1Real: { cfg_get_real_dns(config_value, &found, 1); break; } case F_CFG_UpgradeDomain: { value = cfg_get_param_string(F_CFG_UpgradeDomain); find = strchr(value, ':'); if ((NULL == value) || (NULL == find) || (0 == strcmp(value, "")) || (strlen(find) <= 3)) { value = cfg_get_param_string(F_CFG_LocalUpgradeUrl); cfg_set_param_string(F_CFG_UpgradeDomain, value); } /* not safe */ strcpy(config_value, value); break; } default: { cfg_debug("no such net config value.\n"); break; } } return FV_OK; }
int cfg_get_real_subnetmask(char *value, int *found) { FILE *fp; char *addresstype_s = NULL; char addresstype[F_ADDRESSING_TYPE_SIZE] = {0}; char *wireless_s = NULL; char *def = ""; int ret; char temps[32] = {0}; strcpy (value, def); *found = 1; /* fixme: use one address type source */ fp = fopen ("/var/net_mode", "r"); if (fp != NULL) { fscanf (fp, "%s", addresstype); fclose (fp); } else { addresstype_s = cfg_get_param_string(F_CFG_AddressingType); if (NULL == addresstype_s) { cfg_error("cfg_get_param_string(F_CFG_AddressingType) failed.\n"); return -1; } } wireless_s = cfg_get_param_string(F_CFG_Wireless); if (NULL == wireless_s) { cfg_error("cfg_get_param_string(F_CFG_Wireless) failed.\n"); return -1; } if (fp != NULL) { ret = strcmp(addresstype, "PPPOE"); } else { ret = strcmp(addresstype_s, "PPPOE"); } if (ret != 0) { if (strcmp (wireless_s, "1") == 0) { if (FV_OK != FV_OK) {//fixmeo_get_wireless_dev_name(temps, sizeof(temps))) { cfg_debug("cfg get wireless device interface is null\n"); return -1; } get_real_netmask (temps, value); } else { get_real_netmask ("eth0", value); } } else get_real_netmask ("ppp0", value); return FV_OK; }
void mono_cfg_dump_ir (MonoCompile *cfg, const char *phase_name) { if (cfg->gdump_ctx == NULL) return; cfg_debug ("=== DUMPING PASS \"%s\" ===", phase_name); write_byte (cfg, BEGIN_GRAPH); write_pool (cfg, create_cp_entry (cfg, (void *) phase_name, PT_STRING)); int instruction_count = label_instructions (cfg); write_instructions (cfg, instruction_count); write_blocks (cfg); }
static int fileversion_write(char *verfilename, const char *verbuf) { FILE *fd; fd = fopen(verfilename, "w"); if (NULL == fd) { cfg_error("open %s error!\n", verfilename); return -1; } fputs(verbuf, fd); cfg_debug("%s put ver is %s\n", verfilename, verbuf); fclose(fd); return FV_OK; }
static int fileversion_read(char *verfilename, char *verbuf, unsigned int bufsize) { FILE *fd; char linebuf[64]; int len; int ret; memset(linebuf, 0, 64); ret = __system_property_get("ro.fonsview.stb.RomVersion",linebuf); if ((strlen(linebuf) >= bufsize)||(ret == 0)) { cfg_error("version length from file is large than bufsize!\n"); fclose(fd); return -1; } strcpy(verbuf, linebuf); #if 0 fd = fopen(verfilename, "r"); if (NULL == fd) { cfg_error("open %s error!\n", verfilename); return -1; } if (fgets(linebuf, sizeof(linebuf), fd) == NULL) { cfg_error("%s gets ver error!\n", verfilename); return -1; } cfg_debug("%s get ver is %s\n", verfilename, linebuf); len = strlen(linebuf); if (linebuf[len - 1] == 0x0a) { linebuf[len - 1] = '\0'; } if (strlen(linebuf) >= bufsize) { cfg_error("version length from file is large than bufsize!\n"); fclose(fd); return -1; } strcpy(verbuf, linebuf); fclose(fd); #endif return FV_OK; }
static void write_instructions (MonoCompile *cfg, int instruction_count) { MonoBasicBlock *bb; write_int (cfg, instruction_count); for (bb = cfg->bb_entry; bb; bb = bb->next_bb) { MonoInst *insn; cfg_debug ("== bb: %d (in: %d, out: %d) ==", bb->block_num, bb->in_count, bb->out_count); for (insn = bb->code; insn; insn = insn->next) { int i; int *id = (int *) g_hash_table_lookup (cfg->gdump_ctx->insn2id, insn); g_assert (id); write_int (cfg, *id); // hardcoded node class: only one input and NUM_SUCCESSOR successors write_pool (cfg, create_cp_entry (cfg, (void *) insn, PT_OPTYPE)); write_byte (cfg, cfg->bb_entry->code != insn); // properties write_short (cfg, 2); // property #1 GString *insndesc = mono_print_ins_index_strbuf (-1, insn); cfg_debug ("dumping node [%2d]: %s", *id, insndesc->str); write_pool (cfg, create_cp_entry (cfg, (void *) "fullname", PT_STRING)); write_byte (cfg, PROPERTY_POOL); write_pool (cfg, create_cp_entry (cfg, (void *) insndesc->str, PT_STRING)); g_string_free (insndesc, TRUE); // property #2 write_pool (cfg, create_cp_entry (cfg, (void *) "category", PT_STRING)); write_byte (cfg, PROPERTY_POOL); if (bb->in_count > 1 && bb->code == insn) write_pool (cfg, create_cp_entry (cfg, (void *) "merge", PT_STRING)); else if (bb->code == insn) write_pool (cfg, create_cp_entry (cfg, (void *) "begin", PT_STRING)); else if (MONO_IS_COND_BRANCH_OP (insn)) write_pool (cfg, create_cp_entry (cfg, (void *) "controlSplit", PT_STRING)); else if (MONO_IS_PHI (insn)) write_pool (cfg, create_cp_entry (cfg, (void *) "phi", PT_STRING)); else if (!MONO_INS_HAS_NO_SIDE_EFFECT (insn)) write_pool (cfg, create_cp_entry (cfg, (void *) "state", PT_STRING)); else write_pool (cfg, create_cp_entry (cfg, (void *) "fixed", PT_STRING)); // end of properties write_int (cfg, -1); // never set predecessor. int *next_id; if (insn->next != NULL) { next_id = (int *) g_hash_table_lookup (cfg->gdump_ctx->insn2id, insn->next); g_assert (next_id); cfg_debug ("\tsuccessor' : [%2d]", *next_id); write_int (cfg, *next_id); for (i = 1; i < NUM_SUCCESSOR; i++) write_int (cfg, -1); } else { g_assert (bb->out_count < NUM_SUCCESSOR); for (i = 0; (i < bb->out_count) && (i < NUM_SUCCESSOR); i++) { if (bb->out_bb[i]->code == NULL) write_int (cfg, -1); else { next_id = (int *) g_hash_table_lookup (cfg->gdump_ctx->insn2id, bb->out_bb[i]->code); if (next_id) cfg_debug ("\tsuccessor'': [%2d]", *next_id); write_int (cfg, next_id ? *next_id : -1); } } for (; i < NUM_SUCCESSOR; i++) write_int (cfg, -1); } } } }
int cfg_service_set_config(int config_cmd, char *config_value) { char encodeStr[F_MAX_PASSWORD_SIZE] = {0}; int value = -1; int hdmi_mode = 0; int component_mode = 0; if((config_cmd < 0) || (config_cmd >= F_CFG_NUM)) { cfg_error("cmd num %d beyond\n", config_cmd); return -1; } if(strlen(config_value) >= (unsigned int)cfg_get_ini_bufsize(config_cmd)) { cfg_error("set value len is too long\n"); return -1; } switch (config_cmd) { case F_CFG_HdmiMode: if (NULL == config_value) { sprintf(config_value, O_DISP_720P50_STR); } cfg_debug("config hdmi mode is %s\n", config_value); cfg_set_param_string(config_cmd, config_value); if (!strcmp(config_value, O_DISP_720P50_STR)) { hdmi_mode= N_BOARD_HDMI_INDEX_720p50; component_mode = N_BOARD_COMPONENT_INDEX_720p50; } else if (!strcmp(config_value, O_DISP_720P60_STR)) { hdmi_mode = N_BOARD_HDMI_INDEX_720p59; component_mode = N_BOARD_COMPONENT_INDEX_720p59; } else if (!strcmp(config_value, O_DISP_1080P50_STR)) { hdmi_mode = N_BOARD_HDMI_INDEX_1080p50; component_mode = N_BOARD_COMPONENT_INDEX_1080p50; } else if (!strcmp(config_value, O_DISP_1080P60_STR)) { hdmi_mode = N_BOARD_HDMI_INDEX_1080p59; component_mode = N_BOARD_COMPONENT_INDEX_1080p59; } else { hdmi_mode = N_BOARD_HDMI_INDEX_720p59; component_mode = N_BOARD_COMPONENT_INDEX_720p59; } cfg_debug("hdmi_mode=%d,component_mode=%d\n", hdmi_mode, component_mode); n_bcfg_set_int(N_BCFG_HDMI_MODE, hdmi_mode); n_bcfg_set_int(N_BCFG_COMPONENT_MODE, component_mode); break; case F_CFG_HardwareVersion: n_bcfg_set_string(N_BCFG_HW_VERSION, config_value); break; case F_CFG_VideoMode: if(!strcmp(config_value, "NTSC")) { value = N_BCFG_NORM_NTSC; } else { value = N_BCFG_NORM_PAL; } n_bcfg_set_int(N_BCFG_NORM, value); cfg_set_param_string(config_cmd, config_value); if (N_BCFG_NORM_PAL == value) { cfg_set_param_string(F_CFG_FramebufferHeight, "576"); } else if (N_BCFG_NORM_NTSC == value) { cfg_set_param_string(F_CFG_FramebufferHeight, "480"); } gUbootCfgParamChanged = FV_TRUE; break; case F_CFG_PPPoEPassword: case F_CFG_DhcpPassword: case F_CFG_UserPassword: f_encode_chars(config_value, encodeStr, strlen(config_value)); cfg_set_param_string(config_cmd, encodeStr); break; case F_CFG_MP_Volume: cfg_set_dynamic_param_string(config_cmd, config_value); break; default: if (strcmp(cfg_get_param_string(config_cmd), config_value) != 0) { cfg_set_param_flag(config_cmd, 1); } cfg_set_param_string(config_cmd, config_value); break; } return FV_OK; }
int cfg_service_get_config(int config_cmd, int config_size, char *config_value) { int result = -1; char *tmp = NULL; char decodeStr[F_MAX_PASSWORD_SIZE] = {0}; if((config_cmd < 0) || (config_cmd >= F_CFG_NUM)) { cfg_error("cmd num %d beyond\n", config_cmd); strcpy(config_value, ""); return -1; } if(config_size <= cfg_get_param_string_len(config_cmd)) { cfg_error("config_size is %d, g_cfg_params_info[%d].bufsize is %d\n", config_size, config_cmd, cfg_get_ini_bufsize(config_cmd)); strcpy(config_value, ""); return -1; } /* add for get stbid and mac address */ switch (config_cmd) { case F_CFG_FramebufferWidth: snprintf(config_value, config_size, "%d", n_stb_get_screen_width()); break; case F_CFG_FramebufferHeight: snprintf(config_value, config_size, "%d", n_stb_get_screen_height()); break; case F_CFG_VideoMode: if (n_bcfg_get_int(N_BCFG_NORM, &result) == FV_OK) { if (result == 0) { snprintf(config_value, config_size, "NTSC"); } else { snprintf(config_value, config_size, "PAL"); } } else { strcpy(config_value, cfg_get_param_string(config_cmd)); } break; case F_CFG_PPPoEPassword: case F_CFG_DhcpPassword: case F_CFG_UserPassword: tmp = cfg_get_param_string(config_cmd); f_decode_chars(tmp, decodeStr, strlen(tmp)); strcpy(config_value, decodeStr); break; case F_CFG_IPAddressReal: case F_CFG_SubnetMaskReal: case F_CFG_DefaultGatewayReal: case F_CFG_DNSServer0Real: case F_CFG_DNSServer1Real: case F_CFG_UpgradeDomain: cfg_service_get_net_config(config_cmd, config_size, config_value); break; default: strcpy(config_value, cfg_get_param_string(config_cmd)); /*if (F_CFG_ManageSerURL == config_cmd) { strncpy(config_value, "http://172.16.15.18/acs_sim/acs.php", config_size); printf("### F_CFG_ManageSerURL = %s\n", config_value); }*/ break; } cfg_debug("value=%s\n", config_value); return FV_OK; }
static int get_real_ip(char*nmode, char *ip) { struct ifaddrs *ifap0, *ifap; char buf[NI_MAXHOST]; struct sockaddr_in *addr4; struct sockaddr_in6 *addr6; int family; char *IPV6_FLAG=NULL; IPV6_FLAG = cfg_get_param_string(F_CFG_IPV6); if (strcmp(IPV6_FLAG, "0") == 0){ family=AF_INET; }else{ family=AF_INET6; } if(NULL == ip) { //strcpy (ip, ""); return -1; } if(getifaddrs(&ifap0)) { return -1; } for(ifap=ifap0;ifap!=NULL;ifap=ifap->ifa_next){ if(strcmp(nmode, ifap->ifa_name) != 0) continue; if(ifap->ifa_addr == NULL) continue; if ((ifap->ifa_flags & IFF_UP) == 0) continue; if(family != ifap->ifa_addr->sa_family) continue; if(AF_INET == ifap->ifa_addr->sa_family) { addr4 = (struct sockaddr_in *)ifap->ifa_addr; if ( NULL != inet_ntop(ifap->ifa_addr->sa_family, (void *)&(addr4->sin_addr), buf, NI_MAXHOST) ){ strcpy(ip, buf); cfg_debug ("iface %s's ipaddress is %s\n", nmode, ip); freeifaddrs(ifap0); return 0; } else break; }else if(AF_INET6 == ifap->ifa_addr->sa_family) { addr6 = (struct sockaddr_in6 *)ifap->ifa_addr; if(IN6_IS_ADDR_MULTICAST(&addr6->sin6_addr)){ continue; } if(IN6_IS_ADDR_LINKLOCAL(&addr6->sin6_addr)){ continue; } if(IN6_IS_ADDR_LOOPBACK(&addr6->sin6_addr)){ continue; } if(IN6_IS_ADDR_UNSPECIFIED(&addr6->sin6_addr)){ continue; } if(IN6_IS_ADDR_SITELOCAL(&addr6->sin6_addr)){ continue; } if(NULL != inet_ntop(ifap->ifa_addr->sa_family, (void *)&(addr6->sin6_addr), buf, NI_MAXHOST)){ strcpy(ip, buf); cfg_debug ("iface %s's ipaddress is %s\n", nmode, ip); freeifaddrs(ifap0); return 0; } else break; } } freeifaddrs(ifap0); return -1; }