can somebody help me with buetooth obex ftp

RNA
2007-05-29
2013-05-01
  • RNA
    RNA
    2007-05-29

    i Have wriiten a code in "c" and it works fine for bluetooth connection with my cell but the OBEX_REQUEST_PUT does not work.I am not able track what the issue is.Below is the program plz tell me if i'm missing something,

    typedef struct client_context {
         int serverdone;
         int clientdone;
         char *get_name;     /* Name of last get-request */
         int arg;          /* error code */
         int opcode;
         char *rsp;        /* response storage place */
         uint32_t con_id;          /* connection ide */
         void *private;
    } client_context_t;

    void obex_event(obex_t *handle, obex_object_t *object, int mode, int event, int obex_cmd, int obex_rsp)
    {

    }
    int get_filesize(const char *filename)
    {
         struct stat stats;

         stat(filename, &stats);
         return (int) stats.st_size;
    }

    uint8_t *easy_readfile(const char *filename, int *file_size)
    {
         int actual;
         int fd;
         uint8_t *buf;

         fd = open(filename);
         if (fd == -1) {
              return NULL;
         }
         int file_size1 = get_filesize(filename);
         printf("name=%s, size=%d\n", filename, file_size1);
       if (!(buf = malloc(file_size1))) {
            return NULL;
       }

        actual = read(fd, buf, file_size1);

            if(buf == NULL)
                    printf("read file is null\n");

         close(fd);

         *file_size = actual;
            printf("*******");
            printf("buf :%d\n",*buf);
         return buf;
    }

    void syncwait(obex_t *handle)
    {
            client_context_t *gt;
            int ret;

            gt = OBEX_GetUserData(handle);

            while(!gt->clientdone) {
                    //printf("syncwait()\n");
                    ret = OBEX_HandleInput(handle, 10);
                    if(ret < 0) {
                            printf("Error while doing OBEX_HandleInput()\n");
                            break;
                    }
                    if(ret == 0) {
                            /* If running cable. We get no link-errors, so cancel on timeout */
                            printf("Timeout waiting for data. Aborting\n");
                            OBEX_CancelRequest(handle, 0);
                            break;
                    }
            }

            gt->clientdone =1 ;
    }

    void put_client(obex_t *handle)
    {
            obex_object_t *object;

            char lname[100];//="2.png";
            char rname[100];//="2.png";
            unsigned int rname_size;
            obex_headerdata_t hd;
            uint8_t *buf;
            int file_size;
            printf("PUT file (local, remote)> ");
            scanf("%s %s", lname, rname);
            buf = easy_readfile(lname, &file_size);
            if(buf == NULL)
                    return;
            printf("Going to send %d bytes\n", file_size);
            /* Build object */
            object = OBEX_ObjectNew(handle, OBEX_CMD_PUT);

            uint8_t *ucname;
            int ucname_len;
            ucname_len = strlen(rname)*2 + 2;
            ucname = malloc(ucname_len);
            int err=0;

            hd.bq4 = ConnectionID;
            OBEX_ObjectAddHeader(handle, object, OBEX_HDR_CONNECTION, hd, 4, 0);
            rname_size = OBEX_CharToUnicode(ucname,  rname,ucname_len);
            hd.bq4 = file_size;
            OBEX_ObjectAddHeader(handle, object, OBEX_HDR_LENGTH, hd,  sizeof(uint32_t), 0);
            hd.bs = (uint8_t *) ucname;
            OBEX_ObjectAddHeader(handle, object, OBEX_HDR_NAME, hd, ucname_len, 0);
            hd.bs = buf;
            OBEX_ObjectAddHeader(handle, object, OBEX_HDR_BODY, hd, file_size, OBEX_FL_STREAM_START);
            if((err=OBEX_Request(handle, object)) < 0)
                    printf("Error sending =%d\n",err);
            syncwait(handle);
    }

    int main (int argc, char *argv[])
    {
            char* pcMacddr="xx:xx:xx:xx:xx:xx";
            char* pcChannel;
            uint8_t channel=9;
            obex_t *handle;
            if(! (handle = OBEX_Init(OBEX_TRANS_BLUETOOTH, obex_event, 0)))
            {
                    printf("Error initializing callbac event\n");

            }
            client_context_t *gt;
            gt = malloc(sizeof(client_context_t));
            memset(gt, 0, sizeof(client_context_t));
            OBEX_SetUserData(handle, gt);
            bdaddr_t *dst;
            str2ba(pcMacddr, &dst);
            if(BtOBEX_TransportConnect (handle ,BDADDR_ANY  ,& dst,  channel)<0)
            {
                    printf("Error connecting client\n");
                    getchar();
                    return 0;
            }
            int err=0;
            obex_object_t *oo;
            oo = OBEX_ObjectNew(handle, OBEX_CMD_CONNECT);
            obex_headerdata_t hd;
            obex_object_t *object;
            err = OBEX_Request(handle, oo);
            syncwait(handle);
            if(err < 0)
            {
                    printf("Obex Request failed\n");
                    getchar();
                    return 0;
            }
            printf("Started a new request\n");
            gt = OBEX_GetUserData(handle);
            put_client(handle);
            return 0;
    }

    I think i'm missing some thing plz lemme know ,

     
    • Please be more specific. This is too much code to read jff. You might want to compare to http://dev.zuckschwerdt.org/openobex/wiki/ObexFtpExampleClientC and examine each part.
      If you want a quick result try some scripting language and ObexFTP.

       
      • RNA
        RNA
        2007-05-31

        I got the solution.Thanks guys for ur help
        :)

         
    • RNA
      RNA
      2007-05-29

      I have gone thru this code .But during BtOBEX_TransportConnect request , the request comes to the cell phone (bluetooth device) and after connection in the obex_event i get 0X43(OBEX_RSP_FORBIDDEN) obex_rsp for OBEX_CMD_CONNECT.Can you tell me the reason why this happens?

       
      • I see. You need to setup the connection properly. Send a connect with the proper UUID. This is FBS for most mobiles. In some cases it's the PCSOFTWARE UUID or maybe the S45 UUID for older Siemens mobiles.

         
        • surfzoid
          surfzoid
          2007-05-29

          When yu send the obex frame for connect, the fone answer, yu should find 0xCB, and then the UUID is 0xCB 0xxx 0xxx 0xxx 0xxx, for me and my too phone i have one with 0xCB 0x00 0x00 0x00 0x00 and other 0xCB 0x00 0x00 0x00 0x01, 5 Bytes.

          Also i don't know and never use openobex to write a client, if openobex can't give yu this response from the phone yu can use jobexftp (from me) at SF.net and then yu can see the hex frame of obex response.

           
          • Eric, you are talking about the Connection ID. Like you write you can not use the header 0xCB in CONNECT and that's where the error happens. Connection ID is mostly optional and will error with 0xD3, Service Unavailable.

            If suppling the appropriate UUID and handling Connection IDs is too much trouble, have a look at the ObexFTP API. On the other hand if you want to explore OBEX and learn something try OpenOBEX itself. jobexftp is very early in develpment and a bit unstable I guess.

             
            • RNA
              RNA
              2007-05-30

              Now i have got it working but the file transferred have size zero always.I think the problem is with the header.The file name i receive is same as i input .And one more thing i don't get the call bac event called after Obex put request.Can u plz tell if thr is anything wrong with the code below,

              struct stat stats;
              stat(filename, &stats);
              int file_size = stats.st_size;
              int fd = open(filename,O_RDONLY);
              uint8_t *buf= malloc(file_size);
              int actual = read(fd, buf, file_size1);

              strcpy(rname,"MyFile");
              uint8_t *ucname;
              int ucname_len;
              ucname_len = strlen(rname)*2 + 2;
              ucname = malloc(ucname_len);

              rname_size = OBEX_CharToUnicode(ucname,  rname,ucname_len);
              hd.bs = (uint8_t *) ucname;
              OBEX_ObjectAddHeader(handle, object, OBEX_HDR_NAME, hd, ucname_len, 0);
              hd.bq4 = actual ;
              OBEX_ObjectAddHeader(handle, object, OBEX_HDR_LENGTH, hd,  sizeof(uint32_t), 0);
              hd.bs = buf;
              OBEX_ObjectAddHeader(handle, object, OBEX_HDR_BODY, hd,actual ,0);
              OBEX_Request(handle, object)

               
            • surfzoid
              surfzoid
              2007-05-30

              Yu are complety right zany about UUID and Id, sorry.
              also i spoke about jobexftp only for test and debug, i never think about publicity or to replace openobex stuff because this one is more like "Yoda" for me and i never plane to do  a staff bigest and great as yu, i haven't got enouth knoeldge for this.
              For K750I and M341i/342 jobexftp seems to work corectly.