📄 ltmodem.c,v
字号:
a85 1 printf( "About to dial %s:\n", optarg ); sleep(3);
d87 15d104 1d106 2a107 1 sleep(1);
d110 3a112 1 // Wait for answer tone.
d114 1a114 1 printf("Answer tone detected!\n");
d116 2a117 1 printf("No answer tone detected, bummer!\n");
d124 2a125 2 printf( "About to hangup\n" ); sleep(5);
dp_onhook_cmd();
d127 1d227 1a227 1 printf( "-t basic test, display checksum etc.\n");
d238 4d243 1a243 1
d374 3d378 1d390 3d395 1d498 2a499 2 speakerEnable = (unsigned char)Enabled;
speakerVolume = Volume;
d505 22a526 1// Wait for answer tone, timing out after 5 seconds.
d530 2a531 1 int timeout = 5000;
d535 1a535 1 dp_timer = x_current_time();
d540 1a540 1 // Wait until answer tone detected or 5 seconds has expired.
d542 1a542 1 if (x_elapsed_time(dp_timer) > timeout)
d544 4d551 16@1.5log@Revised for 0.0.6, added dialling stuff from Pavel and minor mod to initialisation.@text@d2 1a2 1 * $Id: ltmodem.c,v 1.4 1999/08/16 02:59:21 root Exp root $
d6 1a6 1 * Copyright (c) 1999 Richard J.M. Close
d8 1a13 1#include "control.h"
d16 1a20 23int verbose = 0;
// Dial the number held in the argument string.
void dial(char *s)
{
sleep(2); /* We do no dial tone detection, so we'll just wait */
while (*s) {
switch (*s) {
case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
if (pulseDial)
dp_pulse_dial_cmd(*s-'0');
else
dp_DTMF_dial_cmd(*s-'0');
break;
default:
printf( "Unknown character in dial sequence `%c' ignored.\n", *s );
break;
}
s++;
}
}
d32 1a32 11 modem = 0;
io_cnt = 0;
pacc = pci_alloc();
pacc->error = die;
pci_filter_init(pacc, &filter);
pci_init(pacc);
scan_devices();
sort_them();
d41 1d45 1a45 1 while ((c = getopt(argc, argv, "imovthpd:" )) != -1) {
d51 3d58 11d74 3d79 2a80 1 // Dial how you want.
d82 14d103 3a105 1 printf("Ready\n" ); sleep(5);
d117 58a174 1 printf( "About to hangup.\n" ); sleep(5);
d177 2d193 5a197 2 printf( "-o run offhook command and dial PI.\n");
printf("-v increase level of verbosity.\n");
d199 3d209 1a209 1 pci_cleanup(pacc);
d214 1a214 2void
setup_irq(void)
d217 1d219 7a225 2 printf( "Removing i2sig\n" );
system("rmmod i2sig");
d227 5a231 2 // Setup IRQ variable used by other stuff.
modem_irq = modem_dev->dev->irq;
d233 14a246 8#if TRY_INTERRUPTS == 1
sprintf( buf, "insmod ./i2sig.o irq=%d pid=%d", modem_irq, getpid());
printf( "Installing new i2sig: %s\n", buf );
system(buf);
#else
sprintf( buf, "TRY_INTERRUPTS disabled for modem IRQ %d.", modem_irq);
printf( "%s\n", buf );
#endif
d248 2a249 1 signal_init();
a251 1/* Find any known any Lucent modems. */
d253 1a253 2static int
find_modem(void)
d255 2a256 29 struct device *d;
int i;
for(d=first_dev; d; d=d->next) {
struct pci_dev *p = d->dev;
/* Only cards with vendor ID = Lucent!. */
if (p->vendor_id == 0x11c1) {
modem_dev = d;
modem = 1;
io_cnt = 0;
/* Record I/O addresses. */
for(i=0; i<htype0_cnt; i++){
pciaddr_t pos = p->base_addr[i];
u32 flg = get_conf_long(d, PCI_BASE_ADDRESS_0 + 4*i);
if (flg == 0xffffffff) flg = 0;
if (!pos && !flg) continue;
if (flg & PCI_BASE_ADDRESS_SPACE_IO)
{
io_address[i] = pos & PCI_BASE_ADDRESS_IO_MASK;
io_length[i] = (io_address[i] < 0x3f8) ? 8 : 256;
io_cnt = i;
}
}
}
}
return modem;
a258 75// Show any found modem.
static void show_modem(void)
{
int c;
struct pci_dev *p = modem_dev->dev;
byte classbuf[128], devbuf[128];
unsigned int irq = p->irq;
byte latency = get_conf_byte( modem_dev, PCI_LATENCY_TIMER);
word status = get_conf_word( modem_dev, PCI_STATUS);
word cmd = get_conf_word( modem_dev, PCI_COMMAND);
byte max_lat, min_gnt;
word subsys_v, subsys_d;
char ssnamebuf[256];
printf("%02x:%02x.%x %s: %s",
p->bus,
p->dev,
p->func,
pci_lookup_name(pacc, classbuf, sizeof(classbuf),
PCI_LOOKUP_CLASS,
get_conf_word( modem_dev, PCI_CLASS_DEVICE), 0),
pci_lookup_name(pacc, devbuf, sizeof(devbuf),
PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE,
p->vendor_id, p->device_id));
if (c = get_conf_byte( modem_dev, PCI_REVISION_ID))
printf(" (rev %02x)", c);
if (c = get_conf_byte( modem_dev, PCI_CLASS_PROG))
printf(" (prog-if %02x)", c);
putchar('\n');
// Only cards with device ID 0x44* are mars chipset based.
if ((p->device_id & 0xfff0) == 0x440)
printf("Mars chipset detected.\n");
else
printf("Warning: your modem does not have a mars chipset.\n");
max_lat = get_conf_byte( modem_dev, PCI_MAX_LAT);
min_gnt = get_conf_byte( modem_dev, PCI_MIN_GNT);
subsys_v = get_conf_word( modem_dev, PCI_SUBSYSTEM_VENDOR_ID);
subsys_d = get_conf_word( modem_dev, PCI_SUBSYSTEM_ID);
if (subsys_v && subsys_v != 0xffff)
printf("\tSubsystem: %s\n",
pci_lookup_name(pacc, ssnamebuf, sizeof(ssnamebuf),
PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE,
subsys_v, subsys_d));
printf("\tFlags: ");
if (cmd & PCI_COMMAND_MASTER)
printf("bus master, ");
if (cmd & PCI_COMMAND_VGA_PALETTE)
printf("VGA palette snoop, ");
if (cmd & PCI_COMMAND_WAIT)
printf("stepping, ");
if (cmd & PCI_COMMAND_FAST_BACK)
printf("fast Back2Back, ");
if (status & PCI_STATUS_66MHZ)
printf("66Mhz, ");
if (status & PCI_STATUS_UDF)
printf("user-definable features, ");
printf("%s devsel",
((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_SLOW) ? "slow" :
((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_MEDIUM) ? "medium" :
((status & PCI_STATUS_DEVSEL_MASK) == PCI_STATUS_DEVSEL_FAST) ? "fast" : "??");
if (cmd & PCI_COMMAND_MASTER)
printf(", latency %d", latency);
if (irq)
printf(", IRQ " IRQ_FORMAT, irq);
putchar('\n');
show_htype0( modem_dev);
}
a332 46
void continous_monitoring(int monitor_type, int monitoring_interval){
// Iteration loop variable.
unsigned int i;
// Main monitoring loop.
while (1) {
// Monitor registers or I/O depending on current setting.
if (monitor_type & 1) {
// Re-scan device.
pci_scan_bus(pacc);
modem_dev = scan_device(modem_dev->dev);
// Show the hex.
show_hex_dump(modem_dev);
}
if (monitor_type & 2) {
// Get access to all of I/O space.
if (iopl(3) < 0) {
perror("ltmodem: iopl()");
fprintf(stderr, "This program must be run as root.\n");
}
else {
// Read the ports.
printf("I/O ports\n ");
// Loop for each known port.
for (i=1;i<=io_cnt;i++) {
unsigned int j;
printf( "%x: ", io_address[i] );
for (j=0; j<io_length[i]; j++) {
// Read each byte, one at a time.
printf("%2x ", inb(io_address[i] + j));
if ( !((j+1)%16) )
printf( "\n%x: ", io_address[i] + j + 1);
}
putchar('\n');
}
// Free the ports.
iopl(0);
}
}
// Wait for the configured amount of time.
usleep(monitoring_interval * 1000);
}
}
a367 70
void
redisplay_modem_regs(void)
{
/* Re-scan device. */
printf ("Registers now contain:\n");
pci_scan_bus(pacc);
modem_dev = scan_device(modem_dev->dev);
/* Show the hex. */
show_hex_dump(modem_dev);
}
void
set_modem_cont_reg(void)
{
/* value input by user. */
int input = 0;
/* CR input after first char. */
char trash;
/* Allow user to set control register. */
printf ("Set control register (value in hex): ");
scanf ("%x%c", &input, &trash);
printf ("Writing %x to control register.\n", input);
/* command register is at address 04. */
pci_write_word(modem_dev->dev, 0x04, input);
}
void
set_modem_io(void)
{
unsigned int i;
/* value input by user. */
unsigned int input = 0;
unsigned int offset = 0;
/* CR input after first char. */
char trash;
if (io_cnt > 0) {
printf("I/O ports found:\n");
for(i=1; i<=io_cnt; i++){
printf("%d - I/O port at %x.\n", i, io_address[i]);
}
// Select the port.
printf ("Port to write long word at (in hex): ");
scanf ("%x%c", &input, &trash);
// Write the value.
if ((input > 0) && (input <= io_cnt)) {
// Allow user to write to selected I/O port.
i = input;
printf ("Write to %x, enter value (in hex): ", io_address[i]);
scanf ("%x%c", &input, &trash);
// Get offset to use.
printf ("Offset to use (in hex): ");
scanf ("%x%c", &offset, &trash);
printf ("Writing %2x to I/O port %x + %x.\n", input, io_address[i], offset);
// Write value to port.
WRITE_PORT_UCHAR ((io_address[i] + offset), input);
///* Delay 10ms. */
usleep(10000);
/* Read back the port. */
printf("Read back value: %2x.\n", READ_PORT_UCHAR(io_address[i] + offset));
}
}
}
d403 1d405 1a405 35
/********************************************************************************
*
* PCI utilities.
*
*********************************************************************************/
static struct device *
scan_device(struct pci_dev *p)
{
int how_much = 0x40; /* First 64 bytes. */
struct device *d;
if (!pci_filter_match(&filter, p))
return NULL;
d = xmalloc(sizeof(struct device));
bzero(d, sizeof(*d));
d->dev = p;
if (!pci_read_block(p, 0, d->config, how_much))
die("Unable to read %d bytes of configuration space.", how_much);
if (how_much < 128 && (d->config[PCI_HEADER_TYPE] & 0x7f) == PCI_HEADER_TYPE_CARDBUS)
{
/* For cardbus bridges, we need to fetch 64 bytes more to get the full standard header... */
if (!pci_read_block(p, 0, d->config+64, 64))
die("Unable to read cardbus bridge extension data.");
how_much = 128;
}
d->config_cnt = how_much;
pci_setup_cache(p, d->config, d->config_cnt);
pci_fill_info(p, PCI_FILL_IDENT | PCI_FILL_IRQ | PCI_FILL_BASES | PCI_FILL_ROM_BASE);
return d;
}
static void
scan_devices(void)
d407 1a407 10 struct device *d;
struct pci_dev *p;
pci_scan_bus(pacc);
for(p=pacc->devices; p; p=p->next)
if (d = scan_device(p))
{
d->next = first_dev;
first_dev = d;
}
d410 1a410 2static int
check_root(void)
a411 1 static int is_root = -1;
d413 2a414 4 if (is_root < 0)
is_root = !geteuid();
return is_root;
}
d416 2a417 9static int
config_fetch(struct device *d, unsigned int pos, unsigned int len)
{
if (pos + len < d->config_cnt)
return 1;
if (pacc->method != PCI_ACCESS_DUMP && !check_root())
return 0;
return pci_read_block(d->dev, pos, d->config + pos, len);
}
d419 2a420 1/* Config space accesses */
a421 4static inline byte
get_conf_byte(struct device *d, unsigned int pos)
{
return d->config[pos];
d424 2a425 2static word
get_conf_word(struct device *d, unsigned int pos)
d427 2a428 2 return d->config[pos] | (d->config[pos+1] << 8);
}
d430 1a430 8static u32
get_conf_long(struct device *d, unsigned int pos)
{
return d->config[pos] |
(d->config[pos+1] << 8) |
(d->config[pos+2] << 16) |
(d->config[pos+3] << 24);
}
d432 11a442 1/* Sorting */
d444 3a446 128static int
compare_them(const void *A, const void *B)
{
const struct pci_dev *a = (*(const struct device **)A)->dev;
const struct pci_dev *b = (*(const struct device **)B)->dev;
if (a->bus < b->bus)
return -1;
if (a->bus > b->bus)
return 1;
if (a->dev < b->dev)
return -1;
if (a->dev > b->dev)
return 1;
if (a->func < b->func)
return -1;
if (a->func > b->func)
return 1;
return 0;
}
static void
sort_them(void)
{
struct device **index, **h, **last_dev;
int cnt;
struct device *d;
cnt = 0;
for(d=first_dev; d; d=d->next)
cnt++;
h = index = alloca(sizeof(struct device *) * cnt);
for(d=first_dev; d; d=d->next)
*h++ = d;
qsort(index, cnt, sizeof(struct device *), compare_them);
last_dev = &first_dev;
h = index;
while (cnt--)
{
*last_dev = *h;
last_dev = &(*h)->next;
h++;
}
*last_dev = NULL;
}
/* Normal output */
static void
show_bases(struct device *d, int cnt)
{
struct pci_dev *p = d->dev;
word cmd = get_conf_word(d, PCI_COMMAND);
int i;
for(i=0; i<cnt; i++)
{
pciaddr_t pos = p->base_addr[i];
u32 flg = get_conf_long(d, PCI_BASE_ADDRESS_0 + 4*i);
if (flg == 0xffffffff)
flg = 0;
if (!pos && !flg) continue;
printf("\tRegion %d: ", i);
if (pos && !flg) /* Reported by the OS, but not by the device */
{
printf("[virtual] ");
flg = pos;
}
if (flg & PCI_BASE_ADDRESS_SPACE_IO)
{
pciaddr_t a = pos & PCI_BASE_ADDRESS_IO_MASK;
printf("I/O ports at ");
if (a) {
portbase = (unsigned int) a;
printf(IO_FORMAT, a);
}
else if (flg & PCI_BASE_ADDRESS_IO_MASK)
printf("<ignored>");
else
printf("<unassigned>");
if (!(cmd & PCI_COMMAND_IO))
printf(" [disabled]");
}
else
{
int t = flg & PCI_BASE_ADDRESS_MEM_TYPE_MASK;
pciaddr_t a = pos & PCI_ADDR_MEM_MASK;
int done = 0;
u32 z = 0;
printf("Memory at ");
if (t == PCI_BASE_ADDRESS_MEM_TYPE_64)
{
if (i >= cnt - 1)
{
printf("<invalid-64bit-slot>\n");
done = 1;
}
else
{
i++;
z = get_conf_long(d, PCI_BASE_ADDRESS_0 + 4*i);
if (buscentric_view)
{
if (a || z)
printf("%08x" ADDR_FORMAT, z, a);
else
printf("<unassigned>");
done = 1;
}
}
}
if (!done)
{
if (a)
printf(ADDR_FORMAT, a);
else
printf(((flg & PCI_BASE_ADDRESS_MEM_MASK) || z) ? "<ignored>" : "<unassigned>");
}
printf(" (%s, %sprefetchable)",
(t == PCI_BASE_ADDRESS_MEM_TYPE_32) ? "32-bit" :
(t == PCI_BASE_ADDRESS_MEM_TYPE_64) ? "64-bit" :
(t == PCI_BASE_ADDRESS_MEM_TYPE_1M) ? "low-1M" : "type 3",
(flg & PCI_BASE_ADDRESS_MEM_PREFETCH) ? "" : "non-");
if (!(cmd & PCI_COMMAND_MEMORY))
printf(" [disabled]");
}
putchar('\n');
d448 2d452 2a453 2static void
show_htype0(struct device *d)
a454 1 unsigned long rom = d->dev->rom_base_addr;
d456 3a458 39 show_bases(d, htype0_cnt);
if (rom & 1)
printf("\tExpansion ROM at %08lx%s\n", rom & PCI_ROM_ADDRESS_MASK,
(rom & PCI_ROM_ADDRESS_ENABLE) ? "" : " [disabled]");
if (get_conf_word(d, PCI_STATUS) & PCI_STATUS_CAP_LIST)
{
int where = get_conf_byte(d, PCI_CAPABILITY_LIST);
while (where)
{
int id, next, cap;
printf("\tCapabilities: ");
if (!config_fetch(d, where, 4))
{
puts("<available only to root>");
break;
}
id = get_conf_byte(d, where + PCI_CAP_LIST_ID);
next = get_conf_byte(d, where + PCI_CAP_LIST_NEXT);
cap = get_conf_word(d, where + PCI_CAP_FLAGS);
printf("[%02x] ", where);
if (id == 0xff)
{
printf("<chain broken>\n");
break;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -