AferoCE / beetle

Afero Bluetooth daemon
MIT License
0 stars 0 forks source link

"con" command flow #5

Open Peter-Lin opened 6 years ago

Peter-Lin commented 6 years ago

Hi I change the source code from bluez to bluedroid on system1(arm device),and system2 is still bluez(ubuntu notebook).

My steps is follow: 1: On system1, launch beetle with the command line: sudo beetle -m per 2. On system2, , launch beetle with the command line: sudo beetle -m cen 3. On the system1 system, connect to beetle with the command: telnet localhost 6969 4. On the system2 system, connect to beetle with the command: telnet localhost 6969 5. On system1, start sending advertising packets over BLE with the command: pad 0006 03c0 d202010123456789abcdef01 6. On system2I can see the advertising packets: adv 7b:e9:3e:41:f1:cc d202010123456789abcdef01 -83 7. Quit telnet session on system2 and restart another telnet session telnet localhost 6969 | grep -v "^adv" 8. On system2, connect to the MAC address of the system1's con 7b:e9:3e:41:f1:cc

Error: I will see the STATUS_TIMED_OUT con 7b:e9:3e:41:f1:cc 0009 0000 Question: Could you tell me if system2 do the command "con" system1 have do anything in the source code and the code flow?? Could you give me some idea to debug this issue? thanks

Daniel

Peter-Lin commented 6 years ago

Hi

I try the same steps on the two ubuntu notebook(beetle is bluez) will get the same STATUS_TIMED_OUT result con 20:68:9d:2d:5d:96 0009 0000

Daniel

Peter-Lin commented 6 years ago

Hi I can see con 4b:3c:81:ac:95:36 con 4b:3c:81:ac:95:36 0000 0007 dis 0007 0000 0013

Do you know what is the reason 0013? Where can I get the reason code? Thanks~

Daniel

clifliu commented 6 years ago

Hi Daniel,

The reason code is in the Bluetooth Specification. In the 5.0 spec it's on page 648.

2.19 Remote User Terminated Connection

The Remote User Terminated Connection error code indicates that the user on the remote device terminated the connection.

Let me reproduce your issue and get back to you. Clif

On Oct 12, 2017, at 3:13 AM, Peter-Lin notifications@github.com wrote:

Hi I can see con 4b:3c:81:ac:95:36 con 4b:3c:81:ac:95:36 0000 0007 dis 0007 0000 0013

Do you know what is the reason 0013? Where can I get the reason code? Thanks~

Daniel

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/AferoCE/beetle/issues/5#issuecomment-336084782, or mute the thread https://github.com/notifications/unsubscribe-auth/AJpulvMvfpPmjTaeeiT7ryTnMfgnDo7kks5sreZRgaJpZM4P2lKc.

clifliu commented 6 years ago

Hi Peter,

I was able to reproduce your issue. It appears that if you use an iogear dongle, the peripheral mode doesn't work correctly.

I recommend that you use a Raspberry Pi 3 (the one with the built-in Bluetooth and Wi-Fi) together with Raspbian. We should be able to build a copy of the latest beetle that runs under Raspbian. Joe George can help you with that.

Clif

On Oct 12, 2017, at 11:33 AM, Clif Liu clif@kiban.io wrote:

Hi Daniel,

The reason code is in the Bluetooth Specification. In the 5.0 spec it's on page 648.

2.19 Remote User Terminated Connection

The Remote User Terminated Connection error code indicates that the user on the remote device terminated the connection.

Let me reproduce your issue and get back to you. Clif

On Oct 12, 2017, at 3:13 AM, Peter-Lin <notifications@github.com mailto:notifications@github.com> wrote:

Hi I can see con 4b:3c:81:ac:95:36 con 4b:3c:81:ac:95:36 0000 0007 dis 0007 0000 0013

Do you know what is the reason 0013? Where can I get the reason code? Thanks~

Daniel

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/AferoCE/beetle/issues/5#issuecomment-336084782, or mute the thread https://github.com/notifications/unsubscribe-auth/AJpulvMvfpPmjTaeeiT7ryTnMfgnDo7kks5sreZRgaJpZM4P2lKc.

afjgeorge commented 6 years ago

Hey Daniel,

Can you try the steps below but reversing the roles of the systems? Use your bluedroid port as the central host and the other one as the peripheral host. That will help us figure out if the issue you’re seeing is a beetle issue or something with the BT chipset.

Thanks!

Joe

On Oct 12, 2017, at 12:29 AM, Peter-Lin notifications@github.com wrote:

Hi I change the source code from bluez to bluedroid on system1(arm device),and system2 is still bluez(ubuntu notebook).

My steps is follow: 1: On system1, launch beetle with the command line: sudo beetle -m per 2. On system2, , launch beetle with the command line: sudo beetle -m cen 3. On the system1 system, connect to beetle with the command: telnet localhost 6969 4. On the system2 system, connect to beetle with the command: telnet localhost 6969 5. On system1, start sending advertising packets over BLE with the command: pad 0006 03c0 d202010123456789abcdef01 6. On system2I can see the advertising packets: adv 7b:e9:3e:41:f1:cc d202010123456789abcdef01 -83 7. Quit telnet session on system2 and restart another telnet session telnet localhost 6969 | grep -v "^adv" 8. On system2, connect to the MAC address of the system1's con 7b:e9:3e:41:f1:cc

Error: I will see the STATUS_TIMED_OUT con 7b:e9:3e:41:f1:cc 0009 0000 Question: Could you tell me if system2 do the command "con" system1 have do anything in the source code and the code flow?? Could you give me some idea to debug this issue? thanks

Daniel

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/AferoCE/beetle/issues/5, or mute the thread https://github.com/notifications/unsubscribe-auth/AQB98mOTyhfWqjLPaILnnBvETdPKbjs0ks5srb_wgaJpZM4P2lKc.

Peter-Lin commented 6 years ago

Hi Joe I had ported the peripheral mode cmd_per_advertisement now, the others is on going. Now I am trying to do the "con" command test following the connectiontest.md. I can connect to the MAC address by the command: con 4b:3c:81:ac:95:36 and can see the response con 4b:3c:81:ac:95:36 0000 0007 but I will get the response after about 1 mins dis 0007 0000 0013

I doubt that I port peripheral mode something wrong. Do you have any suggesting?

About porting beetle sequence, I port peripheral mode firstly and follow the connectiontest.md to do test and find out errors and debug. Do you have any suggestions about the sequence?

My bluedroid beetle can not run in Raspberry Pi 3, because my bluedroid beetle is base on Qualcomm Gatt interface.

thanks

Daniel

clifliu commented 6 years ago

Hi Daniel,

I think that if you can keep the connection open for a minute with no activity you're fine. Hubby will shut down the connection after 14 seconds of no activity so you should be fine.

Your approach to porting is a good one. This is what we do.

You can run the developer version of beetle on Raspberry Pi 3 if you need a central. Joe can provide you with a link where you can download the Debian package.

Clif

On Oct 12, 2017, at 6:52 PM, Peter-Lin notifications@github.com wrote:

Hi Joe I had ported the peripheral mode cmd_per_advertisement now, the others is on going. Now I am trying to do the "con" command test following the connectiontest.md. I can connect to the MAC address by the command: con 4b:3c:81:ac:95:36 and can see the response con 4b:3c:81:ac:95:36 0000 0007 but I will get the response after about 1 mins dis 0007 0000 0013

I doubt that I port peripheral mode something wrong. Do you have any suggesting?

About porting beetle sequence, I port peripheral mode firstly and follow the connectiontest.md to do test and find out errors and debug. Do you have any suggestions about the sequence?

My bluedroid beetle can not run in Raspberry Pi 3, because my bluedroid beetle is base on Qualcomm Gatt interface.

thanks

Daniel

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/AferoCE/beetle/issues/5#issuecomment-336328218, or mute the thread https://github.com/notifications/unsubscribe-auth/AJpullTYBLhHS8SNCyn_ldYFttfZv0fcks5srsJGgaJpZM4P2lKc.

afjgeorge commented 6 years ago

Hi Daniel,

I've uploaded a copy of the Raspberry Pi3 beetle utility for you. This is an internal version I'm working on and not the public developer release, so please don't distribute it outside of Wistron. You should be able to install this on a Pi3 and use it for beetle testing per Clif's recommendation. If you need any assistance installing it please let me know. There are a few prerequisite packages but they're commonly available through apt-get.

afero-ble_1.0.366-1_armhf.deb.zip

My recommendation to swap central and peripheral mode hosts was under the assumption that you had ported central mode code already, if you're working on that now then my apologies, we'll have to try that when you finish your porting effort. :)

Thank you,

Joe

Peter-Lin commented 6 years ago

Hi Hubby will shut down the connection after 14 seconds of no activity so you should be fine<=I test the the time that it is about 15 seconds. But I only run beetle and don't enable hubby. Is it cause by beetle cen mode? Could I change the time from 14 seconds to 60 seconds to verify this issue? Could you tell me how to modify it?

evloop_on_read(&ev, context.listen_fd, handle_listener_read, &context);<=But I don't have the context.listen_fd,so I fill NULL to the fd evloop_on_read(&ev, NULL, handle_listener_read, &context); I found that "handle_listener_read" will not run. Do you have any suggestions?

Thanks

Daniel

afjgeorge commented 6 years ago

Hi Daniel,

In central.c, there is a connect timeout defined for 11 seconds:

