Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#2 [2] Make modem_run work with kernel drv

closed-accepted
nobody
None
3
2002-12-25
2002-06-14
Anonymous
No

Patch body didn't get uploaded in the previous try.

Make modem_run work with kernel-mode drv
This patch allows the use of modem_run as a replacement
for Alcatel's speedmgmt daemon. This allows usage of
the kernel-mode driver without using any non-free software.

This patch includes the following changes:
- Rename modem_run to speedtouchd but keep modem_run as
a symlink to it
- -m flag removed, monitoring is by default and the -x
flag can be used to disable it
- speedtouchd can notice disconnections and reconnect
the modem
- interface 1 not claimed and interface 0 claimed later
- fork/kill -USR2 removed, handle_endpoint_int waits in
the main process
- On Linux, makes ioctls to tell kernel driver about
connection/disconnection
- some timeouts modified to match speedmgmt

Discussion

  • Logged In: NO

    It continues to say "no files currently attached"...
    Here is the patch inline:

    diff -ur /usr/local/src/speedtouch-1.1/Makefile.in
    speedtouch-1.1/Makefile.in
    --- /usr/local/src/speedtouch-1.1/Makefile.in Sat Jun 1 01:34:25 2002
    +++ speedtouch-1.1/Makefile.in Sat Jun 8 19:57:47 2002
    @@ -90,7 +90,7 @@
    @echo
    '-------------------------------------------------------------'
    @echo 'Driver for the speedtouch USB has been installed
    sucessfully'
    @echo ''
    -
    @echo 'The binaries (modem_run and pppoax) have been
    installed in :'
    +
    @echo 'The binaries (speedtouchd and pppoax) have been
    installed in :'
    @echo ' * $(sbindir)'
    @echo ''
    @echo 'GNU/Linux users can find a SysV script in :'
    @@ -110,7 +110,9 @@

    modem_run:
    @echo 'Installing the modem_run program ...'
    -
    $(INSTALL) -m 0755 -o $(installuser) bin/modem_run $(sbindir)
    +
    $(INSTALL) -m 0755 -o $(installuser) bin/modem_run
    $(sbindir)/speedtouchd
    +
    ln -sf speedtouchd $(sbindir)/modem_run
    +
    chown -h $(installuser) $(sbindir)/modem_run

    pppoa2:
    @echo 'Installing the pppoa2 ppp pty slave ...'
    @@ -131,6 +133,7 @@

    uninstall :
    rm -f $(sbindir)/modem_run
    +
    rm -f $(sbindir)/speedtouchd
    rm -f $(sbindir)/pppoa2
    rm -f $(sbindir)/pppoa3
    cd $(doc) && $(MAKE) uninstall
    diff -ur /usr/local/src/speedtouch-1.1/src/modem_run.c
    speedtouch-1.1/src/modem_run.c
    --- /usr/local/src/speedtouch-1.1/src/modem_run.c Sat Jun 1 01:34:26 2002
    +++ speedtouch-1.1/src/modem_run.c Sat Jun 8 20:09:30 2002
    @@ -57,6 +57,20 @@
    #include "pppoa3.h"
    #include "extract.h"

    +#ifdef __linux__
    +#include <linux/usbdevice_fs.h>
    +#include <linux/usb.h>
    +struct pusb_device_t
    +{
    +
    int fd;
    +};
    +struct pusb_endpoint_t
    +{
    +
    int fd;
    +
    int ep;
    +};
    +#endif
    +
    /******************************************************************************
    * Defines
    ******************************************************************************/
    @@ -84,13 +98,13 @@

    static int verbose = 0;
    FILE *log = NULL;
    +int monitoring = 1;

    /*****************************************************************************
    * Local Variables
    *****************************************************************************/

    static int dl_512_first = 1;
    -static int link_up = 0;

    static unsigned char data1[] = {

    @@ -229,7 +243,6 @@
    static int get_reference(pusb_device_t fdusb);
    static int modem_start_synchro(pusb_device_t fdusb);
    static int get_state(pusb_device_t fdusb, unsigned char *buf);
    -static int print_state(unsigned char *buf);

    static void usage();
    static void test_sequence(pusb_device_t fdusb);
    @@ -240,8 +253,6 @@
    static void dump(unsigned char *buf, int len);
    static unsigned char give_char(unsigned char c);

    -static void signal_usr2(int signal);
    -
    /*****************************************************************************
    * Main function
    *****************************************************************************/
    @@ -251,13 +262,16 @@
    * Return Values : ?
    * Description : Does all the job (that's fantastic :)
    */
    +void cleanup()
    +{
    +
    report_stop();
    +}
    +
    int main(int argc, char *argv[])
    {

    pusb\_device\_t fdusb;
    int i;
    

    -
    int monitoring = 0;
    -
    unsigned char buf[TOTAL+1000];
    const char * file = NULL;
    char *devicename = NULL;
    char *user;
    @@ -268,7 +282,7 @@
    * 2 - umask to prevent critical data being read from log file
    */
    if(geteuid() != 0) {
    -
    fprintf(stderr, "modem_run must be run with root privileges\n");
    +
    fprintf(stderr, "speedtouchd must be run with root
    privileges\n");

    return\(-1\);
    \}
    

    @@ -287,14 +301,14 @@

        user = "Unknown";
    \}
    

    -
    report(0, REPORT_INFO, "modem_run version %s started by %s
    uid %d\n", VERSION, user, getuid());
    +
    report(0, REPORT_INFO, "speedtouchd version %s started by %s
    uid %d\n", VERSION, user, getuid());

    for \(i=1;i<argc;i++\) \{
    
    if \(strcmp\(argv\[i\],"-v"\) == 0 && i+1<argc\)
    
        verbose = atoi\(argv\[++i\]\);
    

    -
    else if (strcmp(argv[i],"-m")==0)
    -
    monitoring = 1;
    +
    else if (strcmp(argv[i],"-x")==0)
    +
    monitoring = 0;

    else if \(strcmp\(argv\[i\],"-s"\)==0\)
    
        dl\_512\_first = 0;
    
    else if \(strcmp\(argv\[i\],"-f"\)==0 && i+1<argc\)
    

    @@ -308,9 +322,6 @@

    \}
    

    -
    if (file == NULL)
    -
    usage();
    -
    /* we search the modem on the USB bus */
    if (devicename == NULL) {

    @@ -348,11 +359,9 @@
    * which are all the interfaces of the USB modem.
    */

    -
    if ( pusb_claim_interface(fdusb,0) < 0 ||
    -
    pusb_claim_interface(fdusb,1) < 0 ||
    -
    pusb_claim_interface(fdusb,2) < 0) {
    +
    if (pusb_claim_interface(fdusb,2) < 0) {

    -
    report(0, REPORT_ERROR, "Another program/driver is already
    accessing the modem...\n");
    +
    report(0, REPORT_ERROR, "Another program/driver is already
    accessing the modem (cannot claim interface 2)...\n");

    return\(-1\);
    
    \}
    

    @@ -381,10 +390,6 @@

    /\* It failed all the times == \*/
    
    if\(i == 10\) \{
    

    -
    /* Close all */
    -
    if (pusb_release_interface(fdusb,1) < 0)
    -
    report(0, REPORT_ERROR, "pusb_release_interface 1 failed");
    -

        if \(pusb\_release\_interface\(fdusb,2\) < 0\)
    
            perror\("pusb\_release\_interface 2"\);
    

    @@ -403,62 +408,27 @@

    sleep\(1\);
    
    \}
    

    -

    -
    /* reconfigure USB (configuration & alternate settings) */
    -
    if (pusb_set_configuration(fdusb,1) < 0) {
    -
    report(0, REPORT_ERROR, "pusb_set_configuration 1");
    -
    return(-1);
    -
    }
    -

    -
    if (pusb_set_interface(fdusb,1,2) < 0) {
    -
    report(0, REPORT_ERROR, "pusb_set_interface");
    -
    return(-1);
    -
    }

    +
    if (pusb_claim_interface(fdusb,0) < 0) {

    -
    /*
    -
    * We register the signal handler that will be used to signal
    -
    * the up state of the link.
    -
    */
    -
    signal(SIGUSR2 , signal_usr2);
    +
    report(0, REPORT_ERROR, "Another program/driver is already
    accessing the modem (cannot claim interface 0)...\n");
    +
    return(-1);

    -
    /*
    -
    * Start a subprocess (the so called daemon) to make sure the
    -
    * interrupt endpoint is always writable (because we read it
    there)
    -
    */
    -
    handle_endpoint_int(fdusb);
    +
    }

    +
    atexit (cleanup);
    +

    /\* Cosmetic \*/
    

    +
    /*
    get_reference(fdusb);
    test_sequence(fdusb);
    +
    */

    /\* should start line sync \*/
    modem\_start\_synchro\(fdusb\);
    

    -
    /*
    -
    * New method : The child which reads the interrupt endpoint
    -
    * notices the parent process of the up link
    -
    */
    -
    while(!link_up)
    -
    pause();
    -
    -
    /* The physical adsl link has been established */
    -
    report(0, REPORT_INFO, "ADSL synchronization has been
    obtained\n");
    -
    -
    /* We can print the adsl link state (speed) */
    -
    get_state(fdusb,buf);
    -
    print_state(buf);
    -
    -
    /* Close all */
    -
    if (pusb_release_interface(fdusb,1) < 0)
    -
    report(0, REPORT_ERROR, "pusb_release_interface 1 failed");
    -
    -
    if (pusb_release_interface(fdusb,2) < 0)
    -
    report(0, REPORT_ERROR, "pusb_release_interface 2 failed");

    -
    pusb_close(fdusb);
    -
    -
    report_stop();
    +
    handle_endpoint_int(fdusb);

    return\(0\);
    

    @@ -476,10 +446,10 @@
    static void usage()
    {

    -
    fprintf(stderr, "modem_run version %s: $\n", VERSION);
    -
    fprintf(stderr, "usage: modem_run [-v level] [-m] -f
    microcode \n");
    +
    fprintf(stderr, "speedtouchd version %s: $\n", VERSION);
    +
    fprintf(stderr, "usage: speedtouchd [-v level] [-m] [-f
    microcode] \n");
    fprintf(stderr, " -v : verbose level [0-2]\n");
    -
    fprintf(stderr, " -m : monitor the line\n");
    +
    fprintf(stderr, " -x : exit after the first line
    up/down event\n");
    fprintf(stderr, " -s : skip the first 512 bytes
    read\n");
    fprintf(stderr, " -f microcode : upload this microcode file
    first\n");
    fprintf(stderr, " -d device : defines the device to use\n");
    @@ -527,7 +497,7 @@
    if(dl_512_first){

    gettimeofday\(&start,NULL\);
    

    -
    n = pusb_endpoint_read(ep_code,buf,0x200,DATA_TIMEOUT);
    +
    n = pusb_endpoint_read(ep_code,buf,0x200, 3);

    gettimeofday\(&stop,NULL\);
    
    if \(n < 0\) \{
    

    @@ -743,19 +713,19 @@

    memset\(buf,0,TOTAL\);
    

    -
    ret=pusb_control_msg(fdusb,0xc0,0x12,0x07,0x00,buf+OFFSET_7,SIZE_7,100);
    +
    ret=pusb_control_msg(fdusb,0xc0,0x12,0x07,0x00,buf+OFFSET_7,SIZE_7,CTRL_TIMEOUT);
    if (ret<0) return(ret);

    -
    ret=pusb_control_msg(fdusb,0xc0,0x12,0x0b,0x00,buf+OFFSET_b,SIZE_b,100);
    +
    ret=pusb_control_msg(fdusb,0xc0,0x12,0x0b,0x00,buf+OFFSET_b,SIZE_b,CTRL_TIMEOUT);
    if (ret<0) return(ret);

    -
    ret=pusb_control_msg(fdusb,0xc0,0x12,0x0d,0x00,buf+OFFSET_d,SIZE_d,100);
    +
    ret=pusb_control_msg(fdusb,0xc0,0x12,0x0d,0x00,buf+OFFSET_d,SIZE_d,CTRL_TIMEOUT);
    if (ret<0) return(ret);

    -
    ret=pusb_control_msg(fdusb,0xc0,0x01,0x0e,0x00,buf+OFFSET_e,SIZE_e,100);
    +
    ret=pusb_control_msg(fdusb,0xc0,0x01,0x0e,0x00,buf+OFFSET_e,SIZE_e,CTRL_TIMEOUT);
    if (ret<0) return(ret);

    -
    ret=pusb_control_msg(fdusb,0xc0,0x01,0x0f,0x00,buf+OFFSET_f,SIZE_f,100);
    +
    ret=pusb_control_msg(fdusb,0xc0,0x01,0x0f,0x00,buf+OFFSET_f,SIZE_f,CTRL_TIMEOUT);
    if (ret<0) return(ret);

    return\(0\);
    

    @@ -800,16 +770,33 @@

    }

    +static void notify_link_state_to_kernel (pusb_device_t
    fdusb, int up)
    +{
    +#ifdef __linux__
    +
    struct usbdevfs_ioctl iocs;
    +
    iocs.ifno = 1;
    +
    iocs.ioctl_code = !up + 1;
    +
    iocs.data = NULL;
    +
    ioctl(fdusb->fd, USBDEVFS_IOCTL, &iocs);
    +#endif
    +}
    +
    /*
    * Function : print_state
    * Return Values : 0
    * Description : Print a readale modem state
    * NB : buf MUST be 15 bytes long
    */
    -static int print_state(unsigned char *buf)
    +static void link_state_change(pusb_device_t fdusb)
    {
    -
    time_t t = time(NULL);
    +
    unsigned char buf[TOTAL+1000];
    +

    +
    time_t t;
    int down_speed = 0, up_speed = 0;
    +
    int up = 0;
    +
    +
    get_state(fdusb, buf);
    +
    t = time(NULL);

    report\(2, REPORT\_DEBUG,"Modem State\n",ctime\(&t\)\);
    report\(2, REPORT\_DEBUG|REPORT\_DUMP,"c0 12 0007 : ",
    

    buf+OFFSET_7,SIZE_7);
    @@ -820,13 +807,14 @@

    switch \(buf\[OFFSET\_7\]\) \{
    case 0x00:
    

    -
    report(1, REPORT_INFO, "ADSL line is down\n");
    +
    report(0, REPORT_INFO, "ADSL line is down\n");
    +
    notify_link_state_to_kernel (fdusb, 0);

    break;
    case 0x08:
    

    -
    report(1, REPORT_INFO, "ADSL line is blocked?\n");
    +
    report(0, REPORT_INFO, "ADSL line is blocked?\n");

    break;
    case 0x10:
    

    -
    report(1, REPORT_INFO, "ADSL line is synchronising\n");
    +
    report(0, REPORT_INFO, "ADSL line is synchronising\n");

    break;
    case 0x20:
    
    down\_speed = buf\[OFFSET\_b\] | \(buf\[OFFSET\_b+1\]<<8\)
    

    @@ -843,11 +831,14 @@
    }

    report\(0, REPORT\_INFO, "ADSL line is up \(%d kbit/s down | %d
    

    kbit/s up)\n",down_speed,up_speed);
    +
    up = 1;

    break;
    

    +
    default:
    +
    return;
    }
    -

    -
    return(0);
    -
    +
    notify_link_state_to_kernel (fdusb, up);
    +
    if((buf[OFFSET_7] != 0x10) && !monitoring)
    +
    exit (0);
    }

    /*
    @@ -861,20 +852,8 @@
    */
    static void handle_endpoint_int(pusb_device_t fdusb)
    {
    -
    -
    pid_t child_pid;
    -
    -
    fflush(stdout);
    -
    fflush(stderr);
    -
    -
    if ((child_pid=fork ()) == 0) {
    -
    -
    int ret, up;
    -
    unsigned char lbuf[64*53];
    +
    unsigned char lbuf[6];

    pusb\_endpoint\_t ep\_int;
    

    -
    pid_t parent;
    -
    -
    parent = getppid();

    ep\_int = pusb\_endpoint\_open\(fdusb,EP\_INT,O\_RDONLY\);
    

    @@ -891,46 +870,33 @@

    pusb\_close\(fdusb\);
    

    #endif

    -
    for (up=0;;) {
    -
    -
    ret = pusb_endpoint_read(ep_int,lbuf,sizeof(lbuf),0);
    -

    -
    if (ret < 0) {
    -
    report(0, REPORT_ERROR, "Error reading interrupts\n");
    -
    break;
    -
    }
    -

    -
    report(1, REPORT_INFO|REPORT_DUMP, "Received interrupt, len =
    %d\n", lbuf, ret, ret);
    -
    -
    if(ret == 6) {
    -
    -
    /* The magic interrupt for "up state" */
    -
    char up_int[6] = { 0xa1, 0x00, 0x01, 0x00, 0x00, 0x00};
    -
    -
    /* We send a signal only the first time */
    -
    if(!memcmp(up_int, lbuf, 6) && !up) {
    -
    kill(parent, SIGUSR2);
    -
    up = 1;
    +
    while(1)
    +
    {
    +
    int ret = pusb_endpoint_read (ep_int, lbuf, sizeof(lbuf), 0);
    +

    +
    if(ret < 0)
    +
    {
    +
    if(errno == ENODEV)
    +
    {
    +
    report(0, REPORT_INFO, "Device disconnected, shutting down");
    +
    exit (0);
    +
    }
    +
    else
    +
    {
    +
    report(0, REPORT_ERROR, "Error reading interrupts\n");
    +
    continue;

            \}
    

    -
    -

        \}
    

    +
    report(1, REPORT_INFO|REPORT_DUMP, "Received interrupt, len =
    %d\n", lbuf, ret, ret);
    +

    +
    if((lbuf[0] == 0xa1) && (lbuf[1] == 0))
    +
    {
    +
    link_state_change(fdusb);
    +
    }

    \}
    

    -
    pusb_endpoint_close(ep_int);
    -
    -
    _exit(0);
    -
    -
    }
    -
    -}
    -
    -static void signal_usr2(int signal)
    -{
    -
    -
    link_up = ~link_up;
    -
    +/*
    pusb_endpoint_close(ep_int); */
    }

    /*****************************************************************************

     
  • Gomez Edouard
    Gomez Edouard
    2002-07-11

    Logged In: YES
    user_id=275622

    Is it possible for you to send me the patch directly ?

    I'm curious to know why you did these changes, btw i do not
    plan to include kernel driver support in next modem_run
    because it is out of our business. This is Thomson's
    business now.

    NB : my email is <ed dot gomez at wanadoo dot fr>

    --
    Edouard Gomez

     
  • Gomez Edouard
    Gomez Edouard
    2002-07-11

    • priority: 5 --> 3
    • status: open --> open-later
     
  • Gomez Edouard
    Gomez Edouard
    2002-12-25

    • status: open-later --> closed-accepted