melianmiko / OpenFreebuds

Open source app for HUAWEI FreeBuds (Linux + Windows)
https://mmk.pw/en/openfreebuds/
GNU General Public License v3.0
90 stars 8 forks source link

Possible FreeBuddy collaboration #9

Closed TheLastGimbus closed 1 year ago

TheLastGimbus commented 1 year ago

Hi @melianmiko :wave:

I've written a mail to you, but I think something with our mail servers broken :thinking:

I am also making an app for FreeBuds (and possibly more!) - it's currently mobile-centered, but i would love to also have desktop support! It's made in Dart/Flutter :bird:

If you want, we could exchange knowlage about the protocol, or making a desktop plugin for bluetooth

Cheers, happy new year :beers:

melianmiko commented 1 year ago

Hi @TheLastGimbus,

Don't worry, I saw your mail, but didn't respond because there was no time.

Your work is cool, but I don't know Dart/Flutter, so can't help. I think to make a native Android implementation of OpenFreebuds written in Java, but for now it's just a plan.

I've seen that you need a library to access Bluetooth on PC from Dart, but all interfaces for them should be written in C/C++ due to the need to access the win32/bluez API. I don't have those skills, so I just use PyBluez library. It's development is stopped, but for now, they work.

So sorry, I can't help with your troubles. Maybe later I'll make a reference manual for HUAWEI FreeBuds SPP protocol and commands.

Sorry for any mistakes in this post, my knowledge of english is far from perfect.

Happy new year too =)

TheLastGimbus commented 1 year ago

Oh don't worry, I don't need that much :sweat_smile:

but I don't know Dart/Flutter, so can't help

Duude, writning code is 5% of the work... messing with win32, api documentations, which damn method to call etc is reason i don't sleep at night

For example, I've already spent ~12h looking how to connect to SPP/RFCOMM on linux... only thing i know is that rfcomm command is deprecated :clown_face: - if you could just point me to some nice websites/docuentations/apis on how to use bluez/whatever, i would be super grateful

I think to make a native Android implementation of OpenFreebuds written in Java, but for now it's just a plan.

If you want to level up your java them go, otherwise there's no need to, because FreeBuddy is already working pretty nice on Andorid: https://play.google.com/store/apps/details?id=com.lastgimbus.the.freebuddy - now it's just polishing, widgets, etc - if you had any suggestions what kind of stuff you'll like (home widget with modes/battery), hit me up!

all interfaces for them should be written in C/C++ due to the need to access the win32/bluez API

Dart has an FFI to C :+1: - it's not most pleasurable thing to do, but if i just know what functions i need to use, it would be a pice of cake (for bluez, there's even already a package)

PyBluez library. It's development is stopped

Oh, yeah, i've seen it, decided that I'll pass since it's deprecated, and moved on. But it may be the only good way for now as you say... I've seen that Home Assistant (also in Python) made some big bluetooth migrations, but they may be BLE-only... :roll_eyes:

Maybe later I'll make a reference manual for HUAWEI FreeBuds SPP protocol

I did! You can see it here: https://github.com/TheLastGimbus/FreeBuddy/blob/master/notes/mbb-protocol-wiki.md

I document everythink I find to not forget :sweat_smile: but i've seen you have some more functions (like language change!) that missed - you can have some from mine (i guess you had a problem with checksums?), and you could tell me what i missed :rainbow:

So sorry, I can't help with your troubles

If by all of that you just mean that you don't have any time for any of this, that cool :ice_cube: but if you worried about code - don't because that's not what i need :+1:

Sorry for any mistakes in this post,

0 worries, slavic greetings from Poland :poland:

melianmiko commented 1 year ago

if you could just point me to some nice websites/docuentations/apis on how to use bluez/whatever, i would be super grateful

Sorry, I don't have them. Obly thing that I found is an PyBluez DBus API, which I use to connect a headset in Linux. Windows isn't my main OS, and I didn't have any good skills in their APIs...

If you want to level up your java

Nope, it isn't my main coding language so I don't have any reason to level up that skill.

now it's just polishing, widgets, etc - if you had any suggestions what kind of stuff you'll like (home widget with modes/battery), hit me up!

I didn't checked them for now, I'll do that a bit later. For myself, I use "Audio Assistant", a Chinese-only app fron huawei. It works faster than AI Life, but anyway is laggy. Adding an Android widget is a good idea, some guy on 4PDA (russian IT forum) asked me about that.

I've seen that Home Assistant (also in Python) made some big bluetooth migrations, but they may be BLE-only