central.c:#define CONNECT_TIMEOUT 11

This is used in: static void check_connect_timeout(conn_info_t ci, void arg)

I’m not sure where the extra delay in connection is offhand, I haven’t looked in the code too much. But I think if you were to increase this CONNECT_TIMEOUT value you should be able to extend the timeout you’re seeing so you can test your issue.

Thank you,

Joe

On Oct 16, 2017, at 4:30 AM, Peter-Lin notifications@github.com wrote:

Hi Hubby will shut down the connection after 14 seconds of no activity so you should be fine<=I test the the time that it is about 15 seconds. But I only run beetle and don't enable hubby. Is it cause by beetle cen mode? Could I change the time from 14 seconds to 60 seconds to verify this issue? Could you tell me how to modify it?

evloop_on_read(&ev, context.listen_fd, handle_listener_read, &context);<=But I don't have the context.listen_fd,so I fill NULL to the fd evloop_on_read(&ev, NULL, handle_listener_read, &context); I found that "handle_listener_read" will not run. Do you have any suggestions?

Thanks

Daniel

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/AferoCE/beetle/issues/5#issuecomment-336859366, or mute the thread https://github.com/notifications/unsubscribe-auth/AQB98iRLJrDT1UeEIQ7mMOvbeaKfjI7Mks5ssz5agaJpZM4P2lKc.

Peter-Lin commented 6 years ago

Hi Joe

I change the value "central.c:#define CONNECT_TIMEOUT 11" the connect is still disabled about 15 seconds.

Daniel

afjgeorge commented 6 years ago

Hi Daniel,

I chatted with Clif and he said that beetle actually does NOT ever time out connection attempts. It may be something in the Bluedroid stack thats timing out your connections.

We’d like to see if we can replicate your issue here. Would it be okay if we set up a shared private github repo for you and us to look at your code and see if we can help?

If not, do you mind sharing a current binary for the DB2.1 board at least?

Thank you!

Joe

On Oct 20, 2017, at 12:37 AM, Peter-Lin notifications@github.com wrote:

Hi Joe

I change the value "central.c:#define CONNECT_TIMEOUT 11" the connect is still disabled about 15 seconds.

Daniel

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/AferoCE/beetle/issues/5#issuecomment-338129668, or mute the thread https://github.com/notifications/unsubscribe-auth/AQB98hsdBbZUyx5wcquBdQmwZu0rUJ4Bks5suE2egaJpZM4P2lKc.

Peter-Lin commented 6 years ago

Hi Joe I try to connect by the command con 65:d6:72:1a:c8:34 and get the response: con 65:d6:72:1a:c8:34 0009 0000

I check the log: (handle_hci_read) evt_cmd_complete 01 200e (handle_hci_read) LE_CONNECT: addr=00:00:00:00:00:00 handle=0 handle_connect addr = 00:00:00:00:00:00 no such device 00:00:00:00:00:00

Why the address is 00:00:00:00:00:00? Could I avoid this issue? Thanks.

Daniel

afjgeorge commented 6 years ago

Daniel,

So I’m clear, which one of these systems is your bluedroid version? The one receiving the connection, correct? Can you share any code or binary with us?

The message you’re seeing is coming from hci_beetle.c from bhci_read(bhci_t *bhci). Your file handle and BT address are both zero, which you should never see. It’s extracted from the “data” buffer used in that method, which has to be at least partially valid because part of that data buffer is used to get you to the section of code you’re getting to. Can you maybe try to dump the evt_le_connection_complete buffer in that code section, or maybe the bhci_t buffer passed to bhci_read() to begin with? If it’s all zeroes at that point we can work backwards to see how that buffer’s getting written before getting passed to this code.

This would be a lot easier to look into if we had some code to review. Can you share any code or binary with us?

Thanks,

Joe

On Oct 23, 2017, at 3:45 AM, Peter-Lin notifications@github.com wrote:

Hi Joe I try to connect by the command con 65:d6:72:1a:c8:34 and get the response: con 65:d6:72:1a:c8:34 0009 0000

I check the log: (handle_hci_read) evt_cmd_complete 01 200e (handle_hci_read) LE_CONNECT: addr=00:00:00:00:00:00 handle=0 handle_connect addr = 00:00:00:00:00:00 no such device 00:00:00:00:00:00

Why the address is 00:00:00:00:00:00? Could I avoid this issue? Thanks.

Daniel

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/AferoCE/beetle/issues/5#issuecomment-338620303, or mute the thread https://github.com/notifications/unsubscribe-auth/AQB98lfRBh7IsN6Pxgma1X9Ed7oSTrjuks5svG49gaJpZM4P2lKc.

Peter-Lin commented 6 years ago

Hi Joe

