⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 isa_utils.c

📁 话带数据中传真解调程序
💻 C
字号:
/* * *  ISA specific stuff. * *  Copyright (c) 1999 Richard J.M. Close *  Copyright (c) 2000 Angelo R. Di Filippo * *  Can be freely distributed and used under the terms of the GNU GPL. */#include "isa_utils.h"/******************************************************************************** ISA utilities.********************************************************************************/#define n_modem_id 1char modem_id[n_modem_id][8] = { {'H','S','M','0','a','1','9','\0'} };char card[8]     = "\n";char logdev[8]   = "\n";char port[2][11] = {"\n","\n"}; //10 chars should be enough (0xffffffff\n).char irq[3]      = "\n";void init_isa(void){  FILE *fp;  char buf1[1024];  char buf2[1024];  char *p;    int i,j;  bool found       = false;  bool found_port0 = false;  bool found_irq0  = false;  bool found_port1 = false;  bool found_res1  = false;    isapnp_modem = false;  modem_found  = false;  /*   *  First of all if we have a /etc/ltmodem.conf config file let's use it   *  since isapnp could be broken on detection of the modem.   */  if (fp = fopen("/etc/ltmodem.conf","r")) {    while (!feof(fp)) {      fgets(buf1, 1024, fp);      if (p = strstr(buf1, "IO1")) {        p += 3;        while (p[0] == ' ')          p++;        for (i = 0; p[i] != '\n'; i++)          port[0][i] = p[i];      }      if (p = strstr(buf1, "IO2")) {        p += 3;        while (p[0] == ' ')          p++;        for (i = 0; p[i] != '\n'; i++)          port[1][i] = p[i];      }      if (p = strstr(buf1, "IRQ")) {        p += 3;        while (p[0] == ' ')          p++;        for (i = 0; p[i] != '\n'; i++)          irq[i] = p[i];      }    }    fclose(fp);        if ((port[0][0] != '\n') && (port[1][0] != '\n') && (irq[0] != '\n')) {      isapnp_modem = true;      modem_found  = true;      io_address[1] = strtol(port[0], NULL, 16);      io_address[2] = strtol(port[1], NULL, 16);      io_length[1] = 8;      io_length[2] = 8;      io_cnt = 2;            return;    }  }  if ((fp = fopen("/proc/isapnp","r")) == NULL) {    printf("No ISAPNP support; Lucent ISA PnP modem can't be found.\n");    return;  }  /*   * Let's find a valid modem   */  while (!feof(fp)) {    fgets(buf1, 1024, fp);        for (i = 0; i < n_modem_id; i++) {      if (strstr(buf1, modem_id[i])) {        strcpy(logdev, modem_id[i]);        p = buf2;        while (p[0] != '\'')          p++;        p++;        for(j = 0; j < 7; j++)          card[j] = p[j];        card[7] = '\0';                found = true;        break;      }    }        if (found)      break;          strcpy(buf2, buf1);  }  /*   * No valid modem found   */  if(!found) {    fclose(fp);    return;  }    /*   * Let's read Resoucers 0   */  while (!feof(fp)) {    fgets(buf1, 1024, fp);        if (!found_port0) {      if (p = strstr(buf1, "Port")) {        p +=5;        i = 0;        while (p[i] != '-') {          port[0][i] = p[i];          i++;        }        port[0][i + 1] = '\0';                found_port0 = true;      }    }        if (!(p = strstr(buf1, "Active IRQ"))) {      if (p = strstr(buf1, "IRQ")) {	p +=4;	i = 0;	while (p[i] != ' ') {	  irq[i] = p[i];	  i++;	}	irq[i + 1] = '\0';	found_irq0 = true;      }    }        if ((found_port0) && (found_irq0))      break;  }    /*   * Mmh something of strange happened, so we quit   */  if ((!found_port0) || (!found_irq0)) {    fclose(fp);    return;  }    /*   * Let's find Resources 1   */  while (!feof(fp)) {    fgets(buf1, 1024, fp);    if (strstr(buf1, "Resources 1")) {      found_res1 = true;      break;    }  }    /*   * Mmh something of strange happened, so we quit   */  if (!found_res1) {    fclose(fp);    return;  }  while (!feof(fp)) {    fgets(buf1, 1024, fp);        if (p = strstr(buf1, "Port")) {      p +=5;      i = 0;      while (p[i] != '-') {        port[1][i] = p[i];        i++;      }      port[1][i + 1] = '\0';            found_port1 = true;      break;    }  }  /*   * Mmh something of strange happened, so we quit   */  if (!found_port1) {    fclose(fp);    return;  }  fclose(fp);  if ((fp = fopen("/proc/isapnp","w")) == NULL) {    printf("Mmmh... to me you aren't root.\n");    return;  }  fprintf(fp, "card 0 %s\n", card);  fprintf(fp, "dev  0 %s\n", logdev);  fprintf(fp, "deactivate\n");  fprintf(fp, "port 0 %s\n", port[0]);  fprintf(fp, "port 1 %s\n", port[1]);  fprintf(fp, "irq  0 %s\n", irq);  fprintf(fp, "activate\n");  fclose(fp);    isapnp_modem = true;  modem_found  = true;  io_address[1] = strtol(port[0], NULL, 16);  io_address[2] = strtol(port[1], NULL, 16);  io_length[1] = 8;  io_length[2] = 8;  io_cnt = 2;}void cleanup_isa (void){  FILE *fp;  if ((fp = fopen("/proc/isapnp","w")) == NULL) {    printf("Mmmh... to me you aren't root.\n");    return;  }  fprintf(fp, "card 0 %s\n", card);  fprintf(fp, "dev  0 %s\n", logdev);  fprintf(fp, "deactivate\n");  fclose(fp);}unsigned int get_isamodem_irq (void){  return (unsigned int) strtol(irq, NULL, 0);}void show_isamodem(void){  printf("ISA Modem set with IRQ %s, ports %s, and %s.\n",         irq, port[0], port[1]);}void show_isahex_dump(void){}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -