2009-09-14 10:02:03

by Zhenhua Zhang

[permalink] [raw]
Subject: ioctl(RFCOMMCREATEDEV) failed: File descriptor in bad state

RGVhciBhbGwsDQoNCkkgYW0gY2FsbGluZyBpb2N0bChSRkNPTU1DUkVBVEVERVYpIHRvIGNyZWF0
ZSB0dHkgZGV2aWNlIGZyb20gYSByZmNvbW0gZmQgDQp1c2luZyBoYW5kcy1mcmVlIHByb2ZpbGUu
IElmIHRoZSBIRiBzZW5kIGNvbm5lY3Rpb24gcmVxdWVzdCB0byBBRyBhbmQgbWFrZQ0KcmZjb21t
IGNvbm5lY3QsIHRoZSB0dHkgY291bGQgYmUgbWFkZSBzdWNjZXNzZnVsbHkuIEhvd2V2ZXIsIGlm
IHRoZSANCkFHKG1vYmlsZSkgc2lkZSBtYWtlIHJlcXVlc3QgdG8gY3JlYXRlIHJmY29tbSBjb25u
ZWN0aW9uLCB0aGUgcmZjb21tIGNvdWxkDQpiZSBjcmVhdGVkIGJ1dCBmYWlsIHRvIGNyZWF0ZSB0
aGUgdHR5IGRldmljZS4gVGhlIGtlcm5lbCByZXR1cm5zIGVycm9yIA0KYmVjYXVzZSBzb2NrZXQg
aXMgbm90IGNvbm5lY3RlZCwgc2VlIGJlbG93IGNvZGUuIEFueSBpZGVhPyBUaGFua3MgbXVjaCEN
CiANCiAgICAgaWYgKHJlcS5mbGFncyAmICgxIDw8IFJGQ09NTV9SRVVTRV9ETEMpKSB7DQogICAg
ICAgICAgICAgICAvKiBTb2NrZXQgbXVzdCBiZSBjb25uZWN0ZWQgKi8NCiAgICAgICAgICAgICAg
IGlmIChzay0+c2tfc3RhdGUgIT0gQlRfQ09OTkVDVEVEKQ0KICAgICAgICAgICAgICAgICAgICAg
ICAgcmV0dXJuIC1FQkFERkQ7DQogICAgICAgICAgICAgICANCg0KVGhlIHBzZXVkbyBjb2RlIGxv
Z2ljIGxvb2tzIGxpa2UgdGhpczoNCg0Kdm9pZCByZmNvbW1fY29ubmVjdF9jYihHSU9DaGFubmVs
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CWd3LT50dHkgPSBnX3N0cmR1cF9wcmludGYoIi9kZXYvcmZjb21tJWQiLCBpZCk7DQoNCmZhaWxl
ZDoNCglyZXR1cm47DQp9DQoNCnN0YXRpYyB2b2lkIGhmX2lvX2NiKC4uLikNCnsNCglidF9pb19n
ZXQoY2hhbiwgQlRfSU9fUkZDT01NLCAmZXJyLA0KCQkJQlRfSU9fT1BUX1NPVVJDRV9CREFERFIs
ICZzcmMsDQoJCQlCVF9JT19PUFRfREVTVF9CREFERFIsICZkc3QsDQoJCQlCVF9JT19PUFRfQ0hB
Tk5FTCwgJmNoLA0KCQkJQlRfSU9fT1BUX0lOVkFMSUQpOw0KCQ0KCS8vcmVxdWVzdCBhdXRob3Jp
emF0aW9uDQoJaWYgKCFidF9pb19hY2NlcHQoZ3ctPnJmY29tbSwgcmZjb21tX2Nvbm5lY3RfY2Is
IGRldiwgTlVMTCwNCgkJCQkJCQkmZXJyKSkgew0KCQllcnJvcigiYnRfaW9fYWNjZXB0OiAlcyIs
IGVyci0+bWVzc2FnZSk7DQoJCWdfZXJyb3JfZnJlZShlcnIpOwkJDQoJfQ0KDQp9DQoNClJlZ2Fy
ZHMsDQpaaGVuaHVhDQogDQo=


2009-09-14 13:28:20

by Marcel Holtmann

[permalink] [raw]
Subject: RE: ioctl(RFCOMMCREATEDEV) failed: File descriptor in bad state

Hi,

> >> I am calling ioctl(RFCOMMCREATEDEV) to create tty device from a
> >> rfcomm fd using hands-free profile. If the HF send connection
> >> request to AG and make rfcomm connect, the tty could be made
> >> successfully. However, if the AG(mobile) side make request to create
> >> rfcomm connection, the rfcomm could be created but fail to create
> >> the tty device. The kernel returns error because socket is not
> >> connected, see below code. Any idea? Thanks much!
> >
> > why do you wanna create the TTY in the first place? Going via the TTY
> > layer is pretty bad idea. Don't even think about doing that. Use the
> > RFCOMM socket.
>
> I want to create TTY and expose it to Ofono as /dev/rfcomm0. Ofono side
> could treat bluetooth connection as a TTY device, and create
> GAtChat *chat by using g_at_chat_new_from_tty(tty, syntax).

and that is just wrong to begin with. Write an oFono plugin that uses
Bluetooth RFCOMM sockets directly. I really don't understand why you
wanna make your life so complicated. Within oFono you have to do a
non-blocking RFCOMM connect() anyway using GIOChannel. And once you have
the GIOChannel you can just hand it to g_at_chat_new(). Plain and
simple. Just extend modemconf.c to support a "bluetooth" driver and then
you can even configure address and channel.

Regards

Marcel



2009-09-14 11:38:57

by Zhenhua Zhang

[permalink] [raw]
Subject: RE: ioctl(RFCOMMCREATEDEV) failed: File descriptor in bad state

Hi Marcel,

Marcel Holtmann wrote:
> Hi,
>
>> I am calling ioctl(RFCOMMCREATEDEV) to create tty device from a
>> rfcomm fd using hands-free profile. If the HF send connection
>> request to AG and make rfcomm connect, the tty could be made
>> successfully. However, if the AG(mobile) side make request to create
>> rfcomm connection, the rfcomm could be created but fail to create
>> the tty device. The kernel returns error because socket is not
>> connected, see below code. Any idea? Thanks much!
>
> why do you wanna create the TTY in the first place? Going via the TTY
> layer is pretty bad idea. Don't even think about doing that. Use the
> RFCOMM socket.
>
> Regards
>
> Marcel

I want to create TTY and expose it to Ofono as /dev/rfcomm0. Ofono side
could treat bluetooth connection as a TTY device, and create
GAtChat *chat by using g_at_chat_new_from_tty(tty, syntax).

Regards,
Zhenhua

2009-09-14 11:01:48

by Marcel Holtmann

[permalink] [raw]
Subject: Re: ioctl(RFCOMMCREATEDEV) failed: File descriptor in bad state

Hi,

> I am calling ioctl(RFCOMMCREATEDEV) to create tty device from a rfcomm fd
> using hands-free profile. If the HF send connection request to AG and make
> rfcomm connect, the tty could be made successfully. However, if the
> AG(mobile) side make request to create rfcomm connection, the rfcomm could
> be created but fail to create the tty device. The kernel returns error
> because socket is not connected, see below code. Any idea? Thanks much!

why do you wanna create the TTY in the first place? Going via the TTY
layer is pretty bad idea. Don't even think about doing that. Use the
RFCOMM socket.

Regards

Marcel