Return-Path: Message-ID: From: Albert Huang To: bluez-devel@lists.sourceforge.net Subject: Re: [Bluez-devel] hcitool feature patch In-Reply-To: <43948373.9080606@masaka.cs.ohiou.edu> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_33849_22636644.1133808267426" References: <43948373.9080606@masaka.cs.ohiou.edu> Sender: bluez-devel-admin@lists.sourceforge.net Errors-To: bluez-devel-admin@lists.sourceforge.net Reply-To: bluez-devel@lists.sourceforge.net List-Unsubscribe: , List-Id: BlueZ development List-Post: List-Help: List-Subscribe: , List-Archive: Date: Mon, 5 Dec 2005 13:44:27 -0500 ------=_Part_33849_22636644.1133808267426 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline oh gee, I dunno. Marcel hates my coding style ;) better might be to patch the bluez-libs and then patch hcitool to call a library function. -albert On 12/5/05, Jim Wyllie wrote: > > I had to write a program which changed the flush timeout for a Bluetooth > connection. I integrated it into my version of hcitool since that > seemed the appropriate place for it. The patch applies to hcitool in > bluez-utils 2.22, and adds the 'ftmo' option (for flush timeout). Let > me know if you want me to make any changes. > > Jim Wyllie > IRG Lab > Ohio University > > > 966a967,1089 > > /* Alter connection timeout (for all connections, unfortunately) */ > > > > static struct option ftmo_options[] =3D { > > { "help", 0, 0, 'h' }, > > { "tmout", 1, 0, 't' }, > > { 0, 0, 0, 0 } > > }; > > > > static char *ftmo_help =3D > > "Usage:\n" > > "\tftmo --tmout=3Dvalue bdaddr\n" > > "Sets the flush timeout value to 0.625msec * value for bdaddr\n" > > "Will change reliability for all connections from > microcontroller\n"; > > > > static void cmd_ftmo(int dev_id, int argc, char **argv) > > { > > int err =3D 0, dd, opt, timeout; > > struct hci_conn_info_req *cr =3D 0; > > struct hci_request rq =3D { 0 }; > > bdaddr_t *ba; > > > > struct { > > uint16_t handle; > > uint16_t flush_timeout; > > } cmd_param; > > > > struct { > > uint8_t status; > > uint16_t handle; > > } cmd_response; > > > > for_each_opt(opt, ftmo_options, NULL) { > > switch (opt) { > > > > case 't': > > timeout =3D atoi( optarg ); > > > > if( timeout < 0) { > > printf("Must be 1 or greater, or 0 for no > timeout\n"); > > printf(ftmo_help); > > } > > > > break; > > > > default: > > printf(ftmo_help); > > return; > > } > > } > > > > argc -=3D optind; > > argv +=3D optind; > > > > if (argc < 1) { > > printf(ftmo_help); > > return; > > } > > > > ba =3D (bdaddr_t *)malloc( sizeof( bdaddr_t ) ); > > str2ba(argv[0], ba); > > > > if (dev_id < 0) { > > dev_id =3D hci_get_route(ba); > > if (dev_id < 0) { > > perror("Error in obtaining route to device\n"); > > return; > > } > > } > > > > // find the connection handle to the specified bluetooth device > > cr =3D (struct hci_conn_info_req*) malloc( > > sizeof(struct hci_conn_info_req) + > > sizeof(struct hci_conn_info)); > > > > bacpy( &cr->bdaddr, ba ); > > > > cr->type =3D ACL_LINK; > > > > dd =3D hci_open_dev( dev_id ); > > > > if( dd < 0 ) { > > err =3D dd; > > goto cleanup; > > } > > > > err =3D ioctl(dd, HCIGETCONNINFO, (unsigned long) cr ); > > > > if( err ) { > > fprintf(stderr, "Could not get connection handle, is one > established yet?\n"); > > goto cleanup; > > } > > > > // build a command packet to send to the bluetooth microcontrolle= r > > cmd_param.handle =3D cr->conn_info->handle; > > cmd_param.flush_timeout =3D htobs(timeout); > > rq.ogf =3D OGF_HOST_CTL; > > rq.ocf =3D 0x28; > > rq.cparam =3D &cmd_param; > > rq.clen =3D sizeof(cmd_param); > > rq.rparam =3D &cmd_response; > > rq.rlen =3D sizeof(cmd_response); > > rq.event =3D EVT_CMD_COMPLETE; > > > > // send the command and wait for the response > > err =3D hci_send_req( dd, &rq, 0 ); > > > > if( err ) { > > perror("Could not send request to the microcontroller"); > > goto cleanup; > > } > > > > if( cmd_response.status ) { > > err =3D -1; > > errno =3D bt_error(cmd_response.status); > > } > > > > cleanup: > > free(cr); > > if( dd >=3D 0) > > close(dd); > > return; > > } > > > 2055a2179 > > { "ftmo", cmd_ftmo, "Modify microcontroller flush timeout" }, > > > ------=_Part_33849_22636644.1133808267426 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline oh gee, I dunno.  Marcel hates my coding style ;)

better might be to patch the bluez-libs and then patch hcitool to call a li= brary function.

-albert

On 12/5/05, Jim Wyllie <jwyllie@masaka.cs.ohiou.edu> wrote:
I had to write a program which changed the flush timeout for a Bluetoothconnection.  I integrated it into my version of hcitool since th= at
seemed the appropriate place for it.  The patch applies to = hcitool in
bluez-utils=20 2.22, and adds the 'ftmo' option (for flush timeout).  Let
me = know if you want me to make any changes.

