Changeset 202 for trunk

Show
Ignore:
Timestamp:
10/17/07 17:39:00 (13 months ago)
Author:
zany
Message:

adding transparent OBEX mode check

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/bfb/bfb_io.c

    r201 r202  
    119119        } 
    120120#endif 
     121} 
     122 
     123/** 
     124        Read (repeatedly) from fd until a timeout or an error is encountered. 
     125 */ 
     126static int bfb_io_read_all(int fd, uint8_t *buffer, int length, int timeout) 
     127{ 
     128        int actual; 
     129        int pos = 0; 
     130        for (;;) { 
     131                actual = bfb_io_read(fd, &buffer[pos], length - pos, timeout); 
     132                if (actual < 0) return actual; 
     133                if (actual == 0) return pos; 
     134                pos += actual; 
     135        } 
    121136} 
    122137 
     
    317332{ 
    318333        char rspbuf[200]; 
     334        int actual; 
    319335#ifdef _WIN32 
    320336        HANDLE ttyfd; 
     
    392408        //      goto bfbmode; 
    393409        //} 
     410 
     411        /* check if we are in transparent OBEX or AT mode:      */ 
     412        /* send an ABORT (0xFF) with cleverly embedded AT command.      */ 
     413        /* look for valid OBEX frame (OK=0xA0, BADREQ=0xC0, or alike)   */ 
     414        DEBUG(1, "Checking for transparent OBEX mode\n"); 
     415        actual = bfb_io_write(ttyfd, "\xFF\x00\x08\xCBATZ\r", 8); 
     416        if (actual == 8) { 
     417                DEBUG(3, "Write ok, reading back\n"); 
     418                actual = bfb_io_read_all(ttyfd, rspbuf, sizeof(rspbuf), 2); 
     419                if (actual >= 3 && rspbuf[actual-1] == actual) { 
     420                        DEBUG(3, "Received %02X OBEX frame\n", (uint8_t)rspbuf[0]); 
     421                        DEBUG(1, "Transparent OBEX\n"); 
     422                        *typeinfo = TT_GENERIC; 
     423                        return ttyfd; 
     424                } 
     425                else if (actual >= 3 && !strncmp(rspbuf, "ATZ", 3)) { 
     426                        DEBUG(1, "AT mode\n"); 
     427                } 
     428        } 
    394429 
    395430        if(do_at_cmd(ttyfd, "ATZ\r", rspbuf, sizeof(rspbuf)) < 0) {