[Protocol Request] [Manual Remote Add] Linear Garage Door Remotes

My pleasure, just trying to share my findings and knowledge to everyone as we journey through discovering our world via the Flipper!

And yes, cars are a whole different beast, especially if you don’t have fancy dealer tools. Pro tip on the cars: on many you can resync a known remote to a car by sticking the key in the ignition, turning it to “On” (but not start) and the holding the lock or unlock button until you here a beep, see an indicator on the dash, or here the locks actuate. I may have accidentally desynced my girlfriend’s car key playing with my Flipper which necessitated my learning of this process :slight_smile:

3 Likes

LOL, I’ve seen a lot of people do that and ask how to fix it. I’m thinking about trying to acquire a few of the chips they put in the cars and the fobs for research. I believe I could even make a Flipper add on board that would allow it to be used as a key fob. I would prefer to implement everything in code without an additional board but I’m not sure if I have the skill to do that.

If you do ever figure that out, I would love to hear about it and how to do it myself! Being able to use the Flipper Zero as a backup car key would be awesome! I know the devs are hesitant to add support for car key protocols since they can be used for illegal purposes, but I don’t see the risk of adding it only in a way where we can program our keys to a car the same way factory keys get programmed.

As for acquiring the chips I hope that’s possible. If you can use programmed chips for your purposes, you could buy some replacement fobs from ebay, but I wouldn’t be surprised if the manufacturers of the chips lock down who can purchase them.

1 Like

There is no illegal application for what I’m researching that you couldn’t accomplish easier with a legitimate key fob so there are no moral quandaries. If I have to I can pull the chips from old broken fobs. I only need a few.

1 Like

I came across your post yesterday and though it’d be fun to revers engineer the protocol from scratch just for fun. Since I have lots of different models of Linear transmitters and receivers lying around.

I’m sure someone has done this already. But I just wanted to post this for others that maybe interested in the protocol.

I’m sure someone will read this and disagree with the formula I came up with. Or the processes I used to come up with it. But it seams to work properly.

I don’t know much about coding. But I kind of hope maybe someone finds my formula useful. Or maybe able to use it some how implement a way to selectively manually add remotes directly on the flipper based on decimal numbers for facility code, transmitter, and button

This may be helpful if someone needs to generate a key without internet access as well as understand how a Linear MegaCode key can be generated.

How to use Google Sheet to automate the calculations and conversion of Linear MegaCode to hex.

01] Copy the formula into any cell other than A3 or B3 or C3. (e.g. D3)
	
	=DEC2HEX((SUM(B3*8)+8388608)+(A3*524288)+C3)

02] Then enter a facility code into cell A3. (e.g.3)
03] Then enter a transmitter number into cell B3. (e.g.17316).
04] Then enter a button number into cell C3 (default button number for a single button remote is 2
05] If configured correctly 9A1D22 should be displayed in cell D3
06] Done -- make or edit file using the generated key 9A1D22

---->
Filetype: Flipper SubGhz Key File
Version: 1
Frequency: 318000000
Preset: FuriHalSubGhzPresetOok650Async
Protocol: MegaCode
Bit: 24
Key: 00 00 00 00 00 9A 1D 22
---->
=DEC2HEX((SUM([Transmitter number]*8)+8388608)+([Facility code]*524288)+[Button number])

Manually calculate

(e.g 1) a transmitter with the number 17316 and a facility code 3 Button 2.

01] To convert Facility number to hex use formula (math in DEC)---->  (( 17316 * 8 ) + 128 ) = 152
02] To convert transmitter number to hex use formula (math in DEC)-->  (( 17316 * 8 ) + 2 ) = 138530
03] Now convert the facility number 152 from step one to HEX. You should get -------> 98
04] Now convert the transmitter number 138530 from step two to HEX. You should get --> 21D22
05] Now when the two numbers are combined we see ---> 98 21D22 that's sevin digits. But six is needed.
06] So to shrink sevin digits down to six. Take the last digit of the facility code (8) and first digit of transmitter (2) and add them together (remember this math is HEX)--> 8 + 2 = A
07] Now take the number generated in step six and replace the last digit of the facility number (remember this is HEX)---> 9A
08] Now append the leftover digits of card number (this is HEX) --> 9A 1D 22
09] To complete the key, append ten zeros before the number generated. Make sure there is a space after every two digits. --->   00 00 00 00 00 9A 1D 22
10] Done - create or modify file 

Note: If card and facility are less than 6 then fill the digit between facility code and transmiter code with 0’s
(e.g Transmitter 1, Facility 0, Button 2 = 80A. 80 is the facility A is the transmitter. So to correct it, it would be 80 00 0A

Optional:
If a button other than 2 is desired the last digit can be changed by adding or subtracting the list digit. (0-7) (Two is factory default for single button transmitters)

B1] To change button to 1 subtract 1 from the last digit (this is HEX)  ---> 00 00 00 00 00 9A 1D 21
B2] To change button to 2 leave the last digit alone (this is HEX)  -------> 00 00 00 00 00 9A 1D 22
B3] To change button to 3 add 1 to the last digit (this is HEX) -----------> 00 00 00 00 00 9A 1D 23
B4] To change button to 4 add 2 to the last digit (this is HEX) -----------> 00 00 00 00 00 9A 1D 24
B5] To change button to 5 add 3 to the last digit (this is HEX) -----------> 00 00 00 00 00 9A 1D 25
B6] To change button to 6 add 4 to the last digit (this is HEX) -----------> 00 00 00 00 00 9A 1D 26
B7] To change button to 7 add 5 to the last digit (this is HEX) -----------> 00 00 00 00 00 9A 1D 27
1 Like

