static uint8_t eefs_dir_label(path_t *path, uint8_t *label) { // copy without zero-termination memcpy_P(label, disk_label, 16); return 0; }
void tft_puts_P( int x, int y, char * s, uint32_t color, uint32_t bk_color ) { y+=frame_ptr; if( !currentFont.filename ) { tft_mputs_P(x,y, s, color, bk_color); return; } #if USE_PETIT_FAT == 0 else return; #endif #if USE_PETIT_FAT == 1 char c; uint8_t gH, gW=0, gS, gIS; uint16_t offset; uint8_t startChar = currentFont.startChar; WORD s1; uint16_t pof; char fname1[13]; memset(fname1, 0, 13); memcpy_P(fname1, currentFont.filename, strlen_P( currentFont.filename)); if( pf_open(fname1) ) return; Set_color32(color); Set_bk_color32(bk_color); gH = currentFont.heightPixels; gIS = currentFont.interspacePixels; gS = currentFont.spacePixels; pf_lseek(0); pf_read(sd_buf, 2, &s1); pof = (uint16_t)(sd_buf[1]<<8) | (uint16_t)(sd_buf[0]); while( (c=pgm_read_byte(s)) ) { if( c > ' ') { pf_lseek( (uint16_t)((c-startChar)*3)+2 ); pf_read(sd_buf, 3, &s1); gW = sd_buf[0]; if( !gW ) continue; offset = (uint16_t)(sd_buf[2]<<8) | ( (uint16_t)(sd_buf[1] )); offset+=pof; pf_lseek(offset); pf_read(sd_buf, SD_BUF_SIZE, &s1); send_font_bin(x, y, gH, gW ); x = x + gW + gIS; } else { Set_active_window(x,y,x+gS-1,y+gH-1); Write_command(0x2c); for(offset=0;offset<gS*gH;offset++) { Draw_bk_pixel(); Draw_bk_pixel(); Draw_bk_pixel(); } x+=gS; } s++; } CX=x; CY=y; #endif }
/** * \brief Initializes the random number generator. * * \param tag A string that is stirred into the random pool at startup; * usually this should be a value that is unique to the application and * version such as "MyApp 1.0" so that different applications do not * generate the same sequence of values upon first boot. * \param eepromAddress The EEPROM address to load the previously saved * seed from and to save new seeds when save() is called. There must be * at least SEED_SIZE (49) bytes of EEPROM space available at the address. * * This function should be followed by calls to addNoiseSource() to * register the application's noise sources. * * The \a eepromAddress is ignored on the Arduino Due. The seed is instead * stored in the last page of system flash memory. * * \sa addNoiseSource(), stir(), save() */ void RNGClass::begin(const char *tag, int eepromAddress) { // Save the EEPROM address for use by save(). address = eepromAddress; // Initialize the ChaCha20 input block from the saved seed. memcpy_P(block, tagRNG, sizeof(tagRNG)); memcpy_P(block + 4, initRNG, sizeof(initRNG)); #if defined(RNG_EEPROM) if (eeprom_read_byte((const uint8_t *)address) == 'S') { // We have a saved seed: XOR it with the initialization block. for (int posn = 0; posn < 12; ++posn) { block[posn + 4] ^= eeprom_read_dword((const uint32_t *)(address + posn * 4 + 1)); } } #elif defined(RNG_DUE_TRNG) // Do we have a seed saved in the last page of flash memory on the Due? int posn, counter; if (((const uint32_t *)RNG_SEED_ADDR)[0] == 'S') { // XOR the saved seed with the initialization block. for (posn = 0; posn < 12; ++posn) block[posn + 4] ^= ((const uint32_t *)RNG_SEED_ADDR)[posn + 1]; } // If the device has just been reprogrammed, there will be no saved seed. // XOR the initialization block with some output from the CPU's TRNG // to permute the state in a first boot situation after reprogramming. pmc_enable_periph_clk(ID_TRNG); REG_TRNG_CR = TRNG_CR_KEY(0x524E47) | TRNG_CR_ENABLE; REG_TRNG_IDR = TRNG_IDR_DATRDY; // Disable interrupts - we will poll. for (posn = 0; posn < 12; ++posn) { // According to the documentation the TRNG should produce a new // 32-bit random value every 84 clock cycles. If it still hasn't // produced a value after 200 iterations, then assume that the // TRNG is not producing output and stop. for (counter = 0; counter < 200; ++counter) { if ((REG_TRNG_ISR & TRNG_ISR_DATRDY) != 0) break; } if (counter >= 200) break; block[posn + 4] ^= REG_TRNG_ODATA; } #endif // No entropy credits for the saved seed. credits = 0; // Trigger an automatic save once the entropy credits max out. firstSave = 1; // Rekey the random number generator immediately. rekey(); // Stir in the supplied tag data but don't credit any entropy to it. if (tag) stir((const uint8_t *)tag, strlen(tag)); #if defined(RNG_DUE_TRNG) // Stir in the unique identifier for the CPU so that different // devices will give different outputs even without seeding. stirUniqueIdentifier(); #endif // Re-save the seed to obliterate the previous value and to ensure // that if the system is reset without a call to save() that we won't // accidentally generate the same sequence of random data again. save(); }
void testrun_aes128_eax(void){ uint8_t key[16]; uint8_t nonce[16]; uint8_t header[8]; uint8_t tag[16]; uint8_t msg[21]; uint8_t msg_len; PGM_VOID_P msg_p; PGM_VOID_P cipher_p; uint8_t i, r; bcal_eax_ctx_t ctx; msg_p = eax_msg; cipher_p = eax_cipher; for(i=0; i<10; ++i){ cli_putstr_P(PSTR("\r\n\r\n** AES128-EAX-TEST #")); cli_putc('0'+i); cli_putstr_P(PSTR(" **")); msg_len = pgm_read_byte(eax_msg_len+i); memcpy_P(key, eax_key+16*i, 16); memcpy_P(nonce, eax_nonce+16*i, 16); memcpy_P(header, eax_header+8*i, 8); memcpy_P(msg, msg_p, msg_len); msg_p = (uint8_t*)msg_p+msg_len; cli_putstr_P(PSTR("\r\n key: ")); cli_hexdump(key, 16); cli_putstr_P(PSTR("\r\n msg: ")); if(msg_len){ cli_hexdump(msg, msg_len); } cli_putstr_P(PSTR("\r\n nonce: ")); cli_hexdump(nonce, 16); cli_putstr_P(PSTR("\r\n header: ")); cli_hexdump(header, 8); r = bcal_eax_init(&aes128_desc, key, 128, &ctx); cli_putstr_P(PSTR("\r\n init = 0x")); cli_hexdump(&r, 1); if(r) return; bcal_eax_loadNonce(nonce, 16*8, &ctx); bcal_eax_addLastHeader(header, 8*8, &ctx); bcal_eax_encLastBlock(msg, msg_len*8, &ctx); bcal_eax_ctx2tag(tag, 128, &ctx); cli_putstr_P(PSTR("\r\n cipher: ")); cli_hexdump_block(msg, msg_len, 4, 16); cli_putstr_P(PSTR("\r\n tag: ")); cli_hexdump_block(tag, 16, 4, 16); if(memcmp_P(msg, cipher_p, msg_len)){ cli_putstr_P(PSTR("\r\n cipher: [fail]\r\n should: ")); memcpy_P(msg, cipher_p, msg_len); cli_hexdump_block(msg, msg_len, 4, 16); }else{ cli_putstr_P(PSTR("\r\n cipher: [pass]")); } cipher_p = ((uint8_t*)cipher_p)+msg_len; // * if(memcmp_P(tag, cipher_p, 16)){ cli_putstr_P(PSTR("\r\n tag: [fail]")); }else{ cli_putstr_P(PSTR("\r\n tag: [pass]")); } cipher_p = ((uint8_t*)cipher_p)+16; bcal_eax_free(&ctx); } }
int main () { void *p; /* Fill all EEPROM. */ for (p = 0; p <= (void *)E2END; p++) eeprom_write_byte (p, (int)(p + 1)); /* Update a byte. */ { unsigned char *p = (unsigned char *)1; eeprom_update_byte (p, 2); /* the same value */ if (!eeprom_is_ready ()) exit (__LINE__); if (eeprom_read_byte (p) != 2) exit (__LINE__); eeprom_update_byte (p, 0x12); /* different value */ if (eeprom_is_ready ()) exit (__LINE__); if (eeprom_read_byte (p) != 0x12) exit (__LINE__); } /* Update a word. */ { unsigned int *p = (unsigned int *)2; eeprom_update_word (p, 0x0403); /* the same value */ if (!eeprom_is_ready ()) exit (__LINE__); if (eeprom_read_word (p) != 0x0403) exit (__LINE__); eeprom_update_word (p, 0x0413); if (eeprom_is_ready ()) exit (__LINE__); if (eeprom_read_word (p) != 0x0413) exit (__LINE__); eeprom_update_word (p, 0x1413); if (!eeprom_is_ready ()) exit (__LINE__); if (eeprom_read_word (p) != 0x1413) exit (__LINE__); } /* Update a double word. */ { unsigned long *p = (unsigned long *)4; eeprom_update_dword (p, 0x08070605); /* the same value */ if (!eeprom_is_ready ()) exit (__LINE__); if (eeprom_read_dword (p) != 0x08070605) exit (__LINE__); eeprom_update_dword (p, 0x08070615); if (eeprom_is_ready ()) exit (__LINE__); if (eeprom_read_dword (p) != 0x08070615) exit (__LINE__); eeprom_update_dword (p, 0x08071615); if (!eeprom_is_ready ()) exit (__LINE__); if (eeprom_read_dword (p) != 0x08071615) exit (__LINE__); eeprom_update_dword (p, 0x08171615); if (!eeprom_is_ready ()) exit (__LINE__); if (eeprom_read_dword (p) != 0x08171615) exit (__LINE__); eeprom_update_dword (p, 0x18171615); if (!eeprom_is_ready ()) exit (__LINE__); if (eeprom_read_dword (p) != 0x18171615) exit (__LINE__); } /* Update a block. */ { unsigned char *p = (unsigned char *)8; unsigned char s[5]; memcpy_P (s, PSTR ("\x09\x0A\x0B\x0C\x0D"), 5); eeprom_update_block (s, p, 5); if (!eeprom_is_ready ()) exit (__LINE__); memset (s, 0, sizeof (s)); eeprom_read_block (s, p, 5); if (memcmp_P (s, PSTR ("\x09\x0A\x0B\x0C\x0D"), 5)) exit (__LINE__); memcpy_P (s, PSTR ("\x19\x0A\x0B\x0C\x0D"), 5); eeprom_update_block (s, p, 5); if (eeprom_is_ready ()) exit (__LINE__); memset (s, 0, sizeof (s)); eeprom_read_block (s, p, 5); if (memcmp_P (s, PSTR ("\x19\x0A\x0B\x0C\x0D"), 5)) exit (__LINE__); memcpy_P (s, PSTR ("\x19\x0A\x0B\x0C\x1D"), 5); eeprom_update_block (s, p, 5); if (!eeprom_is_ready ()) exit (__LINE__); memset (s, 0, sizeof (s)); eeprom_read_block (s, p, 5); if (memcmp_P (s, PSTR ("\x19\x0A\x0B\x0C\x1D"), 5)) exit (__LINE__); memcpy_P (s, PSTR ("\x1A\x1B\x1C"), 3); eeprom_update_block (s, p + 1, 1); eeprom_update_block (s + 1, p + 2, 2); } /* Check all EEPROM. */ for (p = 0; p <= (void *)E2END; p++) { unsigned char c; c = (int)p + ((p && (p < (void *)13)) ? 0x11 : 1); if (eeprom_read_byte (p) != c) exit (__LINE__); } return 0; }
void copyConfigRadioFlashToRam() { memcpy_P(&rc1180ConfigRam, &rc1180ConfigFlash, sizeof(rc1180ConfigRam)); }
/** * load_directory - Prepare directory generation and create header * @secondary: secondary address used for reading the directory * * This function prepeares directory reading and fills the buffer * with the header line of the directory listing. * BUG: There is a not-well-known feature in the 1541/1571 disk * drives (and possibly others) that returns unparsed directory * sectors if $ is opened with a secondary address != 0. This * is not emulated here. */ static void load_directory(uint8_t secondary) { buffer_t *buf; path_t path; uint8_t pos=1; buf = alloc_buffer(); if (!buf) return; uint8_t *name; buf->secondary = secondary; buf->read = 1; buf->lastused = 31; if (command_length > 2 && secondary == 0) { if(command_buffer[1]=='=') { if(command_buffer[2]=='P') { /* Parse Partition Directory */ /* copy static header to start of buffer */ memcpy_P(buf->data, dirheader, sizeof(dirheader)); memcpy_P(buf->data + 32, syspart_line, sizeof(syspart_line)); buf->lastused = 63; /* set partition number */ buf->data[HEADER_OFFSET_DRIVE] = max_part; /* Let the refill callback handle everything else */ buf->refill = pdir_refill; if(command_length>3) { /* Parse the name pattern */ if (parse_path(command_buffer+3, &path, &name, 0)) return; buf->pvt.pdir.matchstr = name; } stick_buffer(buf); return; } else if(command_buffer[2]=='T') { buf->pvt.dir.format = DIR_FMT_CMD_SHORT; pos=3; } } } if (command_buffer[pos]) { /* do we have a path to scan? */ if (command_length > 2) { /* Parse the name pattern */ if (parse_path(command_buffer+pos, &path, &name, 0)) return; if (opendir(&buf->pvt.dir.dh, &path)) return; buf->pvt.dir.matchstr = name; /* Check for a filetype match */ name = ustrchr(name, '='); if (name != NULL) { *name++ = 0; switch (*name) { case 'S': buf->pvt.dir.filetype = TYPE_SEQ; break; case 'P': buf->pvt.dir.filetype = TYPE_PRG; break; case 'U': buf->pvt.dir.filetype = TYPE_USR; break; case 'R': buf->pvt.dir.filetype = TYPE_REL; break; case 'C': /* This is guessed, not verified */ buf->pvt.dir.filetype = TYPE_CBM; break; case 'B': /* CMD compatibility */ case 'D': /* Specifying DEL matches everything anyway */ buf->pvt.dir.filetype = TYPE_DIR; break; case 'H': /* Extension: Also show hidden files */ buf->pvt.dir.filetype = FLAG_HIDDEN; break; } if(buf->pvt.dir.filetype) { name++; if(*name++ != ',') { goto scandone; } } while(*name) { switch(*name++) { case '>': if(parse_date(&date_match_start,&name)) goto scandone; if(date_match_start.month && date_match_start.day) // ignore 00/00/00 buf->pvt.dir.match_start = &date_match_start; break; case '<': if(parse_date(&date_match_end,&name)) goto scandone; if(date_match_end.month && date_match_end.day) // ignore 00/00/00 buf->pvt.dir.match_end = &date_match_end; break; case 'L': /* don't switch to long format if 'N' has already been sent */ if(buf->pvt.dir.format != DIR_FMT_CBM) buf->pvt.dir.format = DIR_FMT_CMD_LONG; break; case 'N': buf->pvt.dir.format=DIR_FMT_CBM; /* turn off extended listing */ break; default: goto scandone; } if(*name && *name++ != ',') { goto scandone; } } } } else { /* Command string is two characters long, parse the drive */ if (command_buffer[1] == '0') path.part = current_part; else path.part = command_buffer[1] - '0' - 1; if (path.part >= max_part) { set_error(ERROR_DRIVE_NOT_READY); return; } path.dir = partition[path.part].current_dir; if (opendir(&buf->pvt.dir.dh, &path)) return; } } else { path.part = current_part; path.dir = partition[path.part].current_dir; // if you do not do this, get_label will fail below. if (opendir(&buf->pvt.dir.dh, &path)) return; } scandone: if (secondary != 0) { /* Raw directory */ if (partition[path.part].fop == &d64ops) { /* No need to fake it for D64 files */ d64_raw_directory(&path, buf); return; } /* prepare a fake BAM sector */ memset(buf->data, 0, 256); memset(buf->data + BAM_OFFSET_NAME - 2, 0xa0, BAM_A0_AREA_SIZE); /* fill label and id */ if (dir_label(&path, buf->data + BAM_OFFSET_NAME - 2)) return; if (disk_id(&path, buf->data + BAM_OFFSET_ID - 2)) return; /* change padding of label and id to 0xa0 */ name = buf->data + BAM_OFFSET_NAME - 2 + CBM_NAME_LENGTH; while (*--name == ' ') *name = 0xa0; if (buf->data[BAM_OFFSET_ID+2-2] == 0x20) buf->data[BAM_OFFSET_ID+2-2] = 0xa0; /* DOS version marker */ buf->data[0] = 'A'; buf->refill = rawdir_refill; buf->lastused = 253; } else { /* copy static header to start of buffer */ memcpy_P(buf->data, dirheader, sizeof(dirheader)); /* set partition number */ buf->data[HEADER_OFFSET_DRIVE] = path.part+1; /* read directory name */ if (dir_label(&path, buf->data+HEADER_OFFSET_NAME)) return; /* read id */ if (disk_id(&path,buf->data+HEADER_OFFSET_ID)) return; /* Let the refill callback handle everything else */ buf->refill = dir_refill; } /* Keep the buffer around */ stick_buffer(buf); return; }
/** * try to match the buffer with an instruction (only the first * nb_match_token tokens if != 0). Return 0 if we match all the * tokens, else the number of matched tokens, else -1. */ static int8_t match_inst(parse_pgm_inst_t *inst, const char * buf, uint8_t nb_match_token, void * result_buf) { uint8_t token_num=0; parse_pgm_token_hdr_t * token_p; uint8_t i=0; int8_t n = 0; struct token_hdr token_hdr; token_p = (parse_pgm_token_hdr_t *)pgm_read_word(&inst->tokens[token_num]); memcpy_P(&token_hdr, token_p, sizeof(token_hdr)); /* check if we match all tokens of inst */ while (token_p && (!nb_match_token || i<nb_match_token)) { debug_printf("TK\n"); /* skip spaces */ while (isblank(*buf)) { buf++; } /* end of buf */ if ( isendofline(*buf) || iscomment(*buf) ) break; n = token_hdr.ops->parse(token_p, buf, (result_buf ? result_buf+token_hdr.offset : NULL)); if ( n < 0 ) break; debug_printf("TK parsed (len=%d)\n", n); i++; buf += n; token_num ++; token_p = (parse_pgm_token_hdr_t *)pgm_read_word(&inst->tokens[token_num]); memcpy_P(&token_hdr, token_p, sizeof(token_hdr)); } /* does not match */ if (i==0) return -1; /* in case we want to match a specific num of token */ if (nb_match_token) { if (i == nb_match_token) { return 0; } return i; } /* we don't match all the tokens */ if (token_p) { return i; } /* are there are some tokens more */ while (isblank(*buf)) { buf++; } /* end of buf */ if ( isendofline(*buf) || iscomment(*buf) ) return 0; /* garbage after inst */ return i; }
const SQInfo * const sq_get_info ( size_t _index ) { memcpy_P ( &bufferedInfo, &INFO_LIST[_index], sizeof(SQInfo) ); return &bufferedInfo; }
int8_t parse(parse_pgm_ctx_t ctx[], const char * buf) { uint8_t inst_num=0; parse_pgm_inst_t * inst; const char * curbuf; char result_buf[256]; /* XXX align, size zé in broblém */ void (*f)(void *, void *) = NULL; void * data = NULL; int comment = 0; int linelen = 0; int parse_it = 0; int8_t err = PARSE_NOMATCH; int8_t tok; #ifdef CMDLINE_DEBUG char debug_buf[64]; #endif /* * - look if the buffer contains at least one line * - look if line contains only spaces or comments * - count line length */ curbuf = buf; while (! isendofline(*curbuf)) { if ( *curbuf == '\0' ) { debug_printf("Incomplete buf (len=%d)\n", linelen); return 0; } if ( iscomment(*curbuf) ) { comment = 1; } if ( ! isblank(*curbuf) && ! comment) { parse_it = 1; } curbuf++; linelen++; } /* skip all endofline chars */ while (isendofline(buf[linelen])) { linelen++; } /* empty line */ if ( parse_it == 0 ) { debug_printf("Empty line (len=%d)\n", linelen); return linelen; } #ifdef CMDLINE_DEBUG snprintf(debug_buf, (linelen>64 ? 64 : linelen), "%s", buf); debug_printf("Parse line : len=%d, <%s>\n", linelen, debug_buf); #endif /* parse it !! */ inst = (struct inst *)pgm_read_word(ctx+inst_num); while (inst) { debug_printf("INST\n"); /* fully parsed */ tok = match_inst(inst, buf, 0, result_buf); if (tok > 0) /* we matched at least one token */ err = PARSE_BAD_ARGS; else if (!tok) { debug_printf("INST fully parsed\n"); /* skip spaces */ while (isblank(*curbuf)) { curbuf++; } /* if end of buf -> there is no garbage after inst */ if (isendofline(*curbuf) || iscomment(*curbuf)) { if (!f) { memcpy_P(&f, &inst->f, sizeof(f)); memcpy_P(&data, &inst->data, sizeof(data)); } else { /* more than 1 inst matches */ err = PARSE_AMBIGUOUS; f=NULL; debug_printf("Ambiguous cmd\n"); break; } } } inst_num ++; inst = (struct inst *)pgm_read_word(ctx+inst_num); } /* call func */ if (f) { f(result_buf, data); } /* no match */ else { debug_printf("No match err=%d\n", err); return err; } return linelen; }
int8_t complete(parse_pgm_ctx_t ctx[], const char *buf, int16_t *state, char *dst, uint8_t size) { const char * incomplete_token = buf; uint8_t inst_num = 0; struct inst * inst; parse_pgm_token_hdr_t * token_p; struct token_hdr token_hdr; char tmpbuf[64], completion_buf[64]; uint8_t incomplete_token_len; int8_t completion_len = -1; int8_t nb_token = 0; uint8_t i, n; int8_t l; uint8_t nb_completable; uint8_t nb_non_completable; uint16_t local_state=0; prog_char * help_str; debug_printf("%s called\n", __FUNCTION__); /* count the number of complete token to parse */ for (i=0 ; buf[i] ; i++) { if (!isblank(buf[i]) && isblank(buf[i+1])) nb_token++; if (isblank(buf[i]) && !isblank(buf[i+1])) incomplete_token = buf+i+1; } incomplete_token_len = strlen(incomplete_token); /* first call -> do a first pass */ if (*state <= 0) { debug_printf("try complete <%s>\n", buf); debug_printf("there is %d complete tokens, <%s> is incomplete\n", nb_token, incomplete_token); nb_completable = 0; nb_non_completable = 0; inst = (struct inst *)pgm_read_word(ctx+inst_num); while (inst) { /* parse the first tokens of the inst */ if (nb_token && match_inst(inst, buf, nb_token, NULL)) goto next; debug_printf("instruction match \n"); token_p = (parse_pgm_token_hdr_t *) pgm_read_word(&inst->tokens[nb_token]); memcpy_P(&token_hdr, token_p, sizeof(token_hdr)); /* non completable */ if (!token_p || !token_hdr.ops->complete_get_nb || !token_hdr.ops->complete_get_elt || (n = token_hdr.ops->complete_get_nb(token_p)) == 0) { nb_non_completable++; goto next; } debug_printf("%d choices for this token\n", n); for (i=0 ; i<n ; i++) { if (token_hdr.ops->complete_get_elt(token_p, i, tmpbuf, sizeof(tmpbuf)-1) < 0) continue; strcat_P(tmpbuf, PSTR(" ")); /* we have at least room for one char */ debug_printf(" choice <%s>\n", tmpbuf); /* does the completion match the beginning of the word ? */ if (!strncmp(incomplete_token, tmpbuf, incomplete_token_len)) { if (completion_len == -1) { strcpy(completion_buf, tmpbuf+incomplete_token_len); completion_len = strlen(tmpbuf+incomplete_token_len); } else { completion_len = nb_common_chars(completion_buf, tmpbuf+incomplete_token_len); completion_buf[completion_len] = 0; } nb_completable++; } } next: inst_num ++; inst = (struct inst *)pgm_read_word(ctx+inst_num); } debug_printf("total choices %d for this completion\n", nb_completable); /* no possible completion */ if (nb_completable == 0 && nb_non_completable == 0) return 0; /* if multichoice is not required */ if (*state == 0 && incomplete_token_len > 0) { /* one or several choices starting with the same chars */ if (completion_len > 0) { if (completion_len + 1 > size) return 0; strcpy(dst, completion_buf); return 2; } } } /* init state correctly */ if (*state == -1) *state = 0; debug_printf("Multiple choice STATE=%d\n", *state); inst_num = 0; inst = (struct inst *)pgm_read_word(ctx+inst_num); while (inst) { /* we need to redo it */ inst = (struct inst *)pgm_read_word(ctx+inst_num); if (nb_token && match_inst(inst, buf, nb_token, NULL)) goto next2; token_p = (parse_pgm_token_hdr_t *)pgm_read_word(&inst->tokens[nb_token]); memcpy_P(&token_hdr, token_p, sizeof(token_hdr)); /* one choice for this token */ if (!token_p || !token_hdr.ops->complete_get_nb || !token_hdr.ops->complete_get_elt || (n = token_hdr.ops->complete_get_nb(token_p)) == 0) { if (local_state < *state) { local_state++; goto next2; } (*state)++; if (token_p && token_hdr.ops->get_help) { token_hdr.ops->get_help(token_p, tmpbuf, sizeof(tmpbuf)); help_str = (prog_char *) pgm_read_word(&inst->help_str); if (help_str) snprintf_P(dst, size, PSTR("[%s]: %S"), tmpbuf, help_str); else snprintf_P(dst, size, PSTR("[%s]: No help"), tmpbuf); } else { snprintf_P(dst, size, PSTR("[RETURN]")); } return 1; } /* several choices */ for (i=0 ; i<n ; i++) { if (token_hdr.ops->complete_get_elt(token_p, i, tmpbuf, sizeof(tmpbuf)-1) < 0) continue; strcat_P(tmpbuf, PSTR(" ")); /* we have at least room for one char */ debug_printf(" choice <%s>\n", tmpbuf); /* does the completion match the beginning of the word ? */ if (!strncmp(incomplete_token, tmpbuf, incomplete_token_len)) { if (local_state < *state) { local_state++; continue; } (*state)++; l=snprintf(dst, size, "%s", tmpbuf); if (l>=0 && token_hdr.ops->get_help) { token_hdr.ops->get_help(token_p, tmpbuf, sizeof(tmpbuf)); help_str = (prog_char *) pgm_read_word(&inst->help_str); if (help_str) snprintf_P(dst+l, size-l, PSTR("[%s]: %S"), tmpbuf, help_str); else snprintf_P(dst+l, size-l, PSTR("[%s]: No help"), tmpbuf); } return 1; } } next2: inst_num ++; inst = (struct inst *)pgm_read_word(ctx+inst_num); } return 0; }
int main(void) { SetupHardware(); setLed(RED); state = init; switch_port(0); DBGMSG1("Ready."); // Copy the hub descriptor into ram, vusb's // usbFunctionSetup() callback can't handle stuff // from FLASH memcpy_P(HUB_Hub_Descriptor_ram, HUB_Hub_Descriptor, sizeof(HUB_Hub_Descriptor)); for (;;) { if (port_cur == 0) HUB_Task(); if (port_cur == 5) JIG_Task(); usbPoll(); // connect 1 if (state == hub_ready && expire == 0) { DBG1(0x00, "\x1", 1); setLed(NONE); connect_port(1); state = p1_wait_reset; } if (state == p1_wait_reset && last_port_reset_clear == 1) { DBG1(0x00, "\x2", 1); setLed(RED); switch_port(1); state = p1_wait_enumerate; } // connect 2 if (state == p1_ready && expire == 0) { DBG1(0x00, "\x3", 1); setLed(NONE); switch_port(0); connect_port(2); state = p2_wait_reset; } if (state == p2_wait_reset && last_port_reset_clear == 2) { DBG1(0x00, "\x4", 1); setLed(RED); switch_port(2); state = p2_wait_enumerate; } // connect 3 if (state == p2_ready && expire == 0) { DBG1(0x00, "\x5", 1); setLed(NONE); switch_port(0); connect_port(3); state = p3_wait_reset; } if (state == p3_wait_reset && last_port_reset_clear == 3) { DBG1(0x00, "\x6", 1); setLed(RED); switch_port(3); state = p3_wait_enumerate; } // disconnect 2 if (state == p3_ready && expire == 0) { DBG1(0x00, "\x7", 1); setLed(NONE); switch_port(0); disconnect_port(2); state = p2_wait_disconnect; } if (state == p2_wait_disconnect && last_port_conn_clear == 2) { DBG1(0x00, "\x8", 1); setLed(RED); state = p4_wait_connect; expire = 15; } // connect 4 if (state == p4_wait_connect && expire == 0) { DBG1(0x00, "\x9", 1); setLed(NONE); connect_port(4); state = p4_wait_reset; } if (state == p4_wait_reset && last_port_reset_clear == 4) { DBG1(0x00, "\x10", 1); setLed(RED); switch_port(4); state = p4_wait_enumerate; } // connect 5 if (state == p4_ready && expire == 0) { DBG1(0x00, "\x11", 1); setLed(NONE); switch_port(0); /* When first connecting port 5, we need to have the wrong data toggle for the PS3 to respond */ hub_int_force_data0 = 1; connect_port(5); state = p5_wait_reset; } if (state == p5_wait_reset && last_port_reset_clear == 5) { DBG1(0x00, "\x12", 1); setLed(RED); switch_port(5); state = p5_wait_enumerate; } // disconnect 3 if (state == p5_responded && expire == 0) { DBG1(0x00, "\x13", 1); setLed(NONE); switch_port(0); /* Need wrong data toggle again */ hub_int_force_data0 = 1; disconnect_port(3); state = p3_wait_disconnect; } if (state == p3_wait_disconnect && last_port_conn_clear == 3) { DBG1(0x00, "\x14", 1); setLed(RED); state = p3_disconnected; expire = 45; } // disconnect 5 if (state == p3_disconnected && expire == 0) { DBG1(0x00, "\x15", 1); setLed(NONE); switch_port(0); disconnect_port(5); state = p5_wait_disconnect; } if (state == p5_wait_disconnect && last_port_conn_clear == 5) { DBG1(0x00, "\x16", 1); setLed(RED); state = p5_disconnected; expire = 20; } // disconnect 4 if (state == p5_disconnected && expire == 0) { DBG1(0x00, "\x17", 1); setLed(NONE); switch_port(0); disconnect_port(4); state = p4_wait_disconnect; } if (state == p4_wait_disconnect && last_port_conn_clear == 4) { DBG1(0x00, "\x18", 1); setLed(RED); state = p4_disconnected; expire = 20; } // disconnect 1 if (state == p4_disconnected && expire == 0) { DBG1(0x00, "\x19", 1); setLed(NONE); switch_port(0); disconnect_port(1); state = p1_wait_disconnect; } if (state == p1_wait_disconnect && last_port_conn_clear == 1) { DBG1(0x00, "\x20", 1); setLed(RED); state = p1_disconnected; expire = 20; } // connect 6 if (state == p1_disconnected && expire == 0) { DBG1(0x00, "\x21", 1); setLed(NONE); switch_port(0); connect_port(6); state = p6_wait_reset; } if (state == p6_wait_reset && last_port_reset_clear == 6) { DBG1(0x00, "\x22", 1); setLed(RED); switch_port(6); state = p6_wait_enumerate; } // done if (state == done) { setLed(GREEN); } } }
int16_t ecmd_parse_command(char *cmd, char *output, uint16_t len) { #ifdef DEBUG_ECMD debug_printf("called ecmd_parse_command %s\n", cmd); #endif #ifdef ECMD_LOG_VIA_SYSLOG if (0 == strchr(cmd, ECMD_STATE_MAGIC)) syslog_sendf_P(PSTR("ecmd: %s"), cmd); #endif #ifdef ECMD_REMOVE_BACKSPACE_SUPPORT uint8_t i = 0; while (cmd[i] != '\0' && cmd[i] != ECMD_STATE_MAGIC && i < ECMD_OUTPUTBUF_LENGTH) { // search until end of string if (cmd[i] == '\b') { // check cmd for backspaces uint16_t cmdlen = strlen(cmd + i); memmove(cmd + i - 1, cmd + i + 1, cmdlen); // we found a backspace, so we move all chars backwards i--; // and decrement char counter } else { i++; // goto char } } #endif /* ECMD_REMOVE_BACKSPACE_SUPPORT */ #ifdef ALIASCMD_SUPPORT if (cmd[0] == '$') { // alias command names start with $ #ifdef DEBUG_ECMD debug_printf("try alias\n"); #endif if (aliascmd_decode(cmd) == NULL) { // command not found in alias list #ifdef DEBUG_ECMD debug_printf("Alias failed\n"); #endif } else { #ifdef DEBUG_ECMD debug_printf("new command: %s\n", cmd); #endif } } #endif /* ALIASCMD_SUPPORT */ if (strlen(cmd) < 2) { #ifdef DEBUG_ECMD debug_printf("cmd is too short\n"); #endif return 0; } int ret = -1; char *text = NULL; int16_t(*func) (char *, char *, uint16_t) = NULL; uint8_t pos = 0; while (1) { /* load pointer to text */ text = (char *) pgm_read_word(&ecmd_cmds[pos].name); #ifdef DEBUG_ECMD debug_printf("loaded text addres %p: \n", text); #endif /* return if we reached the end of the array */ if (text == NULL) break; #ifdef DEBUG_ECMD debug_printf("text is: \"%S\"\n", text); #endif /* else compare texts */ if (memcmp_P(cmd, text, strlen_P(text)) == 0) { #ifdef DEBUG_ECMD debug_printf("found match\n"); #endif cmd += strlen_P(text); func = (void *) pgm_read_word(&ecmd_cmds[pos].func); break; } pos++; } #ifdef DEBUG_ECMD debug_printf("rest cmd: \"%s\"\n", cmd); #endif ACTIVITY_LED_ECMD; if (func != NULL) ret = func(cmd, output, len); if (output != NULL) { if (ret == -1) { memcpy_P(output, PSTR("parse error"), 11); ret = 11; } else if (ret == 0) { output[0] = 'O'; output[1] = 'K'; ret = 2; } } return ret; }
static uint8_t eefs_disk_id(path_t *path, uint8_t *id) { memcpy_P(id, disk_id, 5); return 0; }
/** * Copy a raster picture located in program memory in the bitmap. * The size of the raster to copy *must* be the same of the raster bitmap. * * \note This function does \b not update the current pen position */ void gfx_blit_P(Bitmap *bm, const pgm_uint8_t *raster) { memcpy_P(bm->raster, raster, RAST_SIZE(bm->width, bm->height)); }
const SQCallableInfo * const sq_get_callable_info ( size_t _index ) { memcpy_P ( &bufferedCallableInfo, &CALLABLE_LIST[_index], sizeof(SQCallableInfo) ); return &bufferedCallableInfo; }
/** @brief Analyse HTTP request and then services WEB. */ void process_HTTP( SOCKET s, /**< http server socket */ uint8_t * buffer, /**< buffer pointer included http request */ uint16_t length /**< length of http request */ ) { uint8_t * name; uint16_t bytes_read; TickType_t wait_send; FIL source_file; /* File object for the source file */ parse_HTTP_request(pHTTPRequest, buffer); // After analysing request, convert into pHTTPRequest /* method Analyse */ switch (pHTTPRequest->METHOD) { case METHOD_HEAD: case METHOD_GET : case METHOD_POST : name = get_HTTP_URI_name(pHTTPRequest->URI); if (!strcmp((const char *)name, "/")) strcpy((char *)name,"index.htm"); // If URI is "/", respond by index.htm #ifdef WEB_DEBUG if(strlen( (const char *)name) < MAX_INT_STR ) xSerialPrintf_P(PSTR("\r\nPAGE : %s "), name); else xSerialPrint_P(PSTR("\r\nFILENAME TOO LONG")); #endif find_HTTP_URI_type(&pHTTPRequest->TYPE, name); //Check file type (HTML, TEXT, ICO, GIF, JPEG, ZIP are included) // OK now we start to respond to the info we've decoded. /* Open the specified file stored in the SD card FAT32 */ if (f_open(&source_file, (const TCHAR *)name, FA_OPEN_EXISTING | FA_READ)) { // if file open failure memcpy_P( (char *)pHTTPResponse, ERROR_HTML_PAGE, strnlen_P(ERROR_HTML_PAGE, FILE_BUFFER_SIZE) ); #ifdef WEB_DEBUG xSerialPrint_P(PSTR("HTTP Unknown file or page.\r\n")); xSerialPrintf_P(PSTR("HTTP Response...\r\n%s\r\nResponse Size: %u \r\n"), pHTTPResponse, strlen_P(ERROR_HTML_PAGE)); #endif send( s, (const uint8_t*)pHTTPResponse, strlen_P(ERROR_HTML_PAGE)); } else { // if file open success make_HTTP_response_header( pHTTPResponse, pHTTPRequest->TYPE, source_file.fsize); #ifdef WEB_DEBUG xSerialPrintf_P(PSTR("HTTP Opened file: %s Source Size: %u \r\n"), name, source_file.fsize); xSerialPrintf_P(PSTR("HTTP Response Header...\r\n%s\r\nResponse Header Size: %u \r\n"), pHTTPResponse, strlen((char*)pHTTPResponse )); #endif send(s, (const uint8_t*)pHTTPResponse, strlen((char*)pHTTPResponse )); wait_send = xTaskGetTickCount(); while(getSn_TX_FSR(s)!= WIZCHIP_getTxMAX(s)) { if( (xTaskGetTickCount() - wait_send) > (WEBSERVER_SOCKET_TIMEOUT / portTICK_PERIOD_MS) ) // wait up to 1.5 Sec { #ifdef WEB_DEBUG xSerialPrint_P(PSTR("HTTP Response head send fail\r\n")); #endif break; } vTaskDelay( 0 ); // yield until next tick. } for (;;) { if ( f_read(&source_file, pHTTPResponse, (sizeof(uint8_t)*(FILE_BUFFER_SIZE) ), &bytes_read) || bytes_read == 0 ) break; // read error or reached end of file if(pHTTPRequest->TYPE == PTYPE_HTML) // if we've got a html document, there might be some system variables to set { *(pHTTPResponse + bytes_read + 1) = 0; // make the buffer a string, null terminated bytes_read = replace_sys_env_value(pHTTPResponse, bytes_read); // Replace html system environment value to real value } if (send(s, (const uint8_t*)pHTTPResponse, bytes_read) != bytes_read) break; // TCP/IP send error wait_send = xTaskGetTickCount(); while(getSn_TX_FSR(s)!= WIZCHIP_getTxMAX(s)) { if( (xTaskGetTickCount() - wait_send) > (WEBSERVER_SOCKET_TIMEOUT / portTICK_PERIOD_MS) ) // wait up to 1.5 Sec { #ifdef WEB_DEBUG xSerialPrint_P(PSTR("HTTP Response body send fail\r\n")); #endif break; } vTaskDelay( 0 ); // yield until next tick. } } f_close(&source_file); eeprom_busy_wait(); eeprom_update_dword( &pagesServed, eeprom_read_dword(&pagesServed) +1 ); } break; case METHOD_ERR : memcpy_P( (char *)pHTTPResponse, ERROR_REQUEST_PAGE, strnlen_P(ERROR_REQUEST_PAGE, FILE_BUFFER_SIZE) ); #ifdef WEB_DEBUG xSerialPrint_P(PSTR("HTTP Method Error.\r\n")); xSerialPrintf_P(PSTR("HTTP Response...\r\n%s\r\nResponse Size: %u \r\n"), pHTTPResponse, strlen_P(ERROR_REQUEST_PAGE)); #endif send( s, (const uint8_t*)pHTTPResponse, strlen_P(ERROR_REQUEST_PAGE)); break; default : break; } }
const SQPropertyInfo * const sq_get_property_info ( size_t _index ) { memcpy_P ( &bufferedPropertyInfo, &PROPERTY_LIST[_index], sizeof(SQPropertyInfo) ); return &bufferedPropertyInfo; }
/** * createentry - create a single directory entry in buf * @dent : directory entry to be added * @buf : buffer to be used * @format: entry format * * This function creates a directory entry for dent in the selected format * in the given buffer. */ static void createentry(cbmdirent_t *dent, buffer_t *buf, dirformat_t format) { uint8_t i; uint8_t *data = buf->data; if(format == DIR_FMT_CMD_LONG) i=63; else if(format == DIR_FMT_CMD_SHORT) i=41; else i=31; buf->lastused = i; /* Clear the line */ memset(data, ' ', i); /* Line end marker */ data[i] = 0; /* Next line pointer, 1571-compatible =) */ if (dent->remainder != 0xff) /* store remainder in low byte of link pointer */ /* +2 so it is never 0 (end-marker) or 1 (normal value) */ *data++ = dent->remainder+2; else *data++ = 1; *data++ = 1; *data++ = dent->blocksize & 0xff; *data++ = dent->blocksize >> 8; /* Filler before file name */ data++; if (dent->blocksize < 100) data++; if (dent->blocksize < 10) data++; *data++ = '"'; /* copy and adjust the filename - C783 */ memcpy(data, dent->name, CBM_NAME_LENGTH); for (i=0;i<=CBM_NAME_LENGTH;i++) if (dent->name[i] == 0x22 || dent->name[i] == 0 || i == 16) { data[i] = '"'; while (i<=CBM_NAME_LENGTH) { if (data[i] == 0) data[i] = ' '; else data[i] &= 0x7f; i++; } } /* Skip name and final quote */ data += CBM_NAME_LENGTH+1; if (dent->typeflags & FLAG_SPLAT) *data = '*'; /* File type */ memcpy_P(data+1, filetypes + TYPE_LENGTH * (dent->typeflags & EXT_TYPE_MASK), (format & DIR_FMT_CMD_SHORT) ? 1 : TYPE_LENGTH); /* RO marker */ if (dent->typeflags & FLAG_RO) data[4] = '<'; if(format & DIR_FMT_CMD_LONG) { data += 7; data = appendnumber(data,dent->date.month); *data++ = '/'; data = appendnumber(data,dent->date.day); *data++ = '/'; data = appendnumber(data,dent->date.year % 100) + 3; data = appendnumber(data,(dent->date.hour>12?dent->date.hour-12:dent->date.hour)); *data++ = '.'; data = appendnumber(data,dent->date.minute) + 1; *data++ = (dent->date.hour>11?'P':'A'); *data++ = 'M'; while (*data) *data++ = 1; } else if(format == DIR_FMT_CMD_SHORT) { /* Add date/time stamp */ data+=3; data = appendnumber(data,dent->date.month); *data++ = '/'; data = appendnumber(data,dent->date.day) + 1; data = appendnumber(data,(dent->date.hour>12?dent->date.hour-12:dent->date.hour)); *data++ = '.'; data = appendnumber(data,dent->date.minute) + 1; *data++ = (dent->date.hour>11?'P':'A'); while(*data) *data++ = 1; } else { /* Extension: Hidden marker */ if (dent->typeflags & FLAG_HIDDEN) data[5] = 'H'; } }
const SQMonitorInfo * const sq_get_monitor_info ( size_t _index ) { memcpy_P ( &bufferedMonitorInfo, &MONITOR_LIST[_index], sizeof(SQMonitorInfo) ); return &bufferedMonitorInfo; }
void testrun_aes128_cfb1(void){ uint8_t key[16]; uint8_t iv[16]; uint8_t plain[64]; bcal_cfb_b_ctx_t ctx; uint8_t r; memcpy_P(key, modes_key, 16); memcpy_P(iv, modes_iv, 16); memcpy_P(plain, modes_plain, 64); cli_putstr_P(PSTR("\r\n** AES128-CFB1-TEST **")); r = bcal_cfb_b_init(&aes128_desc, key, 128, 1, &ctx); cli_putstr_P(PSTR("\r\n init = 0x")); cli_hexdump(&r, 1); cli_putstr_P(PSTR("\r\n key: ")); cli_hexdump(key, 128/8); cli_putstr_P(PSTR("\r\n IV: ")); cli_hexdump(iv, 128/8); cli_putstr_P(PSTR("\r\n plaintext:")); cli_hexdump_block(plain, 2, 4, 16); if(r) return; uint8_t i, bit_offset, byte_offset; bcal_cfb_b_loadIV(iv, &ctx); for(i=0; i<16; ++i){ byte_offset = i/8; bit_offset = i&7; cli_putstr_P(PSTR("\r\n plain bit: ")); cli_putc((plain[byte_offset]&(1<<(7-bit_offset)))?'1':'0'); bcal_cfb_b_encNext(plain+byte_offset, bit_offset, &ctx); cli_putstr_P(PSTR("\r\n cipher bit: ")); cli_putc((plain[byte_offset]&(1<<(7-bit_offset)))?'1':'0'); } cli_putstr_P(PSTR("\r\n ciphertext: ")); cli_hexdump_block(plain, 2, 4, 16); bcal_cfb_b_loadIV(iv, &ctx); for(i=0; i<16; ++i){ byte_offset = i/8; bit_offset = i&7; cli_putstr_P(PSTR("\r\n plain bit: ")); cli_putc((plain[byte_offset]&(1<<(7-bit_offset)))?'1':'0'); bcal_cfb_b_decNext(plain+byte_offset, bit_offset, &ctx); cli_putstr_P(PSTR("\r\n cipher bit: ")); cli_putc((plain[byte_offset]&(1<<(7-bit_offset)))?'1':'0'); } cli_putstr_P(PSTR("\r\n plaintext: ")); cli_hexdump_block(plain, 2, 4, 16); bcal_cfb_b_encMsg(iv, plain, 0, 64*8, &ctx); cli_putstr_P(PSTR("\r\n ciphertext: ")); cli_hexdump_block(plain, 64, 4, 16); bcal_cfb_b_decMsg(iv, plain, 0, 64*8, &ctx); cli_putstr_P(PSTR("\r\n plaintext: ")); cli_hexdump_block(plain, 64, 4, 16); bcal_cfb_b_free(&ctx); }
/************************************************************************************************** * Handle received HID set feature reports */ void HID_set_feature_report_out(uint8_t *report) { uint8_t response[UDI_HID_REPORT_OUT_SIZE]; response[0] = report[0] | 0x80; response[1] = report[1]; response[2] = report[2]; uint16_t addr; addr = *(uint16_t *)(report+1); switch(report[0]) { // no-op case CMD_NOP: break; // write to RAM page buffer case CMD_RESET_POINTER: page_ptr = 0; return; // read from RAM page buffer case CMD_READ_BUFFER: memcpy(response, &page_buffer[page_ptr], UDI_HID_REPORT_OUT_SIZE); page_ptr += UDI_HID_REPORT_OUT_SIZE; page_ptr &= APP_SECTION_PAGE_SIZE-1; break; // erase entire application section case CMD_ERASE_APP_SECTION: SP_WaitForSPM(); SP_EraseApplicationSection(); return; // calculate application and bootloader section CRCs case CMD_READ_FLASH_CRCS: SP_WaitForSPM(); *(uint32_t *)&response[3] = SP_ApplicationCRC(); *(uint32_t *)&response[7] = SP_BootCRC(); break; // read MCU IDs case CMD_READ_MCU_IDS: response[3] = MCU.DEVID0; response[4] = MCU.DEVID1; response[5] = MCU.DEVID2; response[6] = MCU.REVID; break; // read fuses case CMD_READ_FUSES: response[3] = SP_ReadFuseByte(0); response[4] = SP_ReadFuseByte(1); response[5] = SP_ReadFuseByte(2); response[6] = 0xFF; response[7] = SP_ReadFuseByte(4); response[8] = SP_ReadFuseByte(5); break; // write RAM page buffer to application section page case CMD_WRITE_PAGE: if (addr > (APP_SECTION_SIZE / APP_SECTION_PAGE_SIZE)) // out of range { response[1] = 0xFF; response[2] = 0xFF; break; } SP_WaitForSPM(); SP_LoadFlashPage(page_buffer); SP_WriteApplicationPage(APP_SECTION_START + ((uint32_t)addr * APP_SECTION_PAGE_SIZE)); page_ptr = 0; break; // read application page to RAM buffer and return first 32 bytes case CMD_READ_PAGE: if (addr > (APP_SECTION_SIZE / APP_SECTION_PAGE_SIZE)) // out of range { response[1] = 0xFF; response[2] = 0xFF; } else { memcpy_P(page_buffer, (const void *)(APP_SECTION_START + (APP_SECTION_PAGE_SIZE * addr)), APP_SECTION_PAGE_SIZE); memcpy(&response[3], page_buffer, 32); page_ptr = 0; } break; // erase user signature row case CMD_ERASE_USER_SIG_ROW: SP_WaitForSPM(); SP_EraseUserSignatureRow(); break; // write RAM buffer to user signature row case CMD_WRITE_USER_SIG_ROW: SP_WaitForSPM(); SP_LoadFlashPage(page_buffer); SP_WriteUserSignatureRow(); break; // read user signature row to RAM buffer and return first 32 bytes case CMD_READ_USER_SIG_ROW: if (addr > (USER_SIGNATURES_PAGE_SIZE - 32)) { response[1] = 0xFF; response[2] = 0xFF; } else { memcpy_P(page_buffer, (const void *)(USER_SIGNATURES_START + addr), USER_SIGNATURES_SIZE); memcpy(&response[3], page_buffer, 32); page_ptr = 0; } break; case CMD_READ_SERIAL: { uint8_t i; uint8_t j = 3; uint8_t b; for (i = 0; i < 6; i++) { b = SP_ReadCalibrationByte(offsetof(NVM_PROD_SIGNATURES_t, LOTNUM0) + i); response[j++] = hex_to_char(b >> 4); response[j++] = hex_to_char(b & 0x0F); } response[j++] = '-'; b = SP_ReadCalibrationByte(offsetof(NVM_PROD_SIGNATURES_t, LOTNUM0) + 6); response[j++] = hex_to_char(b >> 4); response[j++] = hex_to_char(b & 0x0F); response[j++] = '-'; for (i = 7; i < 11; i++) { b = SP_ReadCalibrationByte(offsetof(NVM_PROD_SIGNATURES_t, LOTNUM0) + i); response[j++] = hex_to_char(b >> 4); response[j++] = hex_to_char(b & 0x0F); } response[j] = '\0'; break; } case CMD_READ_BOOTLOADER_VERSION: response[3] = BOOTLOADER_VERSION; break; case CMD_RESET_MCU: reset_do_soft_reset(); response[1] = 0xFF; // failed break; case CMD_READ_EEPROM: if (addr > (EEPROM_SIZE - 32)) { response[1] = 0xFF; response[2] = 0xFF; } else { EEP_EnableMapping(); memcpy_P(page_buffer, (const void *)(MAPPED_EEPROM_START + addr), APP_SECTION_PAGE_SIZE); EEP_DisableMapping(); memcpy(&response[3], page_buffer, 32); page_ptr = 0; } break; case CMD_WRITE_EEPROM: if (addr > (EEPROM_SIZE / EEPROM_PAGE_SIZE)) { response[1] = 0xFF; response[2] = 0xFF; } else { EEP_LoadPageBuffer(&report[3], EEPROM_PAGE_SIZE); EEP_AtomicWritePage(addr); } break; // unknown command default: response[0] = 0xFF; break; } udi_hid_generic_send_report_in(response); }
void zg_drv_process() { // TX frame if (tx_ready && !cnf_pending) { zg_send(zg_buf, zg_buf_len); tx_ready = 0; cnf_pending = 1; } // process interrupt if (intr_occured) { zg_process_isr(); } if (intr_valid) { switch (zg_buf[1]) { case ZG_MAC_TYPE_TXDATA_CONFIRM: cnf_pending = 0; break; case ZG_MAC_TYPE_MGMT_CONFIRM: if (zg_buf[3] == ZG_RESULT_SUCCESS) { switch (zg_buf[2]) { case ZG_MAC_SUBTYPE_MGMT_REQ_GET_PARAM: mac[0] = zg_buf[7]; mac[1] = zg_buf[8]; mac[2] = zg_buf[9]; mac[3] = zg_buf[10]; mac[4] = zg_buf[11]; mac[5] = zg_buf[12]; zg_drv_state = DRV_STATE_SETUP_SECURITY; break; case ZG_MAC_SUBTYPE_MGMT_REQ_WEP_KEY: zg_drv_state = DRV_STATE_ENABLE_CONN_MANAGE; break; case ZG_MAC_SUBTYPE_MGMT_REQ_CALC_PSK: memcpy(wpa_psk_key, ((zg_psk_calc_cnf_t*)&zg_buf[3])->psk, 32); zg_drv_state = DRV_STATE_INSTALL_PSK; break; case ZG_MAC_SUBTYPE_MGMT_REQ_PMK_KEY: zg_drv_state = DRV_STATE_ENABLE_CONN_MANAGE; break; case ZG_MAC_SUBTYPE_MGMT_REQ_CONNECT_MANAGE: zg_drv_state = DRV_STATE_START_CONN; break; case ZG_MAC_SUBTYPE_MGMT_REQ_CONNECT: LEDConn_on(); zg_conn_status = 1; // connected break; default: break; } } break; case ZG_MAC_TYPE_RXDATA_INDICATE: zg_drv_state = DRV_STATE_PROCESS_RX; break; case ZG_MAC_TYPE_MGMT_INDICATE: switch (zg_buf[2]) { case ZG_MAC_SUBTYPE_MGMT_IND_DISASSOC: case ZG_MAC_SUBTYPE_MGMT_IND_DEAUTH: LEDConn_off(); zg_conn_status = 0; // lost connection //try to reconnect zg_drv_state = DRV_STATE_START_CONN; break; case ZG_MAC_SUBTYPE_MGMT_IND_CONN_STATUS: { U16 status = (((U16)(zg_buf[3]))<<8)|zg_buf[4]; if (status == 1 || status == 5) { LEDConn_off(); zg_conn_status = 0; // not connected } else if (status == 2 || status == 6) { LEDConn_on(); zg_conn_status = 1; // connected } } break; } break; } intr_valid = 0; } switch (zg_drv_state) { case DRV_STATE_INIT: zg_drv_state = DRV_STATE_GET_MAC; break; case DRV_STATE_GET_MAC: // get MAC address zg_buf[0] = ZG_CMD_WT_FIFO_MGMT; zg_buf[1] = ZG_MAC_TYPE_MGMT_REQ; zg_buf[2] = ZG_MAC_SUBTYPE_MGMT_REQ_GET_PARAM; zg_buf[3] = 0; zg_buf[4] = ZG_PARAM_MAC_ADDRESS; spi_transfer(zg_buf, 5, 1); zg_buf[0] = ZG_CMD_WT_FIFO_DONE; spi_transfer(zg_buf, 1, 1); zg_drv_state = DRV_STATE_IDLE; break; case DRV_STATE_SETUP_SECURITY: switch (security_type) { case ZG_SECURITY_TYPE_NONE: zg_drv_state = DRV_STATE_ENABLE_CONN_MANAGE; break; case ZG_SECURITY_TYPE_WEP: // Install all four WEP keys on G2100 zg_buf[0] = ZG_CMD_WT_FIFO_MGMT; zg_buf[1] = ZG_MAC_TYPE_MGMT_REQ; zg_buf[2] = ZG_MAC_SUBTYPE_MGMT_REQ_WEP_KEY; zg_write_wep_key(&zg_buf[3]); spi_transfer(zg_buf, ZG_WEP_KEY_REQ_SIZE+3, 1); zg_buf[0] = ZG_CMD_WT_FIFO_DONE; spi_transfer(zg_buf, 1, 1); zg_drv_state = DRV_STATE_IDLE; break; case ZG_SECURITY_TYPE_WPA: case ZG_SECURITY_TYPE_WPA2: // Initiate PSK calculation on G2100 zg_buf[0] = ZG_CMD_WT_FIFO_MGMT; zg_buf[1] = ZG_MAC_TYPE_MGMT_REQ; zg_buf[2] = ZG_MAC_SUBTYPE_MGMT_REQ_CALC_PSK; zg_calc_psk_key(&zg_buf[3]); spi_transfer(zg_buf, ZG_PSK_CALC_REQ_SIZE+3, 1); zg_buf[0] = ZG_CMD_WT_FIFO_DONE; spi_transfer(zg_buf, 1, 1); zg_drv_state = DRV_STATE_IDLE; break; default: break; } break; case DRV_STATE_INSTALL_PSK: // Install the PSK key on G2100 zg_buf[0] = ZG_CMD_WT_FIFO_MGMT; zg_buf[1] = ZG_MAC_TYPE_MGMT_REQ; zg_buf[2] = ZG_MAC_SUBTYPE_MGMT_REQ_PMK_KEY; zg_write_psk_key(&zg_buf[3]); spi_transfer(zg_buf, ZG_PMK_KEY_REQ_SIZE+3, 1); zg_buf[0] = ZG_CMD_WT_FIFO_DONE; spi_transfer(zg_buf, 1, 1); zg_drv_state = DRV_STATE_IDLE; break; case DRV_STATE_ENABLE_CONN_MANAGE: // enable connection manager zg_buf[0] = ZG_CMD_WT_FIFO_MGMT; zg_buf[1] = ZG_MAC_TYPE_MGMT_REQ; zg_buf[2] = ZG_MAC_SUBTYPE_MGMT_REQ_CONNECT_MANAGE; zg_buf[3] = 0x01; // 0x01 - enable; 0x00 - disable zg_buf[4] = 10; // num retries to reconnect zg_buf[5] = 0x10 | 0x02 | 0x01; // 0x10 - enable start and stop indication messages // from G2100 during reconnection // 0x02 - start reconnection on receiving a deauthentication // message from the AP // 0x01 - start reconnection when the missed beacon count // exceeds the threshold. uses default value of // 100 missed beacons if not set during initialization zg_buf[6] = 0; spi_transfer(zg_buf, 7, 1); zg_buf[0] = ZG_CMD_WT_FIFO_DONE; spi_transfer(zg_buf, 1, 1); zg_drv_state = DRV_STATE_IDLE; break; case DRV_STATE_START_CONN: { zg_connect_req_t* cmd = (zg_connect_req_t*)&zg_buf[3]; // start connection to AP zg_buf[0] = ZG_CMD_WT_FIFO_MGMT; zg_buf[1] = ZG_MAC_TYPE_MGMT_REQ; zg_buf[2] = ZG_MAC_SUBTYPE_MGMT_REQ_CONNECT; cmd->secType = security_type; cmd->ssidLen = ssid_len; memset(cmd->ssid, 0, 32); memcpy_P(cmd->ssid, ssid, ssid_len); // units of 100 milliseconds cmd->sleepDuration = 0; if (wireless_mode == WIRELESS_MODE_INFRA) cmd->modeBss = 1; else if (wireless_mode == WIRELESS_MODE_ADHOC) cmd->modeBss = 2; spi_transfer(zg_buf, ZG_CONNECT_REQ_SIZE+3, 1); zg_buf[0] = ZG_CMD_WT_FIFO_DONE; spi_transfer(zg_buf, 1, 1); zg_drv_state = DRV_STATE_IDLE; break; } case DRV_STATE_PROCESS_RX: zg_recv(zg_buf, &zg_buf_len); rx_ready = 1; zg_drv_state = DRV_STATE_IDLE; break; case DRV_STATE_IDLE: break; } }
static void dispatch_out(void) { // update latest serial received if (out_packet_ptr) { in_packet[0] = out_packet[0]; if (in_packet_ptr == 0) { in_packet_ptr = 1; } } unsigned char ptr = 1; while (ptr < out_packet_ptr) { unsigned char code = out_packet[ptr]; ++ptr; unsigned char sz = code & 0xf; if (sz == 15) { if (ptr == out_packet_ptr) { goto too_big; } sz = out_packet[ptr]; ++ptr; } if (ptr + sz > out_packet_ptr || ptr + sz < ptr) { too_big: MY_Failure("Too big recv", ptr + sz, out_packet_ptr); } unsigned char code_ix = (code & 0xf0) >> 4; if (code_ix >= sizeof(min_size)) { unknown_op: MY_Failure("Unknown op", code & 0xf0, sz); } unsigned char msz = 0; memcpy_P(&msz, &min_size[code_ix], 1); if (sz < msz) { MY_Failure("Too small data", sz, code); } unsigned char *base = &out_packet[ptr]; switch (code & 0xf0) { case OpSetStatus: set_status(base[0], sz-1, base+1); break; case OpGetStatus: get_status(base[0]); break; case OpWriteServo: write_servo(base[0], base[1], sz-2, base+2); break; case OpReadServo: read_servo(base[0], base[1], base[2]); break; case OpOutText: out_text(sz, base); break; case OpRawWrite: raw_write(sz, base); break; case OpRawRead: raw_read(base[0]); break; default: goto unknown_op; } ptr += sz; } }
// Send the Panasonic DKE/JKE/NKE code void PanasonicHeatpumpIR::sendPanasonic(IRSender& IR, byte operatingMode, byte fanSpeed, byte temperature, byte swingV, byte swingH) { // Only bytes 13, 14, 16, 17 and 26 are modified, DKE and JKE seem to share the same template? static const prog_uint8_t panasonicProgmemTemplate[][27] PROGMEM = { // DKE, model 0 { 0x02, 0x20, 0xE0, 0x04, 0x00, 0x00, 0x00, 0x06, 0x02, 0x20, 0xE0, 0x04, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x0E, 0xE0, 0x00, 0x00, 0x01, 0x00, 0x06, 0x00 }, // JKE, model 1 { 0x02, 0x20, 0xE0, 0x04, 0x00, 0x00, 0x00, 0x06, 0x02, 0x20, 0xE0, 0x04, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x0E, 0xE0, 0x00, 0x00, 0x81, 0x00, 0x00, 0x00 }, // NKE, model 2 { 0x02, 0x20, 0xE0, 0x04, 0x00, 0x00, 0x00, 0x06, 0x02, 0x20, 0xE0, 0x04, 0x00, 0x00, 0x00, 0x80, 0x00, 0x06, 0x00, 0x0E, 0xE0, 0x00, 0x00, 0x81, 0x00, 0x00, 0x00 } // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 }; // Save some SRAM by only having one copy of the template on the SRAM byte panasonicTemplate[27]; memcpy_P(panasonicTemplate, panasonicProgmemTemplate[_panasonicModel], sizeof(panasonicTemplate)); panasonicTemplate[13] = operatingMode; panasonicTemplate[14] = temperature << 1; panasonicTemplate[16] = fanSpeed | swingV; // Only the DKE model has a setting for the horizontal air flow if ( _panasonicModel == PANASONIC_DKE) { panasonicTemplate[17] = swingH; } // Checksum calculation byte checksum = 0xF4; for (int i=0; i<26; i++) { checksum += panasonicTemplate[i]; } panasonicTemplate[26] = checksum; // 40 kHz PWM frequency IR.setFrequency(40); // Header IR.mark(PANASONIC_AIRCON2_HDR_MARK); IR.space(PANASONIC_AIRCON2_HDR_SPACE); // First 8 bytes for (int i=0; i<8; i++) { IR.sendIRByte(panasonicTemplate[i], PANASONIC_AIRCON2_BIT_MARK, PANASONIC_AIRCON2_ZERO_SPACE, PANASONIC_AIRCON2_ONE_SPACE); } // Pause IR.mark(PANASONIC_AIRCON2_BIT_MARK); IR.space(PANASONIC_AIRCON2_MSG_SPACE); // Header IR.mark(PANASONIC_AIRCON2_HDR_MARK); IR.space(PANASONIC_AIRCON2_HDR_SPACE); // Last 19 bytes for (int i=8; i<27; i++) { IR.sendIRByte(panasonicTemplate[i], PANASONIC_AIRCON2_BIT_MARK, PANASONIC_AIRCON2_ZERO_SPACE, PANASONIC_AIRCON2_ONE_SPACE); } IR.mark(PANASONIC_AIRCON2_BIT_MARK); IR.space(0); }
static bool RNDIS_Device_ProcessNDISQuery(USB_ClassInfo_RNDIS_Device_t* const RNDISInterfaceInfo, const uint32_t OId, void* const QueryData, const uint16_t QuerySize, void* ResponseData, uint16_t* const ResponseSize) { (void)QueryData; (void)QuerySize; switch (OId) { case OID_GEN_SUPPORTED_LIST: *ResponseSize = sizeof(AdapterSupportedOIDList); memcpy_P(ResponseData, AdapterSupportedOIDList, sizeof(AdapterSupportedOIDList)); return true; case OID_GEN_PHYSICAL_MEDIUM: *ResponseSize = sizeof(uint32_t); /* Indicate that the device is a true ethernet link */ *((uint32_t*)ResponseData) = 0; return true; case OID_GEN_HARDWARE_STATUS: *ResponseSize = sizeof(uint32_t); *((uint32_t*)ResponseData) = NDIS_HardwareStatus_Ready; return true; case OID_GEN_MEDIA_SUPPORTED: case OID_GEN_MEDIA_IN_USE: *ResponseSize = sizeof(uint32_t); *((uint32_t*)ResponseData) = REMOTE_NDIS_MEDIUM_802_3; return true; case OID_GEN_VENDOR_ID: *ResponseSize = sizeof(uint32_t); /* Vendor ID 0x0xFFFFFF is reserved for vendors who have not purchased a NDIS VID */ *((uint32_t*)ResponseData) = 0x00FFFFFF; return true; case OID_GEN_MAXIMUM_FRAME_SIZE: case OID_GEN_TRANSMIT_BLOCK_SIZE: case OID_GEN_RECEIVE_BLOCK_SIZE: *ResponseSize = sizeof(uint32_t); *((uint32_t*)ResponseData) = ETHERNET_FRAME_SIZE_MAX; return true; case OID_GEN_VENDOR_DESCRIPTION: *ResponseSize = (strlen(RNDISInterfaceInfo->Config.AdapterVendorDescription) + 1); memcpy(ResponseData, RNDISInterfaceInfo->Config.AdapterVendorDescription, *ResponseSize); return true; case OID_GEN_MEDIA_CONNECT_STATUS: *ResponseSize = sizeof(uint32_t); *((uint32_t*)ResponseData) = REMOTE_NDIS_MEDIA_STATE_CONNECTED; return true; case OID_GEN_LINK_SPEED: *ResponseSize = sizeof(uint32_t); /* Indicate 10Mb/s link speed */ *((uint32_t*)ResponseData) = 100000; return true; case OID_802_3_PERMANENT_ADDRESS: case OID_802_3_CURRENT_ADDRESS: *ResponseSize = sizeof(MAC_Address_t); memcpy(ResponseData, &RNDISInterfaceInfo->Config.AdapterMACAddress, sizeof(MAC_Address_t)); return true; case OID_802_3_MAXIMUM_LIST_SIZE: *ResponseSize = sizeof(uint32_t); /* Indicate only one multicast address supported */ *((uint32_t*)ResponseData) = 1; return true; case OID_GEN_CURRENT_PACKET_FILTER: *ResponseSize = sizeof(uint32_t); *((uint32_t*)ResponseData) = RNDISInterfaceInfo->State.CurrPacketFilter; return true; case OID_GEN_XMIT_OK: case OID_GEN_RCV_OK: case OID_GEN_XMIT_ERROR: case OID_GEN_RCV_ERROR: case OID_GEN_RCV_NO_BUFFER: case OID_802_3_RCV_ERROR_ALIGNMENT: case OID_802_3_XMIT_ONE_COLLISION: case OID_802_3_XMIT_MORE_COLLISIONS: *ResponseSize = sizeof(uint32_t); /* Unused statistic OIDs - always return 0 for each */ *((uint32_t*)ResponseData) = 0; return true; case OID_GEN_MAXIMUM_TOTAL_SIZE: *ResponseSize = sizeof(uint32_t); /* Indicate maximum overall buffer (Ethernet frame and RNDIS header) the adapter can handle */ *((uint32_t*)ResponseData) = (RNDIS_MESSAGE_BUFFER_SIZE + ETHERNET_FRAME_SIZE_MAX); return true; default: return false; } }
void dds_select_wave(uint8_t wave_idx) { memcpy_P(wave_buffer, wave_table[wave_idx], 256); }
/** Processes RNDIS query commands, retrieving information from the adapter and reporting it back to the host. The requested * parameter is given as an OID value. * * \param[in] OId OId value of the parameter being queried * \param[in] QueryData Pointer to any extra query data being sent by the host to the device inside the RNDIS message buffer * \param[in] QuerySize Size in bytes of the extra query data being sent by the host * \param[out] ResponseData Pointer to the start of the query response inside the RNDIS message buffer * \param[out] ResponseSize Pointer to the size in bytes of the response data being sent to the host * * \return Boolean \c true if the query was handled, \c false otherwise */ static bool ProcessNDISQuery(const uint32_t OId, void* QueryData, uint16_t QuerySize, void* ResponseData, uint16_t* ResponseSize) { /* Handler for REMOTE_NDIS_QUERY_MSG messages */ switch (OId) { case OID_GEN_SUPPORTED_LIST: *ResponseSize = sizeof(AdapterSupportedOIDList); /* Copy the list of supported NDIS OID tokens to the response buffer */ memcpy_P(ResponseData, AdapterSupportedOIDList, sizeof(AdapterSupportedOIDList)); return true; case OID_GEN_PHYSICAL_MEDIUM: *ResponseSize = sizeof(uint32_t); /* Indicate that the device is a true ethernet link */ *((uint32_t*)ResponseData) = 0; return true; case OID_GEN_HARDWARE_STATUS: *ResponseSize = sizeof(uint32_t); /* Always indicate hardware ready */ *((uint32_t*)ResponseData) = NDIS_HardwareStatus_Ready; return true; case OID_GEN_MEDIA_SUPPORTED: case OID_GEN_MEDIA_IN_USE: *ResponseSize = sizeof(uint32_t); /* Indicate 802.3 (Ethernet) supported by the adapter */ *((uint32_t*)ResponseData) = REMOTE_NDIS_MEDIUM_802_3; return true; case OID_GEN_VENDOR_ID: *ResponseSize = sizeof(uint32_t); /* Vendor ID 0x0xFFFFFF is reserved for vendors who have not purchased a NDIS VID */ *((uint32_t*)ResponseData) = 0x00FFFFFF; return true; case OID_GEN_MAXIMUM_FRAME_SIZE: case OID_GEN_TRANSMIT_BLOCK_SIZE: case OID_GEN_RECEIVE_BLOCK_SIZE: *ResponseSize = sizeof(uint32_t); /* Indicate that the maximum frame size is the size of the ethernet frame buffer */ *((uint32_t*)ResponseData) = ETHERNET_FRAME_SIZE_MAX; return true; case OID_GEN_VENDOR_DESCRIPTION: *ResponseSize = sizeof(AdapterVendorDescription); /* Copy vendor description string to the response buffer */ memcpy_P(ResponseData, AdapterVendorDescription, sizeof(AdapterVendorDescription)); return true; case OID_GEN_MEDIA_CONNECT_STATUS: *ResponseSize = sizeof(uint32_t); /* Always indicate that the adapter is connected to a network */ *((uint32_t*)ResponseData) = REMOTE_NDIS_MEDIA_STATE_CONNECTED; return true; case OID_GEN_LINK_SPEED: *ResponseSize = sizeof(uint32_t); /* Indicate 10Mb/s link speed */ *((uint32_t*)ResponseData) = 100000; return true; case OID_802_3_PERMANENT_ADDRESS: case OID_802_3_CURRENT_ADDRESS: *ResponseSize = sizeof(MAC_Address_t); /* Copy over the fixed adapter MAC to the response buffer */ memcpy_P(ResponseData, &AdapterMACAddress, sizeof(MAC_Address_t)); return true; case OID_802_3_MAXIMUM_LIST_SIZE: *ResponseSize = sizeof(uint32_t); /* Indicate only one multicast address supported */ *((uint32_t*)ResponseData) = 1; return true; case OID_GEN_CURRENT_PACKET_FILTER: *ResponseSize = sizeof(uint32_t); /* Indicate the current packet filter mask */ *((uint32_t*)ResponseData) = CurrPacketFilter; return true; case OID_GEN_XMIT_OK: case OID_GEN_RCV_OK: case OID_GEN_XMIT_ERROR: case OID_GEN_RCV_ERROR: case OID_GEN_RCV_NO_BUFFER: case OID_802_3_RCV_ERROR_ALIGNMENT: case OID_802_3_XMIT_ONE_COLLISION: case OID_802_3_XMIT_MORE_COLLISIONS: *ResponseSize = sizeof(uint32_t); /* Unused statistic OIDs - always return 0 for each */ *((uint32_t*)ResponseData) = 0; return true; case OID_GEN_MAXIMUM_TOTAL_SIZE: *ResponseSize = sizeof(uint32_t); /* Indicate maximum overall buffer (Ethernet frame and RNDIS header) the adapter can handle */ *((uint32_t*)ResponseData) = (sizeof(RNDISMessageBuffer) + ETHERNET_FRAME_SIZE_MAX); return true; default: return false; } }
void test_sign1(void){ bigint_word_t d_w[sizeof(ecdsa_test_1_d)]; uint8_t rnd[sizeof(ecdsa_test_1_k)]; uint8_t *hash; bigint_t d; const hfdesc_t *hash_desc; ecc_combi_point_t q; ecdsa_signature_t sign; ecdsa_ctx_t ctx; uint8_t r; putchar('\n'); d.wordv = d_w; memcpy_P(rnd, ecdsa_test_1_k, sizeof(ecdsa_test_1_k)); memcpy_P(d_w, ecdsa_test_1_d, sizeof(ecdsa_test_1_d)); d.length_W = (sizeof(ecdsa_test_1_d) + sizeof(bigint_word_t) - 1) / sizeof(bigint_word_t); d.info = 0; bigint_adjust(&d); hash_desc = &sha1_desc; //hash_select(); hash = malloc(hfal_hash_getHashsize(hash_desc) / 8); if(hash == NULL){ printf_P(PSTR("DBG: XXX <%S %s %d>\n"), PSTR(__FILE__), __func__, __LINE__); } hash_mem_P(hash_desc, hash, ecdsa_test_1_msg, sizeof(ecdsa_test_1_msg) * 8); printf_P(PSTR("msg hash: ")); cli_hexdump(hash, hfal_hash_getHashsize(hash_desc) / 8); putchar('\n'); ecc_chudnovsky_point_alloc(&q.chudnovsky, nist_curve_p192_p.length_W * sizeof(bigint_word_t)); ctx.basepoint = &nist_curve_p192_basepoint.chudnovsky; ctx.priv = &d; ctx.curve = &nist_curve_p192; printf("\n d: "); bigint_print_hex(&d); printf_P(PSTR("\n Gx: ")); bigint_print_hex(&nist_curve_p192_basepoint.affine.x); printf_P(PSTR("\n Gy: ")); bigint_print_hex(&nist_curve_p192_basepoint.affine.y); r = ecc_chudnovsky_multiplication(&q.chudnovsky, &d, &nist_curve_p192_basepoint.chudnovsky, &nist_curve_p192); if(r){ printf_P(PSTR("ERROR: ecc_chudnovsky_multiplication() returned: %"PRIu8"\n"), r); } r = ecc_chudnovsky_to_affine_point(&q.affine, &q.chudnovsky, &nist_curve_p192); if(r){ printf_P(PSTR("ERROR: ecc_chudnovsky_to_affine_point() returned: %"PRIu8"\n"), r); } printf_P(PSTR("\n Qx: ")); bigint_print_hex(&q.affine.x); printf_P(PSTR("\n Qy: ")); bigint_print_hex(&q.affine.y); putchar('\n'); ctx.pub = &q.affine; ecdsa_signature_alloc(&sign, sizeof(ecdsa_test_1_d) * sizeof(bigint_word_t)); r = ecdsa_sign_hash(&sign, hash, hfal_hash_getHashsize(hash_desc) / 8, &ctx, rnd); if(r){ printf_P(PSTR("ERROR: ecdsa_sign_message() returned: %"PRIu8"\n"), r); } printf_P(PSTR(" r: ")); bigint_print_hex(&sign.r); printf_P(PSTR("\n s: ")); bigint_print_hex(&sign.s); free(hash); ecdsa_signature_free(&sign); ecc_chudnovsky_point_free(&q.chudnovsky); }
static uint8_t eefs_disk_label(uint8_t part, uint8_t *label) { // copy with zero-termination memcpy_P(label, disk_label, 17); return 0; }