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

iButton: Add support for Dallas DS1971

Open baconlive opened this issue 2 years ago • 13 comments

What's new

Added support to one_wire lib to read and write Dallas DS1971 chip. DS1971 is an iButton with 8 bytes fixed key (without CRC and starting with 0x14) and it contains 3 memory areas, one 8 byte application register (writeable only once), a temporary 32 bytes scratchpad and a 32 bytes re-writable memory. The code added allow a user to read key and memory from a DS1971 and save it as file then write memory contents saved into the file on the same iButton or on a different one.

Verification

Read a DS1971, save contents to sd-card, modify it, write it back on the DS1971 (or on a different one) and the read it again to check new data written on the memory.

Checklist (For Reviewer)

  • [x] PR has description of feature/bug or link to Confluence/Jira task
  • [x] Description contains actions to verify feature/bugfix
  • [x] I've built this code, uploaded it to the device and verified feature/bugfix

baconlive avatar Oct 02 '22 20:10 baconlive

Hi.

In order to accept this PR we need 2 things:

  • emulation support
  • example dumps (flipper should be able to read another flipper that emulating)

skotopes avatar Oct 08 '22 13:10 skotopes

Hi, thanks for the update.

I've 2 flippers :-) so i'll proceed to implement emulation and provide dumps.

I'll update the code on PR as soon as it's ready.

Il sab 8 ott 2022, 15:39 あく @.***> ha scritto:

Hi.

In order to accept this PR we need 2 things:

  • emulation support
  • example dumps (flipper should be able to read another flipper that emulating)

— Reply to this email directly, view it on GitHub https://github.com/flipperdevices/flipperzero-firmware/pull/1815#issuecomment-1272322921, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAPF4Y4CERYLVZ5VRBMKAWDWCF2SHANCNFSM6AAAAAAQ3BPA6Q . You are receiving this because you authored the thread.Message ID: @.***>

baconlive avatar Oct 09 '22 07:10 baconlive

Updated code to fix emulation support for DS1971 and tested it with my flippers. Attached 2 dumps one took reading a "real" DS1971 with one flipper, then emulate the saved key. The other is read from the 2nd flipper while the other is emulating the original key. ds1971_dumps.zip

baconlive avatar Oct 12 '22 16:10 baconlive

Please see my comment in PR thread.

Hello, i see that build fails, is there anything i should do? Is is a problem with API VERSION?

I had to change a signature on OneWrireDevice:

ApiEntryFunction(name='onewire_device_alloc', returns='OneWireDevice*', params='uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t')

Thanks.

baconlive avatar Oct 14 '22 09:10 baconlive

@DrZlo13 got some ideas on architecture, we'll postpone this PR a little bit.

skotopes avatar Oct 18 '22 15:10 skotopes

Ok, thank you for the update. Please let me know if you need anything from my end to make things easier for you.

Il giorno mar 18 ott 2022 alle ore 17:32 あく @.***> ha scritto:

@DrZlo13 https://github.com/DrZlo13 got some ideas on architecture, we'll postpone this PR a little bit.

— Reply to this email directly, view it on GitHub https://github.com/flipperdevices/flipperzero-firmware/pull/1815#issuecomment-1282587635, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAPF4Y46AIL2GQ4ERXCNHD3WD27KJANCNFSM6AAAAAAQ3BPA6Q . You are receiving this because you authored the thread.Message ID: @.***>

baconlive avatar Oct 18 '22 15:10 baconlive

Hello, and sorry for the long wait. I looked at the code and in its current form it is not ready enough for the merge. First we need to separate the ibutton_key from the ibutton app. Next - onewire_slave should be allocated with something like a "command list". But this will require rewriting the architecture and operation principle of the onewire_slave library, since it currently does not have a cmd receiver loop, and I will take on this task as soon as I finish the important ones.

DrZlo13 avatar Oct 27 '22 15:10 DrZlo13

Hello, thanks for the update and your findings.

While you work at the onewire_slave library cmd receiver what should i do? Remove the ibutton app part from the PR?

PLease let me know.

Il giorno gio 27 ott 2022 alle ore 17:27 Sergey Gavrilov < @.***> ha scritto:

Hello, and sorry for the long wait. I looked at the code and in its current form it is not ready enough for the merge. First we need to separate the ibutton_key from the ibutton app. Next - onewire_slave should be allocated with something like a "command list". But this will require rewriting the architecture and operation principle of the onewire_slave library, since it currently does not have a cmd receiver loop, and I will take on this task as soon as I finish the important ones.

— Reply to this email directly, view it on GitHub https://github.com/flipperdevices/flipperzero-firmware/pull/1815#issuecomment-1293705286, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAPF4Y24KLNCHCOMXXQCO23WFKNOLANCNFSM6AAAAAAQ3BPA6Q . You are receiving this because you authored the thread.Message ID: @.***>

baconlive avatar Oct 27 '22 15:10 baconlive

Hello, and sorry for the long wait. I looked at the code and in its current form it is not ready enough for the merge. First we need to separate the ibutton_key from the ibutton app. Next - onewire_slave should be allocated with something like a "command list". But this will require rewriting the architecture and operation principle of the onewire_slave library, since it currently does not have a cmd receiver loop, and I will take on this task as soon as I finish the important ones.

Hello, did you have time to look into onewire_slave? Thanks.

baconlive avatar Nov 21 '22 22:11 baconlive

@DrZlo13 still waiting for you ;-)

