* [Bluez-devel] ttyS0 problem
@ 2005-10-09 16:38 davidgchen
2005-10-09 16:45 ` Marcel Holtmann
0 siblings, 1 reply; 6+ messages in thread
From: davidgchen @ 2005-10-09 16:38 UTC (permalink / raw)
To: bluez-devel
[-- Attachment #1: Type: text/plain, Size: 940 bytes --]
Hi marcel,
I want to write some commands to the uart(ttyS0), but it fails. The steps are as follows:
1. hciattach ttyS0 texas
2. Open ttyS0 device again and get a fd, init ttyS0 with speed, flow_ctl and so on,then write a command(0x30) to the fd but return 0; That is nothing is written to ttyS0.
If I write the same command in the function texas(int fd, struct uart_t *u, struct termios *ti), it succeeds.
From bluez-utiles I see the following code which maybe the reason why I can't write the command to ttyS0 after running hciattach ttyS0 texas.
/* Set TTY to N_HCI line discipline */
i = N_HCI;
if (ioctl(fd, TIOCSETD, &i) < 0) {
perror("Can't set line discipline");
return -1;
}
It seems the codes is very important ,because if I delete these codes, the following codes can't run any more.
Is there any method that I can write the command to the ttyS0 successfully after step 1?
regurds,
David
[-- Attachment #2: Type: text/html, Size: 2097 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Bluez-devel] ttyS0 problem
2005-10-09 16:38 davidgchen
@ 2005-10-09 16:45 ` Marcel Holtmann
0 siblings, 0 replies; 6+ messages in thread
From: Marcel Holtmann @ 2005-10-09 16:45 UTC (permalink / raw)
To: bluez-devel
Hi David,
> I want to write some commands to the uart(ttyS0), but it fails.
> The steps are as follows:
>
> 1. hciattach ttyS0 texas
> 2. Open ttyS0 device again and get a fd, init ttyS0 with speed,
> flow_ctl and so on,then write a command(0x30) to the fd but return
> 0; That is nothing is written to ttyS0.
>
> If I write the same command in the function texas(int fd, struct
> uart_t *u, struct termios *ti), it succeeds.
> From bluez-utiles I see the following code which maybe
> the reason why I can't write the command to ttyS0 after running
> hciattach ttyS0 texas.
>
> /* Set TTY to N_HCI line discipline */
> i = N_HCI;
> if (ioctl(fd, TIOCSETD, &i) < 0) {
> perror("Can't set line discipline");
> return -1;
> }
>
> It seems the codes is very important ,because if I delete these
> codes, the following codes can't run any more.
>
> Is there any method that I can write the command to the ttyS0
> successfully after step 1?
after step 1, you must use the HCI raw socket to send commands. What
commands do you wanna send?
Regards
Marcel
-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bluez-devel] ttyS0 problem
[not found] <1128906830.2417.1.camel@localhost.localdomain>
@ 2005-10-10 1:53 ` david
2005-10-10 3:19 ` Marcel Holtmann
0 siblings, 1 reply; 6+ messages in thread
From: david @ 2005-10-10 1:53 UTC (permalink / raw)
To: bluez-devel
Hi marcel,
=D4=DA 2005-10-10=D2=BB=B5=C4 09:13 +0800=A3=ACdavid=D0=B4=B5=C0=A3=BA
> Hi David,
> =20
> > I want to write some commands to the uart(ttyS0), but it fails.
> > The steps are as follows:
> > =20
> > 1. hciattach ttyS0 texas
> > 2. Open ttyS0 device again and get a fd, init ttyS0 with speed,
> > flow_ctl and so on,then write a command(0x30) to the fd but return
> > 0; That is nothing is written to ttyS0.
> > =20
> > If I write the same command in the function texas(int fd, struct
> > uart_t *u, struct termios *ti), it succeeds.
> > From bluez-utiles I see the following code which maybe
> > the reason why I can't write the command to ttyS0 after running
> > hciattach ttyS0 texas.
> > =20
> > /* Set TTY to N_HCI line discipline */
> > i =3D N_HCI;
> > if (ioctl(fd, TIOCSETD, &i) < 0) {
> > perror("Can't set line discipline");
> > return -1;
> > }
> > =20
> > It seems the codes is very important ,because if I delete these
> > codes, the following codes can't run any more.
> > =20
> > Is there any method that I can write the command to the ttyS0
> > successfully after step 1?
> =20
> after step 1, you must use the HCI raw socket to send commands. What
> commands do you wanna send?
> =20
> Regards
> =20
> Marcel
=20
> What commands do you wanna send?
The command is HCI_GO_TO_SLEEP_IND(0x30) which is only one byte. It is a
vendor specific command used to ask the BT device to go to sleep. If BT
device receives the command, maybe it would response
HCILL_GO_TO_SLEEP_ACK(0x31) command to the host.
> after step 1, you must use the HCI raw socket to send commands
Is this means we cannot write command to ttyS0 directly through write()
function?
Regards
David
-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Bluez-devel] ttyS0 problem
2005-10-10 1:53 ` [Bluez-devel] " david
@ 2005-10-10 3:19 ` Marcel Holtmann
0 siblings, 0 replies; 6+ messages in thread
From: Marcel Holtmann @ 2005-10-10 3:19 UTC (permalink / raw)
To: bluez-devel
Hi David,
> > What commands do you wanna send?
> The command is HCI_GO_TO_SLEEP_IND(0x30) which is only one byte. It is a
> vendor specific command used to ask the BT device to go to sleep. If BT
> device receives the command, maybe it would response
> HCILL_GO_TO_SLEEP_ACK(0x31) command to the host.
do you have the specification of these vendor commands? Is this command
according to the HCI specification or is it an extension of the H:4
transport protocol?
> > after step 1, you must use the HCI raw socket to send commands
>
> Is this means we cannot write command to ttyS0 directly through write()
> function?
After calling hciattach the kernel takes over the serial port via the
line discipline and the reads and writes are useless.
Regards
Marcel
-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bluez-devel] ttyS0 problem
[not found] <1129010637.2346.1.camel@localhost.localdomain>
@ 2005-10-11 6:39 ` david
2005-10-11 7:05 ` [Bluez-devel] " david
0 siblings, 1 reply; 6+ messages in thread
From: david @ 2005-10-11 6:39 UTC (permalink / raw)
To: bluez-devel
Hi marcel,
=D4=DA 2005-10-11=B6=FE=B5=C4 14:03 +0800=A3=ACdavid=D0=B4=B5=C0=A3=BA
> Hi David,
> > I want to write some commands to the uart(ttyS0), but it fails.
> > The steps are as follows:
> > =20
> > 1. hciattach ttyS0 texas
> > 2. Open ttyS0 device again and get a fd, init ttyS0 with speed,
> > flow_ctl and so on,then write a command(0x30) to the fd but return
> > 0; That is nothing is written to ttyS0.
> > =20
> marcel write,=20
> > > What commands do you wanna send?
> > The command is HCI_GO_TO_SLEEP_IND(0x30) which is only one byte. It is=
a
> > vendor specific command used to ask the BT device to go to sleep. If B=
T
> > device receives the command, maybe it would response
> > HCILL_GO_TO_SLEEP_ACK(0x31) command to the host.
> =20
> do you have the specification of these vendor commands? Is this command
> according to the HCI specification or is it an extension of the H:4
> transport protocol?
> =20
> > > after step 1, you must use the HCI raw socket to send commands
> >=20
> > Is this means we cannot write command to ttyS0 directly through write(=
)
> > function?
> =20
> After calling hciattach the kernel takes over the serial port via the
> line discipline and the reads and writes are useless.
> =20
> Regards
> =20
> Marcel
Now, I can write command(0x30) to ttyS0 driectly after hciattach tty0
texas(assume step 1);
The function is as follows(assume step 2):
static int write_cmd_to_ttyS0()
{
int fdd;
int len;
char cmd[5];
int temp;
int dd;
=20
fdd =3D open("/dev/ttyS0", O_RDWR | O_NOCTTY);
if (fdd < 0) {
printf("Can't open serial port, fd =3D %d\n",fdd);
return -1;
}
else
printf("open serial ok, fd =3D %d\n", fdd);
=20
temp =3D 0;
if (ioctl(fdd, TIOCSETD, &temp) < 0) {
perror("Can't set line discipline");
return -1;
}
cmd[0] =3D 0x30;//HCILL_GO_TO_SLEEP_IND
len =3D write(fdd, cmd, 1);
printf("write %d byte\n", len);
len =3D read(fdd, cmd, 1);
printf("read %d byte cmd[0] =3D %d\n", len, cmd[0]);
temp =3D N_HCI;
if (ioctl(fdd, TIOCSETD, &temp) < 0) {
perror("Can't set line discipline");
return -1;
}
if (ioctl(fdd, HCIUARTSETPROTO, 0) < 0) {
perror("Can't set device");
return -1;
}
} =20
After step 2, step3 and step 4 run successfully.=20
step 3: hciconfig hci0 up
step 4: hcitool scan
If I change the steps as follows, an error occures in step 4, the error
is "Device is not available". Do you know why? How can I step 4 can run
successfully after step 3?
step 1: hciattach ttyS0 texas
Step 2: hciconfig hci0 up
step 3: write_cmd_to_ttyS0()
step 4: hcitool scan
/*** cmd_scan() ****/
if (dev_id < 0) {
dev_id =3D hci_get_route(NULL);
if (dev_id < 0) {
perror("Device is not available");
exit(1);
}
}
/**********************/
Regards,
David
-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bluez-devel] Re: ttyS0 problem
2005-10-11 6:39 ` [Bluez-devel] ttyS0 problem david
@ 2005-10-11 7:05 ` david
0 siblings, 0 replies; 6+ messages in thread
From: david @ 2005-10-11 7:05 UTC (permalink / raw)
To: bluez-devel
Hi marcel,
=D4=DA 2005-10-11=B6=FE=B5=C4 14:39 +0800=A3=ACdavid=D0=B4=B5=C0=A3=BA
> Hi marcel,
>=20
> =D4=DA 2005-10-11=B6=FE=B5=C4 14:03 +0800=A3=ACdavid=D0=B4=B5=C0=A3=BA
> > Hi David,
>=20
> > > I want to write some commands to the uart(ttyS0), but it fails.
> > > The steps are as follows:
> > > =20
> > > 1. hciattach ttyS0 texas
> > > 2. Open ttyS0 device again and get a fd, init ttyS0 with speed,
> > > flow_ctl and so on,then write a command(0x30) to the fd but return
> > > 0; That is nothing is written to ttyS0.
> > > =20
> > marcel write,=20
> > > > What commands do you wanna send?
> > > The command is HCI_GO_TO_SLEEP_IND(0x30) which is only one byte. It =
is a
> > > vendor specific command used to ask the BT device to go to sleep. If=
BT
> > > device receives the command, maybe it would response
> > > HCILL_GO_TO_SLEEP_ACK(0x31) command to the host.
> > =20
> > do you have the specification of these vendor commands? Is this comman=
d
> > according to the HCI specification or is it an extension of the H:4
> > transport protocol?
> > =20
> > > > after step 1, you must use the HCI raw socket to send commands
> > >=20
> > > Is this means we cannot write command to ttyS0 directly through writ=
e()
> > > function?
> > =20
> > After calling hciattach the kernel takes over the serial port via the
> > line discipline and the reads and writes are useless.
> > =20
> > Regards
> > =20
> > Marcel
>=20
>=20
>=20
> Now, I can write command(0x30) to ttyS0 driectly after hciattach tty0
> texas(assume step 1);
> The function is as follows(assume step 2):
>=20
> static int write_cmd_to_ttyS0()
>=20
> {
> int fdd;
> int len;
> char cmd[5];
> int temp;
> int dd;
> =20
> fdd =3D open("/dev/ttyS0", O_RDWR | O_NOCTTY);
> if (fdd < 0) {
> printf("Can't open serial port, fd =3D %d\n",fdd)=
;
> return -1;
> }
> else
> printf("open serial ok, fd =3D %d\n", fdd);
> =20
> temp =3D 0;
> if (ioctl(fdd, TIOCSETD, &temp) < 0) {
> perror("Can't set line discipline");
> return -1;
> }
>=20
> cmd[0] =3D 0x30;//HCILL_GO_TO_SLEEP_IND
>=20
> len =3D write(fdd, cmd, 1);
> printf("write %d byte\n", len);
> len =3D read(fdd, cmd, 1);
> printf("read %d byte cmd[0] =3D %d\n", len, cmd[0]);
>=20
> temp =3D N_HCI;
> if (ioctl(fdd, TIOCSETD, &temp) < 0) {
> perror("Can't set line discipline");
> return -1;
> }
> if (ioctl(fdd, HCIUARTSETPROTO, 0) < 0) {
> perror("Can't set device");
> return -1;
> }
> } =20
>=20
> After step 2, step3 and step 4 run successfully.=20
>=20
> step 3: hciconfig hci0 up
> step 4: hcitool scan
>=20
> If I change the steps as follows, an error occures in step 4, the error
> is "Device is not available". Do you know why? How can I step 4 can run
> successfully after step 3?
>=20
> step 1: hciattach ttyS0 texas
> Step 2: hciconfig hci0 up
> step 3: write_cmd_to_ttyS0()
> step 4: hcitool scan
>=20
> /*** cmd_scan() ****/
> if (dev_id < 0) {
> dev_id =3D hci_get_route(NULL);
> if (dev_id < 0) {
> perror("Device is not available");
> exit(1);
> }
> }
> /**********************/
>=20
>=20
>=20
>=20
> Regards,
>=20
> David
>=20
I find hci0 is down after step 3. why?
hciconfig -a
hci0: Type: UART
BD Address: 00:00:00:00:00:00 ACL MTU: 0:0 SCO MTU: 0:0
DOWN
RX bytes:5 acl:0 sco:0 events:0 errors:1
TX bytes:0 acl:0 sco:0 commands:0 errors:0
Features: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
Packet type: DM1 DH1 HV1
Link policy:
Link mode: SLAVE ACCEPT
Regards,
David
-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2005-10-11 7:05 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <1129010637.2346.1.camel@localhost.localdomain>
2005-10-11 6:39 ` [Bluez-devel] ttyS0 problem david
2005-10-11 7:05 ` [Bluez-devel] " david
[not found] <1128906830.2417.1.camel@localhost.localdomain>
2005-10-10 1:53 ` [Bluez-devel] " david
2005-10-10 3:19 ` Marcel Holtmann
2005-10-09 16:38 davidgchen
2005-10-09 16:45 ` Marcel Holtmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).