SPI doesn’t work on Jetson Nano 2GB. How to use SPI on Jetson Nano? - spi

SPI doesn’t want to work on my Jetson Nano.
In my devices from terminal I have this:
val#val-desktop:~$ ls /dev/spi*
/dev/spidev0.0 /dev/spidev0.1 /dev/spidev1.0 /dev/spidev1.1
And this:
val#val-desktop:~$ lsmod | grep spi
spidev 13282 0
When I’m connecting MISO and MOSI pins(19 and 21 pins according to this picture ) and testing SPI with this code I have this:
val#val-desktop:~/spi_test$ ./spi_test -v -D /dev/spidev0.0
spi mode: 0x0
bits per word: 8
max speed: 500000 Hz (500 kHz)
TX | FF FF FF FF FF FF 40 00 00 00 00 95 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF F0 0D |…#…|
RX | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |…|
No response. I was trying all 0.0 0.1 1.0 1.1 variants.
What am I doing wrong?

Related

Accessing an external SFP module via I2C not working

I hope this is the correct location for a question like I am asking here (I am new to asking questions on stackoverflow)
I am working on a project with a processor to access the registers of an SFP (connected to the I2C-bus of the processor).
Obviously it is not working (at least not always), but to clarify I want to mention what is working ... The setup fo the processor and the I2C bus is working properly. Other devices on the bus work flawlessly.
At the moment I am using a Raspberry Pi and its I2C capabilities to troubleshoote my project.
The hardware to connect the SFP-interface to the I2C pins of the Raspberry Pi I built myself (and there may be some error in it), but as I am trying different SFPs I see some are working properly.
These are working:
GLC-T, GLC-SX-MM
The following did not work (with an i2detect command from the RPi it does not see any responding device):
GLC-SX-MMD, SFP-10G-SR, PAN-SFP-PLUS-SR-CMT (The last one is from PaloAlto, all others are from Cisco)
I tried to follow the specifications from INF-8074 (https://www.10gtek.com/templates/wzten/pdf/INF-8074.pdf) to make the proper connections and for some SFPs it seems to be working. Even though I cannot verify all the registers' accuracy, there are parts (like the description of the SFP) which show up clearly ... below is the output of the GCL-T:
mordin#ubuntu:~$ sudo i2cdump -y 1 0x50
No size specified (using byte-data access)
0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef
00: 03 04 00 00 00 00 08 00 00 00 00 01 0d 00 00 00 ??....?....??...
10: 00 00 64 00 43 49 53 43 4f 2d 4d 45 54 48 4f 44 ..d.CISCO-METHOD
20: 45 20 20 20 01 00 00 00 53 50 37 30 34 31 5f 52 E ?...SP7041_R
30: 65 76 5f 46 20 20 20 20 46 20 20 20 41 0c c1 5a ev_F F A??Z
40: 00 10 00 00 30 30 30 30 30 4d 54 43 31 35 33 39 .?..00000MTC1539
50: 30 31 45 51 31 31 30 39 32 31 30 31 00 00 00 3c 01EQ11092101...<
60: 00 00 0e fa 99 1c 0a 21 57 89 b6 80 c0 8a 20 a0 ..?????!W????? ?
70: f7 c2 a9 00 00 00 00 00 00 00 00 00 46 a1 08 57 ???.........F??W
80: 43 4e 53 38 54 55 54 41 41 42 33 30 2d 31 34 31 CNS8TUTAAB30-141
90: 30 2d 30 33 00 00 00 00 00 00 00 00 00 00 00 c3 0-03...........?
a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
c0: 47 4c 43 2d 54 20 20 20 20 20 20 20 20 20 20 20 GLC-T
d0: 20 20 20 20 ff ff ff ff ff ff ff ff ff ff ff ff ............
e0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
f0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
There are multiple projects online ... and they all describe their workflow, and it sounds like as long as you make proper physical connections (power, I2C-pins) it should "just work" to have access to the registers of the connected SFP.
Now I am not sure ... did I miss something when I made my physical connections and some SFPs are just working accidently?
Just for "fun" I tried to pin the "TX Disable" to GND (I was thinking maybe the line disables the whole SFP-module and not only the TX-part), but it did not make any difference.
If someone has a suggestion (or a hint what I could try) why I am not able to access many SFPs via I2C while some work just fine, I would be grateful.
Thanks,
Mordin
PS.: apparently I am not allowed to use "sfp" as a tag ... weird

Reference key not useable when authenticating to MIFARE Classic card

I'm trying to authenticate to a MIFARE Classic card using PC/SC based APDU. I'm using a SCL3711 reader and the key A 00 00 00 00 00 03.
>> FF 82 00 60 06 00 00 00 00 00 03
<< 90 00
>> FF 86 00 00 05 01 00 08 60 00
<< 69 84
(Check error : referenced data invalidated)
I'm sure the data stored in the corresponding sector trailer is ok, as using a native reader I'm able to read/write the value. Actually this is the way I was able to restore the key once this happened.
When using other keys like FF FF FF FF FF FF, or 01 02 03 04 05 06, or whatever "normal", everything is working as expected.
a) With valid key FF FF FF FF FF FF
>> FF 82 00 60 06 FF FF FF FF FF FF
<< 90 00
>> FF 86 00 00 05 01 00 08 60 00
<< 90 00
b) With invalid key 01 02 03 04 05 06
>> FF 82 00 60 06 01 02 03 04 05 06
<< 90 00
>> FF 86 00 00 05 01 00 08 60 00
<< 69 82
I have gone through the PC/SC specs (Part 3) and haven't found any place where they include any reference to valid or invalid keys. It is the first time I'm not able to use a key.
Any idea why this is happening?

jbig2 data in pdf is not valid jbig2 data. Wrong magic

I would like to take some jbig2 data out of a pdf file and load it using libjbig2dec (http://sourceforge.net/projects/jbig2dec)
For some reason the jbig2 data in the pdf file starts with this:
00000000 00 00 00 00 30 01 01 00 00 00 13 00 00 0a 5e 00
00000010 00 0f c3 00 00 2e 23 00 00 2e 23 00 00 00 00 00
00000020 00 01 26 01 01 ff ff ff ff 00 00 0a 5e 00 00 0f
00000030 c3 00 00 00 00 00 00 00 00 00 00 03 ff fd ff 02
00000040 fe fe fe ab f3 d0 fe 9e 92 d8 9f 63 ae 67 79 b8
00000050 81 ff 57 33 90 a4 ee c2 af c8 80 dc 0d 60 1e 86
But a valid jbig2 file should start with this magic:
0x97, 0x4a, 0x42, 0x32, 0x0d, 0x0a, 0x1a, 0x0a
What's going on here?
pdf format strips the header and the tail of the jbig2 file as specified in PDF, Version 1.7 (ISO 32000-1:2008) section 7.4.7 JBIG2Decode Filter
Further, some pdf files contain jbig2 streams with last segment of unspecified size (ff ff ff ff). libjbig2dec can not handle this.
Some PDFs are missing JBIG2 header and here is one of well known stream for jb2 file format.
974A42320D0A1A0A0100000001000000003E00010000006820000000536F7572636500506F776572204A4249472D3220456E636F646572202D2054686520556E6976657273697479206F66204272697469736820436F6C756D626120616E6420496D61676520506F77657220496E632E0056657273696F6E00312E302E3000000000
I added the above stream to header of rough data, and it was decoded well.

How can I check INITIALIZE UPDATE and EXTERNAL AUTHENTICATE correctness?

I sent 80 50 00 00 08 00 00 00 00 00 00 00 00 [INITILIZE UPDATE Command] via opensc-tool to my java card and received 00 00 11 60 01 00 8A 79 0A F9 FF 02 00 11 79 11 36 5D 71 00 A5 A5 EC 63 BB DC 05 CC [Init Response] as its response from the card.
As you see:
In the command,I send 00 00 00 00 00 00 00 00 as Host Challenge, And in the response :
00 00 11 60 01 00 8A 79 0A F9 = Key diversification data
FF 02 = Key information
00 11 79 11 36 5D 71 00 = Card challenge
A5 A5 EC 63 BB DC 05 CC = Card cryptogram
Now I want to check myself,if the card cryptogram is OK or not. How I can do it? for example I encrypt 00 00 00 00 00 00 00 00 in this site under a 3DES cryptography algorithm [with keys of my card = 4041...4F], but the output is not equal with card cryptogram that I wrote above. Why?
And the next question is, if I want to send EXTERNAL AUTHENTICATION command to the card, what is its data field (after the above INITILIZE UPDATE)?
Update:
This is GPJ output :
C:\Users\ghasemi\Desktop\gpj-20120310>GPJ
C:\Users\ghasemi\Desktop\gpj-20120310>java -jar gpj.jar
Found terminals: [PC/SC terminal ACS CCID USB Reader 0]
Found card in terminal: ACS CCID USB Reader 0
ATR: 3B 68 00 00 00 73 C8 40 12 00 90 00
.
.
.
DEBUG: Command APDU: 00 A4 04 00 08 A0 00 00 00 03 00 00 00
DEBUG: Response APDU: 6F 10 84 08 A0 00 00 00 03 00 00 00 A5 04 9F 65 01 FF 90 00
Successfully selected Security Domain OP201a A0 00 00 00 03 00 00 00
DEBUG: Command APDU: 80 50 00 00 08 7F 41 A9 E7 19 37 83 FA
DEBUG: Response APDU: 00 00 11 60 01 00 8A 79 0A F9 FF 02 00 1B 9B 95 B9 5E 5E BC BA 51 34 84 D9 C1 B9 6E 90 00
DEBUG: Command APDU: 84 82 00 00 10 13 3B 4E C5 2C 9E D8 24 50 71 83 3A 78 AE 75 23
DEBUG: Response APDU: 90 00
DEBUG: Command APDU: 84 82 00 00 08 13 3B 4E C5 2C 9E D8 24
DEBUG: Response APDU: 90 00
C:\Users\ghasemi\Desktop\gpj-20120310>
So :
Host_Challenge :: 7F41A9E7193783FA
Diversification_Data :: 0000116001008A790AF9
Key_Information :: FF02
Sequence_Counter :: 001B
Card_Challenge :: 9B95B95E5EBC
Card_Cryptogram :: BA513484D9C1B96E
Host_Cryptogram[16,24] = 13 3B 4E C5 2C 9E D8 24
Now,lets make our Host_Cryptogram Manually :
Derivation_data=derivation_const_ENC|sequence_counter|0000 0000 0000 0000 0000 0000
Derivation_Data = 0182001B000000000000000000000000
k_ENC :: 404142434445464748494A4B4C4D4E4F
IV = 00 00 00 00 00 00 00 00
S_ENC = encrypt(TDES_CBC, K_ENC, IV, derivation_data)
So :
I used http://tripledes.online-domain-tools.com/ and its output for above values was :
S_ENC = 448b0a5967ca246d058703ff0c694f15
And :
Padding_DES = 80 00 00 00 00 00 00 00
Host_auth_data = sequence_counter | card_challenge | host_challenge | padding_DES
IV = Card_Cryptogram :: BA513484D9C1B96E
host_cryptogram = encrypt(TDES_CBC, S_ENC, IV, host_auth_data)
So :
Host_Authentication_Data : 001B9B95B95E5EBC7F41A9E7193783FA8000000000000000
Again, I used http://tripledes.online-domain-tools.com/
and :
Host_Cryptogram : 3587b531db71ac52392493c08cff189ce7b9061029c63b62
So :
Host_Cryptogram[16,24] = e7b9061029c63b62
Why these two way [manually and GPJ output] give us two host cryptogram?
From the INITIALIZE UPDATE command you send, you get
host_challenge = 00 00 00 00 00 00 00 00
In response to the INITIALIZE UPDATE command, you get
diversification_data = 00 00 11 60 01 00 8A 79 0A F9
key_information = FF 02
sequence_counter = 00 11
card_challenge = 79 11 36 5D 71 00
card_cryptogram = A5 A5 EC 63 BB DC 05 CC
The key information indicates SCP02 (02). The key diversification data may be used to derive the card-specific K_ENC. Lets assume we have a K_ENC like this
K_ENC = 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
We can then derive the session encryption key like this
derivation_const_ENC = 01 82
derivation_data = derivation_const_ENC | sequence_counter | 00 00 00 00 00 00 00 00 00 00 00 00
IV = 00 00 00 00 00 00 00 00
S_ENC = encrypt(TDES_CBC, K_ENC, IV, derivation_data)
Next, we can assemble the authentication data used to calculate the host cryptogram:
padding_DES = 80 00 00 00 00 00 00 00
host_auth_data = sequence_counter | card_challenge | host_challenge | padding_DES
Then we can use the session encryption key to encrypt the authentication data:
IV = 00 00 00 00 00 00 00 00
host_cryptogram = encrypt(TDES_CBC, S_ENC, IV, host_auth_data)
The last 8 bytes of the encrypted authentication data are the actual host cryptogram that we would send to the card:
EXTERNAL_AUTHENTICATE_data = host_cryptogram[16, 24]
Now we can assemble the EXTERNAL AUTHENTICATE command:
EXTERNAL_AUTHENTICATE = 84 82 03 00 08 | EXTERNAL_AUTHENTICATE_data
We can then calculate the S_MAC key (analoguous to getting the S_ENC above) and the MAC over that command and append it to the command data to get the full EXTERNAL AUTHENTICATE command that can be sent to the card:
EXTERNAL_AUTHENTICATE = 84 82 03 00 10 | EXTERNAL_AUTHENTICATE_data | MAC
Update
Using http://tripledes.online-domain-tools.com/ to reproduce the results of GPJ
Your K_ENC is 404142434445464748494A4B4C4D4E4F. The online tools does not properly support 2-key-3DES, so you have to convert the key into its 3-key form first:
K_ENC = 404142434445464748494A4B4C4D4E4F4041424344454647
Use this key and a zero IV to encrypt the derivation data (0182001B000000000000000000000000). You get
S_ENC = fb063cc2e17b979b10e22f82110234b4
In 3-key notation, this is
S_ENC = fb063cc2e17b979b10e22f82110234b4fb063cc2e17b979b
Use this key and a zero IV to encrypt the host authentication data (001b9b95b95e5ebc7f41a9e7193783fa8000000000000000):
HOST_CRYPTOGRAM = 773e790c91acce3167d99f92c60e2afd133b4ec52c9ed824

MS Project 2010 - How to restore macros from (corrupt?) Global.MPT

i was developing some VBA macro during a day - 500 lines of code. Code was placed into Global.mpt because i was going to reuse it across different project files.
At some moment i missed to increment cycle in the while cycle. When debugging this brought MS Project into endless non-responsive 100%-CPU-usage loop. I had to kill MS Project from task manager and after restarting it i see no VBA modules in Global.mpt. I see names of my variables and procedures in existing Global.MPT, but there is no plain code to restore manually.
When i try renaming Global.MPT into MyGlobal.MPT and opening it, MS Project shows 'Organizer' dialog suggesting to import content from MyGlobal.MPT to Global.MPT but 'Modules' tab shows empty list of like there is nothing to import.
Is there way to fix or export VBA content from the file? I do not want to loose day of works :(
For referrence - module named MyModule with following content
Sub HelloWorld()
MsgBox 'HelloWorld'
End Sub
Looks like following in the VBA stream
0012BA04 01 16 01 00 02 F0 00 00 00 BC 02 00 00 D4 00 00 |................|
0012BA14 00 B0 01 00 00 FF FF FF FF EA 02 00 00 8A 03 00 |................|
0012BA24 00 00 00 00 00 01 00 00 00 7D 0A CF 43 00 00 FF |.........}..C...|
0012BA34 FF 03 00 00 00 00 00 00 00 B6 00 FF FF 01 01 00 |................|
0012BA44 00 00 00 FF FF FF FF 00 00 00 00 FF FF 04 00 FF |................|
0012BA54 FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
0012BA64 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
0012BA74 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
0012BA84 00 00 00 00 00 00 00 10 00 00 00 03 00 00 00 05 |................|
0012BA94 00 00 00 07 00 00 00 FF FF FF FF FF FF FF FF 01 |................|
0012BAA4 01 08 00 00 00 FF FF FF FF 78 00 00 00 02 00 00 |.........x......|
0012BAB4 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
0012BAC4 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FF |................|
0012BAD4 00 00 00 00 4D 45 00 00 FF FF FF FF FF FF 00 00 |....ME..........|
0012BAE4 00 00 FF FF 00 00 00 00 FF FF 01 01 00 00 00 00 |................|
0012BAF4 DF 00 FF FF 00 00 00 00 04 00 FF FF FF FF FF FF |................|
0012BB04 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF |................|
0012BB14 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF |................|
0012BB24 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF |................|
0012BB34 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF |................|
0012BB44 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF |................|
0012BB54 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF |................|
0012BB64 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF |................|
0012BB74 FF FF FF FF FF FF FF FF FF FF 28 00 00 00 00 00 |..........(.....|
0012BB84 36 0A FF FF FF FF 00 00 00 00 02 3C 08 00 FF FF |6..........<....|
0012BB94 00 00 00 00 02 3C 0C 00 FF FF 00 00 00 00 02 3C |.....<.........<|
0012BBA4 FF FF FF FF 00 00 FF FF 01 01 00 00 00 00 00 00 |................|
0012BBB4 01 00 00 00 FF FF FF FF 01 01 80 00 00 00 38 00 |..............8.|
0012BBC4 00 00 FF FF FF FF 02 83 1C 02 FF FF FF FF 08 00 |................|
0012BBD4 FF FF 30 00 00 00 00 00 FF FF FF FF FF FF 00 00 |..0.............|
0012BBE4 00 00 FF FF FF FF FF FF FF FF 00 00 00 00 1D 00 |................|
0012BBF4 00 00 25 00 00 00 0B 12 1E 02 FF FF FF FF 00 00 |..%.............|
0012BC04 00 60 00 00 00 00 FF FF FF FF FF FF FF FF 00 00 |.`..............|
0012BC14 00 00 00 00 00 00 FF FF FF FF 7C FF 00 00 FF FF |..........|.....|
0012BC24 FF FF FF FF FF FF FF FF FF FF 03 00 03 00 00 00 |................|
0012BC34 84 00 00 03 00 00 FF FF FF FF C0 01 00 00 01 00 |................|
0012BC44 01 00 00 00 00 00 00 00 00 00 00 00 00 00 38 00 |..............8.|
0012BC54 00 00 FF FF FF FF FF FF FF FF FF FF FF FF FF FF |................|
0012BC64 FF FF FF FF FF FF 38 00 00 00 FF FF FF FF FF FF |......8.........|
0012BC74 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF |................|
0012BC84 FF FF FF FF FF FF 08 00 00 00 00 00 00 00 01 00 |................|
0012BC94 00 00 08 00 04 00 FF FF FF FF 00 00 00 00 FF FF |................|
0012BCA4 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF |................|
0012BCB4 FF FF FF FF FF FF 02 00 00 00 00 00 E4 E7 C5 4E |...............N|
0012BCC4 0E 00 01 24 00 2A 00 5C 00 52 00 66 00 66 00 66 |...$.*.\.R.f.f.f|
0012BCD4 00 66 00 2A 00 30 00 3F 00 34 00 65 00 63 00 35 |.f.*.0.?.4.e.c.5|
0012BCE4 00 65 00 37 00 65 00 39 00 DF 00 00 00 00 00 00 |.e.7.e.9........|
0012BCF4 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
0012BD04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
0012BD14 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
0012BD24 00 00 00 00 00 00 FE CA 01 00 03 00 22 81 08 00 |............"...|
0012BD34 06 00 00 00 00 00 00 00 00 81 08 04 18 00 00 00 |................|
0012BD44 10 00 00 00 04 81 08 00 02 00 00 00 08 00 00 00 |................|
0012BD54 FF FF FF FF 01 01 30 00 00 00 96 04 38 00 00 00 |......0.....8...|
0012BD64 00 00 6F 00 FF FF 70 00 00 00 41 40 22 02 00 00 |..o...p...A#"...|
0012BD74 E0 00 0B 00 0B 00 48 65 6C 6C 6F 57 6F 72 6C 64 |......HelloWorld|
0012BD84 27 00 FF FF FF FF 50 00 00 00 FF FF FF FF 00 00 |'.....P.........|
0012BD94 01 52 B0 00 41 74 74 72 69 62 75 74 00 65 20 56 |.R..Attribut.e V|
0012BDA4 42 5F 4E 61 6D 00 65 20 3D 20 22 4D 79 4D 00 6F |B_Nam.e = "MyM.o|
0012BDB4 64 75 6C 65 22 0D 0A 00 53 75 62 20 48 65 6C 6C |dule"...Sub Hell|
0012BDC4 00 6F 57 6F 72 6C 64 28 29 08 0D 0A 20 00 00 4D |.oWorld()... ..M|
0012BDD4 73 67 42 10 6F 78 20 27 07 64 27 0D 0A 10 45 6E |sgB.ox '.d'...En|
0012BDE4 64 20 00 5C 0D 0A |d .\..|
Other solutions are to recover from backup. Open on another machine with Project or repair the User Profile. It may be corrupt. If you can log in with another username to the PC and try to open the file. Good luck,
OR:
1] Go t File --> Options --> Trust Center --> click on Trust Center Settings --> Select the option "Allow loading files with legacy or non-default file formats" and try opening the file.
2] Open a blank project and try inserting the problematic file and try opening it.
The easiest way is to simply change the file extension to MPP and open it as a project. The organizer will come up and ask you if you want to copy the MPP's macros and code into your new (blank) MPT file. Just slide them over and you're good as gold (you'll have to reset your references, but otherwise, ready to go)