skotopes avatar Dec 10 '22 20:12 skotopes

What should i do on my side? Remove app code from the PR?

Please let me know.

Il sab 10 dic 2022, 21:23 あく @.***> ha scritto:

@DrZlo13 https://github.com/DrZlo13 still waiting for you ;-)

— Reply to this email directly, view it on GitHub https://github.com/flipperdevices/flipperzero-firmware/pull/1815#issuecomment-1345377438, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAPF4Y6NH4IFTKPSJLMWBA3WMTRETANCNFSM6AAAAAAQ3BPA6Q . You are receiving this because you authored the thread.Message ID: @.***>

baconlive avatar Dec 10 '22 20:12 baconlive

@baconlive nothing, @DrZlo13 will take care of it soon.

skotopes avatar Dec 10 '22 20:12 skotopes

Thanks.

Il sab 10 dic 2022, 21:38 あく @.***> ha scritto:

@baconlive https://github.com/baconlive nothing, @DrZlo13 https://github.com/DrZlo13 will take care of it soon.

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

baconlive avatar Dec 10 '22 20:12 baconlive

@baconlive nothing, @DrZlo13 will take care of it soon.

Any progress?

baconlive avatar Jan 08 '23 22:01 baconlive

@baconlive I am currently working on 1-Wire and iButton refactoring, it'll take another couple of weeks.

gsurkov avatar Jan 09 '23 10:01 gsurkov

Thanks. I'll wait for an update as soon as you're ready

Il lun 9 gen 2023, 11:05 Georgii Surkov @.***> ha scritto:

@baconlive https://github.com/baconlive I am currently working on 1-Wire and iButton refactoring, it'll take another couple of weeks.

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

baconlive avatar Jan 09 '23 10:01 baconlive

Hello Georgii, any progress on this?

Thanks

Il giorno lun 9 gen 2023 alle ore 11:42 Guido Giorgi @.***> ha scritto:

Thanks. I'll wait for an update as soon as you're ready

Il lun 9 gen 2023, 11:05 Georgii Surkov @.***> ha scritto:

@baconlive https://github.com/baconlive I am currently working on 1-Wire and iButton refactoring, it'll take another couple of weeks.

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

baconlive avatar Feb 05 '23 20:02 baconlive

@baconlive working on it right now, it is taking longer than expected, sorry!

gsurkov avatar Feb 06 '23 10:02 gsurkov

I'll move this PR to draft while we prepare base for this PR

skotopes avatar Feb 08 '23 11:02 skotopes

Ok, thank you!

Il mer 8 feb 2023, 12:36 あく @.***> ha scritto:

I'll move this PR to draft while we prepare base for this PR

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

baconlive avatar Feb 08 '23 12:02 baconlive

Any ETA for One wire library refactory?

Il mer 8 feb 2023, 13:32 Guido Giorgi @.***> ha scritto:

Ok, thank you!

Il mer 8 feb 2023, 12:36 あく @.***> ha scritto:

I'll move this PR to draft while we prepare base for this PR

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

baconlive avatar Feb 25 '23 17:02 baconlive

@baconlive At final stage, will be included in 0.79.

skotopes avatar Feb 25 '23 17:02 skotopes

@baconlive Sorry for the long wait As you may have noticed, the refactoring is done (but hasn't been thoroughly tested yet) and is now in the dev branch.

To add support for DS1971, first create 2 files in lib/one_wire/ibutton/protocols/dallas folder: touch protocol_ds1971.{c,h}.

Use other protocols such as ds1992 or ds1990 as an example. You will need to implement all methods listed in protocol_dallas_base.h, the only exceptions are write_blank, write_copy adn render_data, in that case the corresponding protocol features must not be set.

Look into dallas_common files to see if some of the code you need is already implemented there (for example, the reading of DS19xx ROM).

When done, add your new protocol to protocol_group_dallas_defs.{c,h} files. Together with the 2 files you have created before, those are the only 4 files one needs to edit in order to add a new iButton key type.

gsurkov avatar Mar 09 '23 09:03 gsurkov

@baconlive Sorry for the long wait As you may have noticed, the refactoring is done (but hasn't been thoroughly tested yet) and is now in the dev branch.

To add support for DS1971, first create 2 files in lib/one_wire/ibutton/protocols/dallas folder: touch protocol_ds1971.{c,h}.

Use other protocols such as ds1992 or ds1990 as an example. You will need to implement all methods listed in protocol_dallas_base.h, the only exceptions are write_blank, write_copy adn render_data, in that case the corresponding protocol features must not be set.

Look into dallas_common files to see if some of the code you need is already implemented there (for example, the reading of DS19xx ROM).

When done, add your new protocol to protocol_group_dallas_defs.{c,h} files. Together with the 2 files you have created before, those are the only 4 files one needs to edit in order to add a new iButton key type.

@gsurkov I've already tested the new implementation and successful added ds1971 "protocol" into my dev firmware, i'll have only to work out writing functions.

As soon as i finish i'll update the PR removing old updates and pushing the files.

Thanks you.

baconlive avatar Mar 09 '23 10:03 baconlive

Hello , @gsurkov i finished setting up the code, but i made some mess on this PR so i preferred to open a new one:

iButton: Add support for Dallas DS1971 v2 #2492

As soon as you confirm everything is ok on the new PR i'll close this.

Thanks

baconlive avatar Mar 15 '23 13:03 baconlive