flipperzero-firmware icon indicating copy to clipboard operation
flipperzero-firmware copied to clipboard

iButton ds1990a emulation doesn't work

Open jagotu opened this issue 2 years ago • 31 comments

Describe the bug.

I've been having issues with emulating my iButton to the door lock, so I took a logic analyzer to it and got some recordings.

It seems to me (and I'm an amateur at this) like the window between resets left by the reader is just 230 microseconds and the flipper doesn't react fast enough.

This is what the emulation attempt looks like: image

Between resets, there's just 230 microseconds: image

I also MITM'd the actual key and it reacts with the presence signal in 35 microseconds: image

I also attach saleae recordings of the failed emulation attempt and what a succesful communication looks like. The MITM communaction is cut-off before the UID transmission but the beginning of the transaction is clearly visible.

1wire_saleae.zip

I have pretty much unlimited access to the button, the readers and the logic analyzer, so I can provide more captures if necessary.

Reproduction

  1. Emulate a ds1990a iButton
  2. Attach Flipper to the reader, making sure there is good connectivity.
  3. No reaction whatsoever from the reader.

Target

No response

Logs

No response

Anything else?

No response

jagotu avatar Oct 07 '22 22:10 jagotu

I've also noticed this with my iButton key. The flipper can capture the key just fine, but can not emulate it back to the reader correctly. I believe it's a similar issue with timing, but I don't have the correct equipment to measure it.

alecmatthews avatar Oct 14 '22 14:10 alecmatthews

@nminaylov can you take a look in next sprint?

skotopes avatar Oct 14 '22 17:10 skotopes

@nminaylov Any updates? Did you manage to reproduce? Is more information required from me?

jagotu avatar Nov 18 '22 10:11 jagotu

Hello, I am having the same issue with the same type of iButton key. I can successfully read the key and save it, but emulation does not work.

Steampunkery avatar Feb 20 '23 01:02 Steampunkery

@Steampunkery we just finished refactoring of ibutton application and underlying libraries. Can you test again?

skotopes avatar Mar 13 '23 14:03 skotopes

Hi, I installed the new firmware, but it still doesn't work. The key reader doesn't recognize it as a key or blink red or anything, just no response. I even tried it with breakout jumpers just to be sure.

On Mon, Mar 13, 2023, 10:22 あく @.***> wrote:

@Steampunkery https://github.com/Steampunkery we just finished refactoring of ibutton application and underlying libraries. Can you test again?

— Reply to this email directly, view it on GitHub https://github.com/flipperdevices/flipperzero-firmware/issues/1847#issuecomment-1466236519, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC3IOU3C4PJ3DJ75RMAHRQLW34UQZANCNFSM6AAAAAAQ76OVEQ . You are receiving this because you were mentioned.Message ID: @.***>

Steampunkery avatar Mar 15 '23 18:03 Steampunkery

i think we need data from log analyzer to figure out what happens on the bus

skotopes avatar Mar 16 '23 18:03 skotopes

I think I have access to a logic analyzer. I'll see if I can get a dump from it next week.

Steampunkery avatar Mar 17 '23 02:03 Steampunkery

Hi, confirming I see the same issue with the latest stock firmware update - DS1990 can read and write just fine, but emulation doesn't seem to elicit any response from the reader.

theoilie avatar Jun 11 '23 07:06 theoilie

@theoilie We need oscillograms and/or record from logic analyzer to understand better what happens on the bus.

skotopes avatar Jun 16 '23 08:06 skotopes

I have the same issue but on the DS1971 Emulation, but with this reader. IMG_5380

the flipper zero stays on the iButton Emulating screen, which makes me believe that there is something within the reader that is blocking the emulation.

@theoilie @skotopes, is there anything I can provide to help?

jeffdlin1618 avatar Aug 16 '23 18:08 jeffdlin1618

data from log analyzer, reader name

skotopes avatar Aug 17 '23 01:08 skotopes

I don't have access to a GPIO module for the log analyzer, but the ibutton reader is DS1402D-DR8+-ND

jeffdlin1618 avatar Aug 17 '23 21:08 jeffdlin1618

@doomwastaken FYI

skotopes avatar Aug 21 '23 20:08 skotopes

Found the reader, should be able to try this within the week

doomwastaken avatar Aug 22 '23 05:08 doomwastaken

I don't have any oscillogram data to provide, but the reader was a Schlage deadbolt lock with anti-emulation which makes sense for why an emulator doesn't work on it. The workaround is to write to a programmable DS1990A key (ie RW1990), and then that works just fine on the Schlage reader.

theoilie avatar Aug 28 '23 04:08 theoilie

We are waiting arrival of one of the 1-wire readers mentioned here, I will try and search for Schlage 1-wire lock, however they are mostly US based, will update once I get more details

doomwastaken avatar Aug 29 '23 08:08 doomwastaken

Any update since receiving the reader?

jeffdlin1618 avatar Sep 15 '23 06:09 jeffdlin1618

Checked with logistics, should be available for testing on monday

doomwastaken avatar Sep 15 '23 07:09 doomwastaken

Are there any updates on this issue yet?

davidwernhart avatar Oct 15 '23 09:10 davidwernhart

Currently unable to verify, until NFC refactor is merged. We've purchased DS1402D-DR8+-ND, just need to set it up. I will have time available this week, if I will try and confirm the issue locally. You can ping me for it too

doomwastaken avatar Oct 17 '23 06:10 doomwastaken

I have found an interesting feature - the reader does not respond to Dallas key emulation, but it does respond (gives an error signal) when Metacom or Cifral emulation is used.

klim3000 avatar Nov 07 '23 19:11 klim3000

I have found an interesting feature - the reader does not respond to Dallas key emulation, but it does respond (gives an error signal) when Metacom or Cifral emulation is used.

Hmm any ideas on how we can get Dallas to work?

jeffdlin1618 avatar Nov 09 '23 17:11 jeffdlin1618

Seems like there was a hardware solution here: https://forum.flipper.net/t/problem-emulating-ibuttons/4463/19

jeffdlin1618 avatar Nov 09 '23 17:11 jeffdlin1618

Seems like there was a hardware solution here: https://forum.flipper.net/t/problem-emulating-ibuttons/4463/19

This is really interesting! Seems like it would actually be an easy fix in software. Let's hope this gets sorted out soon!

davidwernhart avatar Nov 19 '23 15:11 davidwernhart

@DrZlo13 reminder

skotopes avatar Jan 03 '24 11:01 skotopes

I tried to investigate the issue of DS1990 not working.

As far as understood, flipper does not see 1->0->1 (RESET) on the line, meaning that interrupt handler registered in one_wire_slave.c newer gets called: furi_hal_gpio_add_int_callback(bus->gpio_pin, onewire_slave_exti_callback, bus); furi_hal_gpio_init(bus->gpio_pin, GpioModeInterruptRiseFall, GpioPullNo, GpioSpeedLow); Changing GpioSpeedLow to other values did not helped. Impulse might be too short, so flipper just does not see it. [I think this is confirmed by logic analyzer logs in the first post]

[as someone mentioned that using Metakom emulation gives BEEP-deny from terminal] I also looked at Metakom emulation and it is implemented in completely different way (using timers). So I rewrote the interrupt callback using timer implementation.

static void ibutton_fixed_interrupt(void* context) {
    OneWireSlave* bus = context;

    bool current_state = furi_hal_gpio_read(bus->gpio_pin);
    if (current_state == 1) {
        // read 1
        if (bus->pulse_start != 0) {
            // high -> [low -> high]
            const uint32_t pulse_length = (DWT->CYCCNT - bus->pulse_start) / furi_hal_cortex_instructions_per_microsecond();
            
            LOG("pulse_length %i\n", pulse_length);

            LOG("cond %i <= %i <= %i | %i\n", 
                onewire_slave_timings_overdrive.trstl_min, pulse_length, 
                onewire_slave_timings_normal.trstl_max,
                (pulse_length >= onewire_slave_timings_overdrive.trstl_min) && (pulse_length <= onewire_slave_timings_normal.trstl_max));

            if((pulse_length >= onewire_slave_timings_overdrive.trstl_min) && (pulse_length <= onewire_slave_timings_normal.trstl_max)) {
                /* Start in reset state in order to send a presence pulse immediately */
                bus->error = OneWireSlaveErrorResetInProgress;
                /* Determine reset type (chooses speed mode if supported by the emulated device) */
                bus->is_short_reset = pulse_length <= onewire_slave_timings_overdrive.trstl_max;
                /* Initial reset allows going directly into overdrive mode */
                bus->is_first_reset = true;

                const bool result = onewire_slave_bus_start(bus);

                if(result && bus->result_callback != NULL) {
                    bus->result_callback(bus->result_callback_context);
                }
            }
            bus->pulse_start = 0;
        } else {
            // nothing on the line       
        }
    } else {
        // read 0
        if (bus->pulse_start == 0) {
            // start of RESET impulse [high -> low]
            bus->pulse_start = DWT->CYCCNT;
        } else {
            // low signal continue
        }
    }

    furi_hal_ibutton_emulate_set_next(10 * furi_hal_cortex_instructions_per_microsecond());
}
void onewire_slave_start(OneWireSlave* bus) {
    furi_hal_ibutton_pin_configure();
    furi_hal_ibutton_emulate_start(0, ibutton_fixed_interrupt, bus);
}
void onewire_slave_stop(OneWireSlave* bus) {
    UNUSED(bus);
    furi_hal_ibutton_emulate_stop();
    furi_hal_ibutton_pin_reset();
}

It also did not worked. Maybe my furi_hal_ibutton_emulate_set_next is wrong? I tried to make timer fire as fast as possible.

Last thing that was metioned [in external thread, link in one of the upper posts] is that by using external button and shorting 1W to GRD we can get emulation working. And this is also confirm theory that flipper need a much longer RESET impulse comparing to the impulse door generates.

I hope this info will help someone more skilled in flipper firmware programming to resolve this issue.

cr0eax avatar Jan 22 '24 12:01 cr0eax

@gsurkov FYI

skotopes avatar Jan 23 '24 05:01 skotopes

@doomwastaken Have you been able to replicate this by now?

Thank you for your time!

davidwernhart avatar Mar 17 '24 10:03 davidwernhart

After 0.99.1 update same issue appears. DS1990 emulation stopped to work. In details, it has 1 impulse, then it stopped to emulate.

armdn avatar Mar 18 '24 09:03 armdn