comparison main.c @ 19:5f9a40d6991b

Import SD handling from http://www.roland-riegel.de/sd-reader/index.html Use smaller build options
author Matt Johnston <matt@ucc.asn.au>
date Tue, 25 Jun 2013 13:55:11 +0800
parents 021e6e0006f4
children 534009795508
comparison
equal deleted inserted replaced
18:021e6e0006f4 19:5f9a40d6991b
13 #include <util/atomic.h> 13 #include <util/atomic.h>
14 #include <util/crc16.h> 14 #include <util/crc16.h>
15 15
16 #include "hmac-sha1.h" 16 #include "hmac-sha1.h"
17 #include "aes.h" 17 #include "aes.h"
18
19 #include "fat.h"
20 #include "fat_config.h"
21 #include "partition.h"
22 #include "sd_raw.h"
23 #include "sd_raw_config.h"
18 24
19 //#include "simple_ds18b20.h" 25 //#include "simple_ds18b20.h"
20 //#include "onewire.h" 26 //#include "onewire.h"
21 27
22 LOCKBITS = (LB_MODE_3 & BLB0_MODE_4 & BLB1_MODE_4); 28 LOCKBITS = (LB_MODE_3 & BLB0_MODE_4 & BLB1_MODE_4);
263 UDR0 = '\n'; 269 UDR0 = '\n';
264 } 270 }
265 return (unsigned char)c; 271 return (unsigned char)c;
266 } 272 }
267 273
274 uint8_t find_file_in_dir(struct fat_fs_struct* fs, struct fat_dir_struct* dd, const char* name, struct fat_dir_entry_struct* dir_entry)
275 {
276 while(fat_read_dir(dd, dir_entry))
277 {
278 if(strcmp(dir_entry->long_name, name) == 0)
279 {
280 fat_reset_dir(dd);
281 return 1;
282 }
283 }
284
285 return 0;
286 }
287
288 struct fat_file_struct*
289 open_file_in_dir(struct fat_fs_struct* fs, struct fat_dir_struct* dd, const char* name)
290 {
291 struct fat_dir_entry_struct file_entry;
292 if(!find_file_in_dir(fs, dd, name, &file_entry))
293 return 0;
294
295 return fat_open_file(fs, &file_entry);
296 }
297
298 static void
299 hmac_file(const char* fn)
300 {
301 sd_raw_init();
302 struct partition_struct* partition = partition_open(sd_raw_read, sd_raw_read_interval, 0, 0, 0);
303 struct fat_fs_struct* fs = fat_open(partition);
304 struct fat_dir_entry_struct directory;
305 fat_get_dir_entry_of_path(fs, "/", &directory);
306
307 struct sd_raw_info disk_info;
308 sd_raw_get_info(&disk_info);
309 printf("diskinfo size %d", disk_info.capacity);
310
311 struct fat_dir_struct* dd = fat_open_dir(fs, &directory);
312 struct fat_file_struct* fd = open_file_in_dir(fs, dd, "fn");
313
314 char c = 0;
315 char buf[512];
316 for (int i = 0; i < 10; i++)
317 {
318 fat_read_file(fd, buf, sizeof(buf));
319 c ^= buf[0];
320 }
321 printf("total %d\n", c);
322 }
323
268 static void 324 static void
269 cmd_reset() 325 cmd_reset()
270 { 326 {
271 printf_P(PSTR("reset\n")); 327 printf_P(PSTR("reset\n"));
272 _delay_ms(100); 328 _delay_ms(100);
489 if (memcmp(output, indata, HMACLEN) != 0) { 545 if (memcmp(output, indata, HMACLEN) != 0) {
490 printf_P(PSTR("FAIL: hmac mismatch\n")); 546 printf_P(PSTR("FAIL: hmac mismatch\n"));
491 } 547 }
492 548
493 uint8_t tmpbuf[256]; 549 uint8_t tmpbuf[256];
494 aesInit(avr_keys[key_index], tmpbuf); 550 //aesInit(avr_keys[key_index], tmpbuf);
495 aesDecrypt(&indata[HMACLEN], NULL); 551 //aesDecrypt(&indata[HMACLEN], NULL);
496 552
497 printf_P(PSTR("DECRYPTED: ")); 553 printf_P(PSTR("DECRYPTED: "));
498 printhex(output, AESLEN, stdout); 554 printhex(output, AESLEN, stdout);
499 fputc('\n', stdout); 555 fputc('\n', stdout);
500 } 556 }
844 DDR_PI_RESET |= _BV(PIN_PI_RESET); 900 DDR_PI_RESET |= _BV(PIN_PI_RESET);
845 _delay_ms(200); 901 _delay_ms(200);
846 902
847 PORT_PI_WARNING &= ~_BV(PIN_PI_WARNING); 903 PORT_PI_WARNING &= ~_BV(PIN_PI_WARNING);
848 DDR_PI_RESET &= ~_BV(PIN_PI_RESET); 904 DDR_PI_RESET &= ~_BV(PIN_PI_RESET);
905
906 hmac_file("stuff");
849 } 907 }
850 908
851 static void 909 static void
852 wait_reboot_pi() 910 wait_reboot_pi()
853 { 911 {