What does this mean? I’m trying a python implementation.

If a button other than 2 is desired the last digit can be changed by adding or subtracting the list digit.

What’s a "list digit?

(0-7) (Two is factory default for single button transmitters)

Here is a quick implementation in python

# Python implementation 2023 jmr based on the work of Justin_T
# Inspired by AdvJosh and his research
# Linear garage door remotes calculator
# We would love to see it ported to the Flipper
# Fill out the following variables
# Enter a facility code
fc = 3
# Enter a transmitter number. (e.g.17316).
tn = 17316
# Enter a button number (0-7) (default button number for a single button remote is 2
bn = 2
# Leave this alone unless you need a different frequency
# in mHz
frequency = 318


# DON"T TOUCH ANYTHING BELOW
frequency = frequency * 1000000


# If a button other than 2 is desired the last digit can be changed by adding or subtracting the list digit.


# Filetype: Flipper SubGhz Key File
# Version: 1
# Frequency: 318000000
# Preset: FuriHalSubGhzPresetOok650Async
# Protocol: MegaCode
# Bit: 24
# Key: 00 00 00 00 00 9A 1D 22

# Original formula
# =DEC2HEX((SUM(B3*8)+8388608)+(A3*524288)+C3)


dec2hex = (((tn*8)+8388608)+(fc*524288)+bn).to_bytes(8, "big").hex(" ").upper()

print("Filetype: Flipper SubGhz Key File")
print("Version: 1")
print("Frequency: " + str(frequency))
print("Preset: FuriHalSubGhzPresetOok650Asyn")
print("Protocol: MegaCode")
print("Bit: 24")
print("Key: " + str(dec2hex))
1 Like

the last digit to the hex value. So in the example I used 9A 1D 22.

9A 1D 21 = button 1
9A 1D 22 = button 2
9A 1D 23 = button 3
9A 1D 24 = button 4
9A 1D 25 = button 5
etc.

1 Like

That make sense. The code seems to do that just fine. From what you wrote I believe the options are 0-7. The equation seems pretty simple to emulate programmatically. It also sounded like this might work with more then just garage doors. I need to get back into C programming so I can create Flipper apps. Great work figuring this out!

That’s Awesome!

I ran your code and tried 15 of so different Tr , Fc, button combinations and its printing out properly for mimicking all the handheld Linear MegaCode transmitters available on the market that I know of.

One thing I noticed I didn’t take into consideration with the formula is the boundaries needed for this formula to also mimic the Linear MegaCode wireless keypads. But that maybe a few days before Im able figure out the rest of the formula for that. I’m kind of on the fence about publicly publishing that portion of the formula once I figure out how to get it implemented into this existing formula.

The benefit of appending the boundaries in the formula would be that it keeps all the potential handheld code combinations in check within a single formula that can be used anywhere, without external conditions or coding. But would also automatically calculate the wireless keypad Hex also.

1 Like

Here is one last version on github for easy modification by others. The changes include a simple cleanup, a better user interaction, and the ability to save a sub file. The file will save to the same directory as the python program currently. I have no idea if I will continue to work on this version but there are some interesting things that could be done to improve it like saving the file directly to a Flipper and expanding the functions as mentioned in the post above.

1 Like

Nice job. That’s definitely cleaner to use. It took me a lang minute to find the saved file buried in vscode. But I found it.
I hope you or others are able to be utilized maybe else were.
Ill work on getting the rest of the formula figured out. It maybe a few days before I have time to work on it agin.

1 Like

to answer the comment about his protocol being used for more than garage doors. Answer is yes this protocols is implemented in all kinds of products not just under the Linear brand. Everything from residential light switches and wireless entrapment sensors , to commercial access control systems.

1 Like

After a little more testing my formula actually already works to mimic wireless keypad. So your program as is fully functional beyond any MegaCode hex generator available. Because all other generators cap out 65535.

To mimic a MegaCode wireless keypad.The FC needs to be 0 and Btn needs to be 1. Then an entry code between 1 and 999999 can be used in place of Transmitter number.

1 Like

Cool! I’ll update some prompts. My focus now will be porting this to a C library that can be included in a Flipper app.

My abilities in C are very limited. I’ve forgotten so much since I last used it. Practically starting from scratch.

Thanks to the following authors for the hex translation code.
Decimal to Hexadecimal in C - Sanfoundry

1 Like

I updated the python repo to guide the user through the keypad generation process.

1 Like

When I get a chance Im going to try it in a node red project Ive been working on.

1 Like

Very cool! I don’t use node red but it’s a staple in the home automation scene so I’m very aware of it. I use Home Assistant without node red.

1 Like

The python code looks good and I got my garage door functioning!
One issue though is that a small typo in your code keeps it from being recognized by flipper. You need to add a ‘c’ to the end of the Preset name. It should be ‘FuriHalSubGhzPresetOok650Async’ not ‘FuriHalSubGhzPresetOok650Asyn’

Cheers!

1 Like

Good feedback. I’m still working on the code but I got way behind on everything because of a multi day power outage. Hopefully that won’t happen again today. We have another severe storm moving in.

1 Like