|
14 | 14 |
|
15 | 15 | #include "2bload.h" |
16 | 16 |
|
| 17 | +void pic_challenge_response(void) |
| 18 | +{ |
| 19 | + register u8 x1c, x1d, x1e, x1f; |
| 20 | + register u8 b1, b2, b3, b4; |
| 21 | + register int i; |
| 22 | + |
| 23 | + smbus_set_addr(0x21); /* set PIC address; read command */ |
| 24 | + smbus_read_start(0x1c); |
| 25 | + if (!smbus_cycle_completed()) return; |
| 26 | + x1c = smbus_read_data(); |
| 27 | + x1d = smbus_read(0x1d); |
| 28 | + x1e = smbus_read(0x1e); |
| 29 | + x1f = smbus_read(0x1f); |
| 30 | + |
| 31 | + b1 = 0x33; |
| 32 | + b2 = 0xed; |
| 33 | + b3 = x1c << 2; |
| 34 | + b3 ^= x1d + 0x39; |
| 35 | + b3 ^= x1e >> 2; |
| 36 | + b3 ^= x1f + 0x63; |
| 37 | + b4 = x1c + 0x0b; |
| 38 | + b4 ^= x1d >> 2; |
| 39 | + b4 ^= x1e + 0x1b; |
| 40 | + |
| 41 | + for (i = 0; i < 4; b1 += b2 ^ b3, b2 += b1 ^ b4, ++i); |
| 42 | + |
| 43 | + smbus_set_addr(0x20); /* set PIC address; write command */ |
| 44 | + smbus_write(0x20, b1); |
| 45 | + smbus_write(0x21, b2); |
| 46 | +} |
17 | 47 |
|
18 | 48 | // ---------------------------- I2C ----------------------------------------------------------- |
19 | 49 | // |
@@ -85,65 +115,6 @@ int I2CTransmitWord(u8 bPicAddressI2cFormat, u16 wDataToWrite) |
85 | 115 | return ERR_I2C_ERROR_BUS; |
86 | 116 | } |
87 | 117 |
|
88 | | -// ---------------------------- PIC challenge/response ----------------------------------------------------------- |
89 | | -// |
90 | | -// given four bytes, returns a u16 |
91 | | -// LSB of return is the 'first' byte, MSB is the 'second' response byte |
92 | | - |
93 | | -u16 BootPicManipulation( |
94 | | - u8 bC, |
95 | | - u8 bD, |
96 | | - u8 bE, |
97 | | - u8 bF |
98 | | -) { |
99 | | - int n=4; |
100 | | - u8 |
101 | | - b1 = 0x33, |
102 | | - b2 = 0xed, |
103 | | - b3 = ((bC<<2) ^ (bD +0x39) ^ (bE >>2) ^ (bF +0x63)), |
104 | | - b4 = ((bC+0x0b) ^ (bD>>2) ^ (bE +0x1b)) |
105 | | - ; |
106 | | - |
107 | | - while(n--) { |
108 | | - b1 += b2 ^ b3; |
109 | | - b2 += b1 ^ b4; |
110 | | - } |
111 | | - |
112 | | - return (u16) ((((u16)b2)<<8) | b1); |
113 | | -} |
114 | | - |
115 | | -// actual business of getting I2C data from PIC and reissuing munged version |
116 | | -// returns zero if all okay, else error code |
117 | | - |
118 | | -int BootPerformPicChallengeResponseAction() |
119 | | -{ |
120 | | - u8 bC, bD, bE, bF; |
121 | | - int n; |
122 | | - |
123 | | - n=I2CTransmitByteGetReturn( 0x10, 0x1c ); |
124 | | - if(n<0) return n; |
125 | | - bC=n; |
126 | | - n=I2CTransmitByteGetReturn( 0x10, 0x1d ); |
127 | | - if(n<0) return n; |
128 | | - bD=n; |
129 | | - n=I2CTransmitByteGetReturn( 0x10, 0x1e ); |
130 | | - if(n<0) return n; |
131 | | - bE=n; |
132 | | - n=I2CTransmitByteGetReturn( 0x10, 0x1f ); |
133 | | - if(n<0) return n; |
134 | | - bF=n; |
135 | | - |
136 | | - { |
137 | | - u16 w=BootPicManipulation(bC, bD, bE, bF); |
138 | | - |
139 | | - I2CTransmitWord( 0x10, 0x2000 | (w&0xff)); |
140 | | - I2CTransmitWord( 0x10, 0x2100 | (w>>8) ); |
141 | | - } |
142 | | - |
143 | | - // continues as part of video setup.... |
144 | | - return ERR_SUCCESS; |
145 | | -} |
146 | | - |
147 | 118 | extern int I2cSetFrontpanelLed(u8 b) |
148 | 119 | { |
149 | 120 | I2CTransmitWord( 0x10, 0x800 | b); // sequencing thanks to Jarin the Penguin! |
|
0 commit comments