Hi, I wrote:
> > The lbuf usage is still needed, it's the reading buffer. unused_cell is > > just a pointer that keeps tracks of pppoa3 progress into the read buffer > > if there are still ATM cells left in. > > Then that should be changed back. The current patch doesn't seem to use > lbuf at all. Correction. unused_cells is initialised to lbuf at the first loop, and the value of unused_cells is changed to atm_pointer by the call to aal5_frame_from_atm_cells. This is probably a way to walk through lbuf. Ie the use of unused_cells instead of lbuf makes sense. I'll have to look at this a little closer, but I guess it is correct. The lazy mans way to check if it behaves correctly is by using a small lbuf. Guess I'll have a go at that ;) . > > I have just a doubt about the case where: > > - num_bytes_read < 0 > > > > It seems to me, that this case should be checked and invalidate the > > unused_cell data. > > Isn't unused_cells set to NULL by aal5_frame_from_atm_cell() after the > whole frame has been processed? Indeed unused_cells is set to NULL. Also I don't really get your point. Whenever num_bytes_read is not zero -num_bytes_read will be smaller than 0... The two checks whether pti == 1 can be merged. Dropping the "idiotic frame length" check, using the constants from atm.h, renaming n1 to nb_cells, moving the declaration of nb_cells inside the if (pti == 1) and simplifiying the payload length calculation renders the following patch: diff -pruN speedtouch.000/src/pppoa3.c speedtouch/src/pppoa3.c --- speedtouch.000/src/pppoa3.c Tue Nov 18 10:39:35 2003 +++ speedtouch/src/pppoa3.c Tue Nov 18 12:13:08 2003 @@ -955,7 +955,8 @@ static void *read_from_usb_thread(void* { sigset_t signal_set; - unsigned int pos; + int pos; + int num_bytes_read = 0; unsigned char *buffer; unsigned char *aal5_recv_buf; unsigned char *destination_buf; @@ -1002,10 +1003,11 @@ static void *read_from_usb_thread(void* int n; int pti; - unsigned char lbuf[64*53]; + int num_bytes_new; + unsigned char lbuf[64 * ATM_CELL_TOTAL_SIZE]; unsigned char *unused_cells; - /* Reads 64*53 bytes from usb */ + /* Reads 64 * ATM_CELL_TOTAL_SIZE bytes from usb */ do { n = pusb_endpoint_read(ep_data, lbuf, sizeof(lbuf), 0); } while (n < 0 && (errno == EINTR || errno == ETIMEDOUT)); @@ -1018,55 +1020,62 @@ static void *read_from_usb_thread(void* /* Debug information */ report(2, REPORT_DEBUG|REPORT_DATE|REPORT_DUMP, "ATM cells read from USB (%d bytes long)\n", lbuf, n, n); - /* Accumulates data in the aal5_recv buffer */ - /* pti will be equal to the last cell pti */ - pti = aal5_frame_from_atm_cells(aal5_recv_buf, lbuf, n, my_vpi, my_vci, &pos, &unused_cells); - - /* A buffer overflow has been detected */ - if(pti<0) { - report(0, REPORT_ERROR|REPORT_DATE, "Buffer overflow, too many cells for the same aal5 frame\n"); - pti = 0; - } + num_bytes_read += n; /* save total number of bytes to be processed */ + num_bytes_new = n; + unused_cells = lbuf; /* point at start of lbuf */ + + /* Accumulate all cell-data in the aal5_recv buffer */ + /* Depending on how many cells and what type, we have to loop one or more times until everything */ + /* has been dealt with. (for example we read: cell-cell-cell-'end'cell-cell-cell-cell */ + /* Every call to aal5_etc stops after finding an 'end'cell and then pti = 1 ) 1 cell = 53 bytes */ + while (unused_cells != NULL) { + pti = aal5_frame_from_atm_cells(aal5_recv_buf, unused_cells, num_bytes_new, my_vpi, my_vci, &pos, &unused_cells); + + /* 'pos' saves the place, where we are in the aal5_recv_buf */ + + /* A buffer overflow has been detected */ + if (pti < 0) { + report(0, REPORT_ERROR|REPORT_DATE, "Buffer overflow, too many cells for the same aal5 frame\n"); + pti = 0; + } - /* As the last pti is 1, we have to send the aal5_frame data */ - while(pti) { + /* pti = 0 (more frames to follow) or pti = 1 (end of frame-group) */ + /* When pti is 1, we have to send the aal5_frame data */ - /* Debug information */ - report(2, REPORT_DEBUG|REPORT_DATE|REPORT_DUMP, "AAL5 frame joined up (%d bytes long)\n", aal5_recv_buf, pos, pos); + if (pti == 1) { - /* Prepares the aal5 data (no overwrite is done)*/ - n = aal5_frame_dec(aal5_recv_buf, aal5_recv_buf, pos); + int nb_cells; - if(n<0) { + /* Debug information */ + report(2, REPORT_DEBUG|REPORT_DATE|REPORT_DUMP, "AAL5 frame joined up (%d bytes long)\n", aal5_recv_buf, pos, pos); - report(0, REPORT_ERROR|REPORT_DATE, "CRC error in an AAL5 frame\n"); + /* Prepares the aal5 data (no overwrite is done)*/ + n = aal5_frame_dec(aal5_recv_buf, aal5_recv_buf, pos); - } - else { + if (n < 0) { + + report(0, REPORT_ERROR|REPORT_DATE, "CRC error in AAL5 frame\n"); + } + else { + + report(2, REPORT_DEBUG|REPORT_DATE, "CRC okay %d\n", n); - /* Writes the result buffer */ + /* Writes the result buffer */ #ifdef BRIDGING_ENABLED - n += (bridging)?-BRIDGING1483_HEADER:HDLC_HEADER_SIZE; + n += (bridging)?-BRIDGING1483_HEADER:HDLC_HEADER_SIZE; #else - n += HDLC_HEADER_SIZE; + n += HDLC_HEADER_SIZE; #endif - if(write_dest(fdout, destination_buf, n) > 0) - report(2, REPORT_DEBUG|REPORT_DATE, "Extracted PPP packet sent to destination device\n\n"); - - } - - /* Reinitializes pos and n*/ - pos = 0; - pti = 0; - - /* Are cells unused in lbuf ? */ - if(unused_cells != NULL) { + if (write_dest(fdout, destination_buf, n) > 0) + report(2, REPORT_DEBUG|REPORT_DATE, "Extracted PPP packet sent to destination device\n"); - int length; + } - length = sizeof(lbuf) - (unused_cells - lbuf); + /* adjust the values of num_bytes_read based on pos */ - pti = aal5_frame_from_atm_cells(aal5_recv_buf, unused_cells, length, my_vpi, my_vci, &pos, &unused_cells); + nb_cells = (pos / ATM_CELL_DATA_SIZE) * ATM_CELL_TOTAL_SIZE; /* = actual length of payload-frames processed */ + num_bytes_new = num_bytes_read -= nb_cells; /* calculate the rest if there is any */ + pos = 0; } ---end of patch--- Bye, Leonard. -- How clean is a war when you shoot around nukelar waste? Stop the use of depleted uranium ammo! End all weapons of mass destruction. Liste de diffusion modem ALCATEL SpeedTouch USB Pour se désinscrire : mailto:[EMAIL PROTECTED]