I also saw that, and also found a couple of BLE libraries for Python, but for our projects they are useless. The only thing that I use from PyBluez is SDP (Service Discover Protocol), which checks that SPP service exists and gives their port number. The same way that Android app does, just for compatibility. Bluetooth RFCOMM is supported in python out-of-box. It looks like the usage of Bluetooth on PC in that way isn't popular, and because of that we have so many problems with libraries.

like language change

Yep, I found this feature via reverse-engineering huawei's android app.

i guess you had a problem with checksums?

This is true, in the official app there's the same algorithm that you can see in my code. Later I'll try your solution, and give you Information about features, like language change. I want to make a big blog post on my website about that protocol.

For now, I'm working on my website. The current version is running via Hugo SSG, and the code is very very bad, so I rewrote it from scratch, to make them work above Django. As soon as I finish that work (and fix some small bugs in other projects), I'll begin making documentation for OpenFreebuda and other projects.

melianmiko commented 1 year ago

Ready, here's all what I found: https://melianmiko.ru/en/posts/freebuds-4i-proto/

TheLastGimbus commented 1 year ago

Holy shit, this is good *jawdrop* :open_mouth: - will read it all through soon - in mean time, one big question stands - how did you manage to rev eng it so well - did you just decompile the app with some really good decompiler, watched the logs / wireshark, or what? Would be interested to read about this too

In general - how did you get such rev eng experience? Is it just slow progress tinkering with Mi Bands (as i've seen on your repos) or did you attend/found some course on youtube? I'm interested...

Another small question - why MDN ? When i was decompiling/reading logs, the MBB name was everywhere... :thinking:

melianmiko commented 1 year ago

MDN

I remember that name... Maybe it's my mistake, I'll check later.

Reg eng

Yep, I decompile Audio assistant Android app, which I found on our 4PDA forum. To do that I use apktool (it unpack dex into smali files) and jadx (it partially reconstruct java code from smali). Fun fact: in that build of APK (if need, I can give a link), all class, variable names was kept, so I got mostly readable java code =)

Checksum algorithm I just rewritten from their code as-is. Also I use some data from logcat, but mostly it's useless. Catch command IDs and parameters from Java code become easier and faster.

how did you get such rev eng experience? Is it just slow progress tinkering with Mi Bands (as i've seen on your repos) or did you attend/found some course on youtube?

No, this experience isn't related with Mi Bands, because I didn't reverse their apps =) Est 5-6 years ago I was engaged into Android app & firmware modification, and from that I have some basic knowledge about "exploring" android apps.

But OpenFreebuds is my first really big deal in that, because modification of apps didn't require too much skill of reversing.


Sorry for second comment with mostly the same content, looks like it's GitHub android app bug. They created new comment instead of editing exiting, idk why =)

TheLastGimbus commented 1 year ago

Audio assistant Android app

Never heard of that - can you send me a link? Who are those guys...

I got mostly readable java code =)

The dream 🤤

Also I use some data from logcat, but mostly it's useless

Check out the official AI app, it spits out a lot. I also created a python script to filter it: https://github.com/TheLastGimbus/FreeBuddy/blob/master/notes/live_print_data.py

You use it like: $ adb logcat | python live_print_data.py

OpenFreebuds is my first

Great job honestly, it will help me a lot!

melianmiko commented 1 year ago

Hi, sorry for waiting.

I found that app on 4PDA forum. But, due to need to register and solve Russian captcha, you'll have some troubles getting it from there, so I uploaded it here for you.

I don't know where author of that post found this app, because Google don't know it, but, it works =)

TheLastGimbus commented 1 year ago

thanks!!

after translating this forum i see:

After the ears are determined, go to "Updates", find the firmware file and wait for the update to finish (the firmware will start immediately, without warning)

Um... are these guys making custom firmware for these ??

Wow, browsing this forum is fun! Looking further, looks like audio assistant it also available on desktop... to me, this seems like some external app that huawei made for china/other markets for some reason :shrug:

melianmiko commented 1 year ago

Um... are these guys making custom firmware for these ??

No, they just use this tool to install newer/older official builds. Some people think that in older firmwares noise cancellation works better ¯⁠\⁠⁠(⁠ツ⁠)⁠⁠/⁠¯

to me, this seems like some external app that huawei made for china/other markets for some reason 🤷

Me too, but I don't find it in AppGallery, where it should be, I think...

TheLastGimbus commented 1 year ago

Small question - can cite your notes/images in my notes (while indicating that it's yours of course) ?

melianmiko commented 1 year ago

Small question - can cite your notes/images in my notes (while indicating that it's yours of course) ?

Yes, of course.