I get the address 00:00:00:00:00:00 in the test environment. Notebook is bluez central(I add debug message), DB2.1 is the bluedroid peripheral. When in the open environment, I will get the address 00:00:00:00:00:00 easily. But in the shielding room, the frequency is not always happen.

Maybe I can give you the code which I add debug message bluez beetle, but I am sorry that I can't give you the bluedroid beetle before my boss agree

Daniel

afjgeorge commented 6 years ago

Hi Daniel,

You’re seeing a valid BT address being advertised by the bluedroid beetle in peripheral mode, correct?

Then when you connect to it from the bluez beetle, you see LE_CONNECT 00:00:00:00:00:00 in the bluedroid side?

Do you think you could share a binary of your bluedroid beetle application so we can see if we can duplicate this?

Joe

On Oct 23, 2017, at 6:59 PM, Peter-Lin notifications@github.com wrote:

Hi Joe

I get the address 00:00:00:00:00:00 in the test environment. Notebook is bluez central(I add debug message), DB2.1 is the bluedroid peripheral. When in the open environment, I will get the address 00:00:00:00:00:00 easily. But in the shielding room, the frequency is not always happen.

Maybe I can give you the code which I add debug message bluez beetle, but I am sorry that I can't give you the bluedroid beetle before my boss agree

Daniel

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/AferoCE/beetle/issues/5#issuecomment-338848709, or mute the thread https://github.com/notifications/unsubscribe-auth/AQB98jqqscNTQI9Y2RxoVfiJLH5hUcBHks5svUSQgaJpZM4P2lKc.

Peter-Lin commented 6 years ago

Hi Joe

When I run the command "kat 7" on the central side. I will get the uuid 0x2803 not 0x2800 on the peripheral side. Is it correct? thanks~

Daniel

clifliu commented 6 years ago

Yes this is correct. The babygatt_central stack does a Read By Type Request for GATT Characteristics (0x2803) not services (0x2800).

Peter-Lin commented 6 years ago

Hi The function "add_attribute" in the babygatt_peripheral.c is similar to add characteristic or descriptor in the gatt stack? thanks~ Daniel

clifliu commented 6 years ago

That's correct. We do a dirty trick and only keep the significant part of the UUID, which is only 16 bits, rather than keeping the entire UUID in the attribute structure (struct gap_entry).

Clif

On Nov 6, 2017, at 12:01 AM, Peter-Lin notifications@github.com wrote:

Hi The function "add_attribute" in the babygatt_peripheral.c is similar to add characteristic or descriptor in the gatt stack? thanks~ Daniel

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/AferoCE/beetle/issues/5#issuecomment-342072775, or mute the thread https://github.com/notifications/unsubscribe-auth/AJpuluICl-dhY0IpaK9A4pI3M24hDrRGks5szrz3gaJpZM4P2lKc.

Peter-Lin commented 6 years ago

Hi

Run command "kat 7" on central device, my BLUEDROID peripheral device will not receive data. 1. Is the behavor correct that my BLUEDROID peripheral device can not receive data? 2. Does my BLUEDROID peripheral device have to parser the command which receives from central device send? 3. What should my BLUEDROID peripheral device do after running command "kat 7" on central device?

thanks~

Daniel

clifliu commented 6 years ago

Hi Daniel,

No you should see something on the peripheral side. Specifically executing kat 7 should send a Read by Type request (OP=0x08) with a start of 1 and end of 0xffff. The stream should look like 0x08 0x01 0x00 0xff 0xff 0x03 0x28.

On the peripheral side you should see this debug message:

DEBUG("read_by_type start=%d end=%d uuid=%d", start, end, uuid);

and the per_do_read_by_type function should execute.

Clif

On Nov 7, 2017, at 6:16 PM, Peter-Lin notifications@github.com wrote:

Hi

Run command "kat 7" on central device, my BLUEDROID peripheral device will not receive data. 1. Is the behavor correct that my BLUEDROID peripheral device can not receive data? 2. Does my BLUEDROID peripheral device have to parser the command which receives from central device send? 3. What should my BLUEDROID peripheral device do after running command "kat 7" on central device?

thanks~

Daniel

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/AferoCE/beetle/issues/5#issuecomment-342688281, or mute the thread https://github.com/notifications/unsubscribe-auth/AJpulj81ZyH3r4mGOylPIoCm6LPNhT5Oks5s0Q8NgaJpZM4P2lKc.

tastybento commented 6 years ago

@Peter-Lin - Hi Daniel - did this work okay for you?

Peter-Lin commented 6 years ago

Hi I can get the message and data in the bluedroid level. But I can't get the data in the bluedroid peripheral beetle.

Daniel

afjgeorge commented 6 years ago

@Peter-Lin Hello Daniel,

We've had a big Thanksgiving holiday in the US and I've been out of the office a few days. How are you doing? Can we assist in any way?

Joe