Jim Wyllie
IRG Lab
Oh= io University


966a967,1089
> /* Alter connection timeout (= for all connections, unfortunately) */
>
> static struct option ftmo_options[] =3D {
> &nb= sp;     { "help",    &nbs= p;  0, 0, 'h' },
>       { "t= mout",      1, 0, 't' },
> &n= bsp;     { 0, 0, 0, 0 }
> };
>
> stat= ic char *ftmo_help =3D
>       "Usage:\n"
>&n= bsp;      "\tftmo --tmout=3Dvalue bdaddr\n&qu= ot;
>       "Sets the flush timeou= t value to 0.625msec * value for bdaddr\n"
>   &n= bsp;   "Will change reliability for all connections from mic= rocontroller\n";
>
> static void cmd_ftmo(int dev_id, int argc, char **argv)> {
>       int err =3D 0, dd, opt,= timeout;
>       struct hci_conn_info_= req *cr =3D 0;
>       struct hci_reque= st rq =3D { 0 };
>       bdaddr_t *ba;
>
> = ;      struct {
>    &nb= sp;          uint16_t handle;<= br>>           &n= bsp;   uint16_t flush_timeout;
>    &nb= sp;  } cmd_param;
>
>       = struct {
>          = ;     uint8_t  status;
>           &= nbsp;   uint16_t handle;
>     &nb= sp; } cmd_response;
>
>       for= _each_opt(opt, ftmo_options, NULL) {
>     &= nbsp;         switch (opt) {
>= ;
>           =     case 't':
>      &nb= sp;            =     timeout =3D atoi( optarg );
>
>     &n= bsp;            = ;     if( timeout < 0) {
>       &nbs= p;            &= nbsp;          printf("Must be 1 or greater, or 0 for no timeout\n");
>&nb= sp;            =             &nb= sp;     printf(ftmo_help);
>        &= nbsp;           &nbs= p;  }
>
>         &nbs= p;             break;
>
>         = ;      default:
>    &nb= sp;            =       printf(ftmo_help);
>        &= nbsp;           &nbs= p;  return;
>          =      }
>       }>
>       argc -=3D optind;
>=        argv +=3D optind;
>
> = ;      if (argc < 1) {
>   = ;            printf(= ftmo_help);
>         &n= bsp;     return;
>       }
>
>  &= nbsp;    ba =3D (bdaddr_t *)malloc( sizeof( bdaddr_t ) );>       str2ba(argv[0], ba);
>
&= gt;       if (dev_id < 0) {
> &= nbsp;           &nbs= p; dev_id =3D hci_get_route(ba);
>      = ;         if (dev_id < 0) {
>           &= nbsp;           perror("Error in obtaining route to device\n");
> &nbs= p;            &= nbsp;        return;
>          =      }
>       }>
>       // find the connection ha= ndle to the specified bluetooth device
>     = ;  cr =3D (struct hci_conn_info_req*) malloc(
>   = ;    sizeof(struct hci_conn_info_req) +
>       sizeof(struct hci_conn_info));=
>
>       bacpy( &cr->bda= ddr, ba );
>
>       cr->type = =3D ACL_LINK;
>
>       dd =3D hc= i_open_dev( dev_id );
>
>       i= f( dd < 0 ) {
>           &= nbsp;   err =3D dd;
>      &n= bsp;        goto cleanup;
> &= nbsp;     }
>
>    &nbs= p;  err =3D ioctl(dd, HCIGETCONNINFO, (unsigned long) cr );
>>       if( err ) {
>  &n= bsp;            fprintf(stderr, "Could not get connection handle, is one established yet?\n");
>         = ;      goto cleanup;
>   &nbs= p;   }
>
>       // bui= ld a command packet to send to the bluetooth microcontroller
> &= nbsp;     cmd_param.handle =3D cr->conn_info->han= dle;
>       cmd_param.flush_timeout =3D htobs(= timeout);
>       rq.ogf =3D OGF_HOST_C= TL;
>       rq.ocf =3D 0x28;
>&nb= sp;      rq.cparam =3D &cmd_param;
>&nbs= p;      rq.clen =3D sizeof(cmd_param);
>&nbs= p;      rq.rparam =3D &cmd_response;
>       rq.rlen= =3D sizeof(cmd_response);
>       rq.e= vent =3D EVT_CMD_COMPLETE;
>
>     &nb= sp; // send the command and wait for the response
>   =     err =3D hci_send_req( dd, &rq, 0 );
>
>       if( err ) {
>&nb= sp;            =   perror("Could not send request to the microcontroller");
>&= nbsp;           &nbs= p;  goto cleanup;
>       }
>= ;
>       if( cmd_response.status ) {>           &nb= sp;   err =3D -1;
>      &nbs= p;        errno =3D bt_error(cmd_respons= e.status);
>       }
>
>  &= nbsp;    cleanup:
>      = ;         free(cr);
> &n= bsp;            = ; if( dd >=3D 0)
>        =        close(dd);
>   &n= bsp;           return;> }
>
2055a2179
>       { = "ftmo",   cmd_ftmo,   "Modify microcontr= oller flush timeout" },



------=_Part_33849_22636644.1133808267426-- ------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click _______________________________________________ Bluez-devel mailing list Bluez-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/bluez-devel