int get_device_type_by_device(const char *device_name) { if(device_name == NULL || strlen(device_name) <= 0){ usb_dbg("(%s): The device name is not correct.\n", device_name); return DEVICE_TYPE_UNKNOWN; } #ifdef RTCONFIG_USB if(!strncmp(device_name, "sd", 2) #ifdef SUPPORT_IDE_SATA_DISK || !strncmp(device_name, "hd", 2) #endif ){ return DEVICE_TYPE_DISK; } #endif #ifdef RTCONFIG_USB_PRINTER if(!strncmp(device_name, "lp", 2)){ return DEVICE_TYPE_PRINTER; } #endif #ifdef RTCONFIG_USB_MODEM if(!strncmp(device_name, "sg", 2)){ return DEVICE_TYPE_SG; } if(!strncmp(device_name, "sr", 2)){ return DEVICE_TYPE_CD; } if(isSerialNode(device_name) || isACMNode(device_name)){ return DEVICE_TYPE_MODEM; } #endif #ifdef RTCONFIG_USB_BECEEM if(isBeceemNode(device_name)){ return DEVICE_TYPE_BECEEM; } #endif return DEVICE_TYPE_UNKNOWN; }
/* * Called when link comes up */ int ipup_main(int argc, char **argv) { FILE *fp; char *wan_ifname = safe_getenv("IFNAME"); char *wan_linkname = safe_getenv("LINKNAME"); char tmp[100], prefix[] = "wanXXXXXXXXXX_"; char buf[256], *value; int unit; _dprintf("%s():: %s\n", __FUNCTION__, argv[0]); /* Get unit from LINKNAME: ppp[UNIT] */ if ((unit = ppp_linkunit(wan_linkname)) < 0) return 0; _dprintf("%s: unit=%d ifname=%s\n", __FUNCTION__, unit, wan_ifname); snprintf(prefix, sizeof(prefix), "wan%d_", unit); /* Stop triggering demand connection */ if (nvram_get_int(strcat_r(prefix, "pppoe_demand", tmp))) nvram_set_int(strcat_r(prefix, "pppoe_demand", tmp), 1); #ifdef RTCONFIG_USB_MODEM // wanX_ifname is used for device for USB Modem if ((value = getenv("DEVICE")) && (isSerialNode(value) || isACMNode(value))) nvram_set(strcat_r(prefix, "ifname", tmp), value); #endif /* Touch connection file */ if (!(fp = fopen(strcat_r("/tmp/ppp/link.", wan_ifname, tmp), "a"))) { perror(tmp); return errno; } fclose(fp); if ((value = getenv("IPLOCAL"))) { if (nvram_invmatch(strcat_r(prefix, "ipaddr", tmp), value)) ifconfig(wan_ifname, IFUP, "0.0.0.0", NULL); _ifconfig(wan_ifname, IFUP, value, "255.255.255.255", getenv("IPREMOTE")); nvram_set(strcat_r(prefix, "ipaddr", tmp), value); nvram_set(strcat_r(prefix, "netmask", tmp), "255.255.255.255"); } if ((value = getenv("IPREMOTE"))) nvram_set(strcat_r(prefix, "gateway", tmp), value); strcpy(buf, ""); if ((value = getenv("DNS1"))) sprintf(buf, "%s", value); if ((value = getenv("DNS2"))) sprintf(buf + strlen(buf), "%s%s", strlen(buf) ? " " : "", value); /* empty DNS means they either were not requested or peer refused to send them. * lift up underlying xdns value instead, keeping "dns" filled */ if (strlen(buf) == 0) sprintf(buf, "%s", nvram_safe_get(strcat_r(prefix, "xdns", tmp))); nvram_set(strcat_r(prefix, "dns", tmp), buf); wan_up(wan_ifname); _dprintf("%s:: done\n", __FUNCTION__); return 0; }
int mdev_tty_main(int argc, char **argv) { FILE *fp; int isLock, devnum, has_int_pipe; char usb_port_id[64], usb_interface_id[64], node_fname[64]; const char *device_name, *action; if(argc != 3){ printf("Usage: %s [device_name] [action]\n", argv[0]); return 0; } device_name = argv[1]; action = argv[2]; usb_dbg("(%s): action=%s.\n", device_name, action); if (!isSerialNode(device_name) && !isACMNode(device_name)) return 0; sprintf(node_fname, "%s/%s", MODEM_NODE_DIR, device_name); // Check Lock. if((isLock = file_lock((char *)device_name)) == -1) return 0; // If remove the device? if(!check_hotplug_action(action)){ unlink(node_fname); if (get_usb_modem_wan(0)) notify_rc("on_unplug_usb_modem"); usb_dbg("(%s): Remove the modem node\n", device_name); goto out_unlock; } // Get DevNum devnum = 0; has_int_pipe = 0; usb_port_id[0] = 0; if (get_interface_by_device(device_name, usb_interface_id, sizeof(usb_interface_id))) { has_int_pipe = get_interface_Int_endpoint(usb_interface_id); if (get_usb_port_by_interface_string(usb_interface_id, usb_port_id, sizeof(usb_port_id))) devnum = get_usb_devnum(usb_port_id); } // Write node file. mkdir_if_none(MODEM_NODE_DIR); fp = fopen(node_fname, "w+"); if (fp) { fprintf(fp, "pref=%d\n", (has_int_pipe) ? 1 : 0); fprintf(fp, "devnum=%d\n", devnum); fprintf(fp, "portid=%s\n", usb_port_id); fclose(fp); } if (nvram_invmatch("modem_arun", "0") && nvram_match("modem_rule", "1") && nvram_invmatch("modem_type", "3")) notify_rc("on_hotplug_usb_modem"); usb_dbg("(%s): Success!\n", device_name); out_unlock: file_unlock(isLock); return 1; }
/* * Called when link comes up */ int ipup_main(int argc, char **argv) { FILE *fp; char *wan_ifname = safe_getenv("IFNAME"); char *wan_linkname = safe_getenv("LINKNAME"); char tmp[100], prefix[] = "wanXXXXXXXXXX_"; char buf[256], *value; int unit; _dprintf("%s():: %s\n", __FUNCTION__, argv[0]); /* Get unit from LINKNAME: ppp[UNIT] */ if ((unit = ppp_linkunit(wan_linkname)) < 0) return 0; _dprintf("%s: unit=%d ifname=%s\n", __FUNCTION__, unit, wan_ifname); snprintf(prefix, sizeof(prefix), "wan%d_", unit); /* Stop triggering demand connection */ if (nvram_get_int(strcat_r(prefix, "pppoe_demand", tmp))) nvram_set_int(strcat_r(prefix, "pppoe_demand", tmp), 1); #ifdef RTCONFIG_USB_MODEM // wanX_ifname is used for device for USB Modem if ((value = getenv("DEVICE")) && (isSerialNode(value) || isACMNode(value))) nvram_set(strcat_r(prefix, "ifname", tmp), value); #endif /* Touch connection file */ if (!(fp = fopen(strcat_r("/tmp/ppp/link.", wan_ifname, tmp), "a"))) { perror(tmp); return errno; } fclose(fp); if ((value = getenv("IPLOCAL"))) { if (nvram_invmatch(strcat_r(prefix, "ipaddr", tmp), value)) ifconfig(wan_ifname, IFUP, "0.0.0.0", NULL); _ifconfig(wan_ifname, IFUP, value, "255.255.255.255", getenv("IPREMOTE")); nvram_set(strcat_r(prefix, "ipaddr", tmp), value); nvram_set(strcat_r(prefix, "netmask", tmp), "255.255.255.255"); } if ((value = getenv("IPREMOTE"))) nvram_set(strcat_r(prefix, "gateway", tmp), value); #ifdef RTCONFIG_DSL /* Paul add 2013/1/23, only for Auto DNS and 3G/4G */ if (!nvram_match(strcat_r(prefix, "dnsenable_x", tmp), "0")) { #endif strcpy(buf, ""); if ((value = getenv("DNS1"))) sprintf(buf, "%s", value); if ((value = getenv("DNS2"))) sprintf(buf + strlen(buf), "%s%s", strlen(buf) ? " " : "", value); /* set PPP DNS, no DNS/usepeerdns forces update_resolvconf use xdns value */ nvram_set(strcat_r(prefix, "dns", tmp), buf); #ifdef RTCONFIG_DSL } #endif wan_up(wan_ifname); _dprintf("%s:: done\n", __FUNCTION__); return 0; }