Update ESP8266 version
This commit is contained in:
parent
102219f9a7
commit
ff2cd22d9a
42 changed files with 3035 additions and 213 deletions
19
embedded8266/web/Makefile
Normal file
19
embedded8266/web/Makefile
Normal file
|
@ -0,0 +1,19 @@
|
|||
all : execute_reflash page.dat push
|
||||
|
||||
mfsmaker : mfsmaker.c
|
||||
gcc -o $@ $^
|
||||
|
||||
page.dat : mfsmaker page
|
||||
./mfsmaker page page.dat
|
||||
|
||||
pushtodev : pushtodev.c
|
||||
gcc -o $@ $^
|
||||
|
||||
execute_reflash : execute_reflash.c md5.c
|
||||
gcc -o $@ $^
|
||||
|
||||
push : pushtodev page.dat
|
||||
./pushtodev 192.168.4.1 1048576 page.dat
|
||||
|
||||
clean :
|
||||
rm -rf mfsmaker page.dat pushtodev execute_reflash
|
266
embedded8266/web/execute_reflash.c
Normal file
266
embedded8266/web/execute_reflash.c
Normal file
|
@ -0,0 +1,266 @@
|
|||
//Copyright 2015 <>< Charles Lohr Under the MIT/x11 License, NewBSD License or
|
||||
// ColorChord License. You Choose.
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/poll.h>
|
||||
#include <sys/types.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "md5.h"
|
||||
|
||||
#define BLOCK_SIZE 65536
|
||||
#define SECTOR_SIZE 4096
|
||||
#define PADDING 1024
|
||||
int sockfd;
|
||||
struct sockaddr_in servaddr,cliaddr;
|
||||
|
||||
int PushMatch( const char * match )
|
||||
{
|
||||
struct timeval tva, tvb;
|
||||
gettimeofday( &tva, 0 );
|
||||
gettimeofday( &tvb, 0 );
|
||||
while( tvb.tv_sec - tva.tv_sec < 3 )
|
||||
{
|
||||
struct pollfd ufds;
|
||||
ufds.fd = sockfd;
|
||||
ufds.events = POLLIN;
|
||||
int rv = poll(&ufds, 1, 100);
|
||||
if( rv > 0 )
|
||||
{
|
||||
char recvline[10000];
|
||||
int n=recvfrom(sockfd,recvline,10000,0,NULL,NULL);
|
||||
// printf( "%s === %s\n", recvline, match );
|
||||
if( strncmp( recvline, match, strlen( match ) ) == 0 )
|
||||
{
|
||||
printf( "Ok - " ); fflush( stdout );
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
gettimeofday( &tvb, 0 );
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint32_t Push( uint32_t offset, const char * file )
|
||||
{
|
||||
char sendline[1000];
|
||||
char recvline[1000];
|
||||
|
||||
if( offset <= 0 )
|
||||
{
|
||||
fprintf( stderr, "Error: Cannot write to address 0 or before.\n" );
|
||||
exit(-2);
|
||||
}
|
||||
|
||||
FILE * f = fopen( file, "rb" );
|
||||
if( !f || feof( f ) )
|
||||
{
|
||||
fprintf( stderr, "Error: cannot open file.\n" );
|
||||
exit(-3);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int devo = 0;
|
||||
int lastblock = -1;
|
||||
|
||||
while( !feof( f ) )
|
||||
{
|
||||
int tries;
|
||||
int thissuccess;
|
||||
char buffer[PADDING];
|
||||
char bufferout[2000];
|
||||
|
||||
int reads = fread( buffer, 1, PADDING, f );
|
||||
int sendplace = offset + devo;
|
||||
int sendsize = PADDING;//reads;
|
||||
int block = sendplace / BLOCK_SIZE;
|
||||
|
||||
memset( buffer + reads, 0, sendsize-reads );
|
||||
|
||||
if( block != lastblock )
|
||||
{
|
||||
char se[64];
|
||||
int sel = sprintf( se, "FB%d\r\n", block );
|
||||
|
||||
thissuccess = 0;
|
||||
for( tries = 0; tries < 10; tries++ )
|
||||
{
|
||||
char match[75];
|
||||
printf( "Erase: %d\n", block );
|
||||
sendto( sockfd, se, sel, MSG_NOSIGNAL, (struct sockaddr *)&servaddr,sizeof(servaddr));
|
||||
sprintf( match, "FB%d", block );
|
||||
|
||||
if( PushMatch(match) == 0 ) { thissuccess = 1; break; }
|
||||
printf( "Retry.\n" );
|
||||
}
|
||||
if( !thissuccess )
|
||||
{
|
||||
fprintf( stderr, "Error: Timeout in communications.\n" );
|
||||
exit( -6 );
|
||||
}
|
||||
|
||||
lastblock = block;
|
||||
}
|
||||
|
||||
|
||||
int r = sprintf( bufferout, "FW%d:%d:", sendplace, sendsize );
|
||||
memcpy( bufferout + r, buffer, sendsize );
|
||||
|
||||
printf( "bufferout: %d %d\n", sendplace, sendsize );
|
||||
|
||||
thissuccess = 0;
|
||||
for( tries = 0; tries < 10; tries++ )
|
||||
{
|
||||
char match[75];
|
||||
sendto( sockfd, bufferout, sendsize + r, MSG_NOSIGNAL, (struct sockaddr *)&servaddr,sizeof(servaddr));
|
||||
sprintf( match, "FW%d", sendplace );
|
||||
|
||||
if( PushMatch(match) == 0 ) { thissuccess = 1; break; }
|
||||
printf( "Retry.\n" );
|
||||
}
|
||||
if( !thissuccess )
|
||||
{
|
||||
fprintf( stderr, "Error: Timeout in communications.\n" );
|
||||
exit( -6 );
|
||||
}
|
||||
devo += sendsize;
|
||||
}
|
||||
|
||||
return devo;
|
||||
}
|
||||
|
||||
void ComputeMD5WithKey( char * md5retText, const char * filename, const char * key )
|
||||
{
|
||||
uint8_t retmd5[16];
|
||||
MD5_CTX ctx;
|
||||
FILE * f = fopen( filename, "rb" );
|
||||
if( !f )
|
||||
{
|
||||
fprintf( stderr, "Error opening %s\n", filename );
|
||||
exit( -9 );
|
||||
}
|
||||
|
||||
fseek( f, 0, SEEK_END );
|
||||
int l = ftell( f );
|
||||
printf("MD5 Size: %d\n", l );
|
||||
int padl = ((l-1) / PADDING)*PADDING+PADDING;
|
||||
printf("MD5 Pad: %d\n", padl );
|
||||
fseek( f, 0, SEEK_SET );
|
||||
uint8_t data[padl];
|
||||
fread( data, l, 1, f );
|
||||
fclose( f );
|
||||
|
||||
memset( data+l, 0, padl-l );
|
||||
MD5_Init( &ctx );
|
||||
if( !strlen(key) )
|
||||
MD5_Update( &ctx, key, strlen( key ) );
|
||||
MD5_Update( &ctx, data, padl );
|
||||
MD5_Final( retmd5, &ctx );
|
||||
|
||||
for( l = 0; l < 16; l++ )
|
||||
{
|
||||
sprintf( md5retText + l*2, "%02x", retmd5[l] );
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t roundup( uint32_t r )
|
||||
{
|
||||
return ((r-1)&(~0xFFF))+0x1000;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char**argv)
|
||||
{
|
||||
int n;
|
||||
|
||||
char sendline[1000];
|
||||
char recvline[1000];
|
||||
|
||||
char md5_f1[48];
|
||||
char md5_f2[48];
|
||||
|
||||
if (argc < 4 )
|
||||
{
|
||||
printf("usage: pushtodev [IP address] [file_lower] [file_upper] [key (optional)]\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
const char * file1 = argv[2];
|
||||
const char * file2 = argv[3];
|
||||
|
||||
|
||||
|
||||
sockfd=socket(AF_INET,SOCK_DGRAM,0);
|
||||
|
||||
bzero(&servaddr,sizeof(servaddr));
|
||||
servaddr.sin_family = AF_INET;
|
||||
servaddr.sin_addr.s_addr=inet_addr(argv[1]);
|
||||
servaddr.sin_port=htons(7878);
|
||||
|
||||
uint32_t fs1 = Push( 0x080000, file1 );
|
||||
uint32_t fs2 = Push( 0x0c0000, file2 );
|
||||
|
||||
if( !fs1 || !fs2 )
|
||||
{
|
||||
fprintf( stderr, "Error: File size not acceptable.\n" );
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char * dat = "";
|
||||
if( argc == 5 )
|
||||
{
|
||||
dat = argv[4];
|
||||
}
|
||||
|
||||
ComputeMD5WithKey( md5_f1, file1, dat );
|
||||
ComputeMD5WithKey( md5_f2, file2, dat );
|
||||
|
||||
printf( "%s %s\n", md5_f1, md5_f2 );
|
||||
|
||||
//FM[from_address]:[to_address]:[size]:[MD5(key+data)]:[from_address]:[to_address]:[size]:[MD5(key+data)]
|
||||
|
||||
char cmd[1024];
|
||||
|
||||
sprintf( cmd, "FM%d:%d:%d:%s:%d:%d:%d:%s\n",
|
||||
0x080000,
|
||||
0x000000,
|
||||
fs1, //roundup( fs1 ),
|
||||
md5_f1,
|
||||
0x0C0000,
|
||||
0x040000,
|
||||
fs2, //roundup( fs2 ),
|
||||
md5_f2 );
|
||||
|
||||
printf( "Issuing: %s\n", cmd );
|
||||
sendto( sockfd, cmd, strlen(cmd), MSG_NOSIGNAL, (struct sockaddr *)&servaddr,sizeof(servaddr));
|
||||
usleep(10000);
|
||||
sendto( sockfd, cmd, strlen(cmd), MSG_NOSIGNAL, (struct sockaddr *)&servaddr,sizeof(servaddr));
|
||||
|
||||
struct pollfd ufds;
|
||||
ufds.fd = sockfd;
|
||||
ufds.events = POLLIN;
|
||||
int rv = poll(&ufds, 1, 100);
|
||||
if( rv > 0 )
|
||||
{
|
||||
char recvline[10000];
|
||||
int n=recvfrom(sockfd,recvline,10000,0,NULL,NULL);
|
||||
|
||||
printf( "Response: %s\n",recvline );
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf( "Timeout. Good? Maybe?\n" );
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
296
embedded8266/web/md5.c
Normal file
296
embedded8266/web/md5.c
Normal file
|
@ -0,0 +1,296 @@
|
|||
/*
|
||||
* This is an OpenSSL-compatible implementation of the RSA Data Security, Inc.
|
||||
* MD5 Message-Digest Algorithm (RFC 1321).
|
||||
*
|
||||
* Homepage:
|
||||
* http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5
|
||||
*
|
||||
* Author:
|
||||
* Alexander Peslyak, better known as Solar Designer <solar at openwall.com>
|
||||
*
|
||||
* This software was written by Alexander Peslyak in 2001. No copyright is
|
||||
* claimed, and the software is hereby placed in the public domain.
|
||||
* In case this attempt to disclaim copyright and place the software in the
|
||||
* public domain is deemed null and void, then the software is
|
||||
* Copyright (c) 2001 Alexander Peslyak and it is hereby released to the
|
||||
* general public under the following terms:
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted.
|
||||
*
|
||||
* There's ABSOLUTELY NO WARRANTY, express or implied.
|
||||
*
|
||||
* (This is a heavily cut-down "BSD license".)
|
||||
*
|
||||
* This differs from Colin Plumb's older public domain implementation in that
|
||||
* no exactly 32-bit integer data type is required (any 32-bit or wider
|
||||
* unsigned integer data type will do), there's no compile-time endianness
|
||||
* configuration, and the function prototypes match OpenSSL's. No code from
|
||||
* Colin Plumb's implementation has been reused; this comment merely compares
|
||||
* the properties of the two independent implementations.
|
||||
*
|
||||
* The primary goals of this implementation are portability and ease of use.
|
||||
* It is meant to be fast, but not as fast as possible. Some known
|
||||
* optimizations are not included to reduce source code size and avoid
|
||||
* compile-time configuration.
|
||||
*/
|
||||
|
||||
#ifndef HAVE_OPENSSL
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "md5.h"
|
||||
|
||||
/*
|
||||
* The basic MD5 functions.
|
||||
*
|
||||
* F and G are optimized compared to their RFC 1321 definitions for
|
||||
* architectures that lack an AND-NOT instruction, just like in Colin Plumb's
|
||||
* implementation.
|
||||
*/
|
||||
#define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
|
||||
#define G(x, y, z) ((y) ^ ((z) & ((x) ^ (y))))
|
||||
#define H(x, y, z) (((x) ^ (y)) ^ (z))
|
||||
#define H2(x, y, z) ((x) ^ ((y) ^ (z)))
|
||||
#define I(x, y, z) ((y) ^ ((x) | ~(z)))
|
||||
|
||||
/*
|
||||
* The MD5 transformation for all four rounds.
|
||||
*/
|
||||
#define STEP(f, a, b, c, d, x, t, s) \
|
||||
(a) += f((b), (c), (d)) + (x) + (t); \
|
||||
(a) = (((a) << (s)) | (((a) & 0xffffffff) >> (32 - (s)))); \
|
||||
(a) += (b);
|
||||
|
||||
/*
|
||||
* SET reads 4 input bytes in little-endian byte order and stores them
|
||||
* in a properly aligned word in host byte order.
|
||||
*
|
||||
* The check for little-endian architectures that tolerate unaligned
|
||||
* memory accesses is just an optimization. Nothing will break if it
|
||||
* doesn't work.
|
||||
*/
|
||||
#if defined(__i386__) || defined(__x86_64__) || defined(__vax__)
|
||||
#define SET(n) \
|
||||
(*(MD5_u32plus *)&ptr[(n) * 4])
|
||||
#define GET(n) \
|
||||
SET(n)
|
||||
#else
|
||||
#define SET(n) \
|
||||
(ctx->block[(n)] = \
|
||||
(MD5_u32plus)ptr[(n) * 4] | \
|
||||
((MD5_u32plus)ptr[(n) * 4 + 1] << 8) | \
|
||||
((MD5_u32plus)ptr[(n) * 4 + 2] << 16) | \
|
||||
((MD5_u32plus)ptr[(n) * 4 + 3] << 24))
|
||||
#define GET(n) \
|
||||
(ctx->block[(n)])
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This processes one or more 64-byte data blocks, but does NOT update
|
||||
* the bit counters. There are no alignment requirements.
|
||||
*/
|
||||
static const void *body(MD5_CTX *ctx, const void *data, unsigned long size)
|
||||
{
|
||||
const unsigned char *ptr;
|
||||
MD5_u32plus a, b, c, d;
|
||||
MD5_u32plus saved_a, saved_b, saved_c, saved_d;
|
||||
|
||||
ptr = (const unsigned char *)data;
|
||||
|
||||
a = ctx->a;
|
||||
b = ctx->b;
|
||||
c = ctx->c;
|
||||
d = ctx->d;
|
||||
|
||||
do {
|
||||
saved_a = a;
|
||||
saved_b = b;
|
||||
saved_c = c;
|
||||
saved_d = d;
|
||||
|
||||
/* Round 1 */
|
||||
STEP(F, a, b, c, d, SET(0), 0xd76aa478, 7)
|
||||
STEP(F, d, a, b, c, SET(1), 0xe8c7b756, 12)
|
||||
STEP(F, c, d, a, b, SET(2), 0x242070db, 17)
|
||||
STEP(F, b, c, d, a, SET(3), 0xc1bdceee, 22)
|
||||
STEP(F, a, b, c, d, SET(4), 0xf57c0faf, 7)
|
||||
STEP(F, d, a, b, c, SET(5), 0x4787c62a, 12)
|
||||
STEP(F, c, d, a, b, SET(6), 0xa8304613, 17)
|
||||
STEP(F, b, c, d, a, SET(7), 0xfd469501, 22)
|
||||
STEP(F, a, b, c, d, SET(8), 0x698098d8, 7)
|
||||
STEP(F, d, a, b, c, SET(9), 0x8b44f7af, 12)
|
||||
STEP(F, c, d, a, b, SET(10), 0xffff5bb1, 17)
|
||||
STEP(F, b, c, d, a, SET(11), 0x895cd7be, 22)
|
||||
STEP(F, a, b, c, d, SET(12), 0x6b901122, 7)
|
||||
STEP(F, d, a, b, c, SET(13), 0xfd987193, 12)
|
||||
STEP(F, c, d, a, b, SET(14), 0xa679438e, 17)
|
||||
STEP(F, b, c, d, a, SET(15), 0x49b40821, 22)
|
||||
|
||||
/* Round 2 */
|
||||
STEP(G, a, b, c, d, GET(1), 0xf61e2562, 5)
|
||||
STEP(G, d, a, b, c, GET(6), 0xc040b340, 9)
|
||||
STEP(G, c, d, a, b, GET(11), 0x265e5a51, 14)
|
||||
STEP(G, b, c, d, a, GET(0), 0xe9b6c7aa, 20)
|
||||
STEP(G, a, b, c, d, GET(5), 0xd62f105d, 5)
|
||||
STEP(G, d, a, b, c, GET(10), 0x02441453, 9)
|
||||
STEP(G, c, d, a, b, GET(15), 0xd8a1e681, 14)
|
||||
STEP(G, b, c, d, a, GET(4), 0xe7d3fbc8, 20)
|
||||
STEP(G, a, b, c, d, GET(9), 0x21e1cde6, 5)
|
||||
STEP(G, d, a, b, c, GET(14), 0xc33707d6, 9)
|
||||
STEP(G, c, d, a, b, GET(3), 0xf4d50d87, 14)
|
||||
STEP(G, b, c, d, a, GET(8), 0x455a14ed, 20)
|
||||
STEP(G, a, b, c, d, GET(13), 0xa9e3e905, 5)
|
||||
STEP(G, d, a, b, c, GET(2), 0xfcefa3f8, 9)
|
||||
STEP(G, c, d, a, b, GET(7), 0x676f02d9, 14)
|
||||
STEP(G, b, c, d, a, GET(12), 0x8d2a4c8a, 20)
|
||||
|
||||
/* Round 3 */
|
||||
STEP(H, a, b, c, d, GET(5), 0xfffa3942, 4)
|
||||
STEP(H2, d, a, b, c, GET(8), 0x8771f681, 11)
|
||||
STEP(H, c, d, a, b, GET(11), 0x6d9d6122, 16)
|
||||
STEP(H2, b, c, d, a, GET(14), 0xfde5380c, 23)
|
||||
STEP(H, a, b, c, d, GET(1), 0xa4beea44, 4)
|
||||
STEP(H2, d, a, b, c, GET(4), 0x4bdecfa9, 11)
|
||||
STEP(H, c, d, a, b, GET(7), 0xf6bb4b60, 16)
|
||||
STEP(H2, b, c, d, a, GET(10), 0xbebfbc70, 23)
|
||||
STEP(H, a, b, c, d, GET(13), 0x289b7ec6, 4)
|
||||
STEP(H2, d, a, b, c, GET(0), 0xeaa127fa, 11)
|
||||
STEP(H, c, d, a, b, GET(3), 0xd4ef3085, 16)
|
||||
STEP(H2, b, c, d, a, GET(6), 0x04881d05, 23)
|
||||
STEP(H, a, b, c, d, GET(9), 0xd9d4d039, 4)
|
||||
STEP(H2, d, a, b, c, GET(12), 0xe6db99e5, 11)
|
||||
STEP(H, c, d, a, b, GET(15), 0x1fa27cf8, 16)
|
||||
STEP(H2, b, c, d, a, GET(2), 0xc4ac5665, 23)
|
||||
|
||||
/* Round 4 */
|
||||
STEP(I, a, b, c, d, GET(0), 0xf4292244, 6)
|
||||
STEP(I, d, a, b, c, GET(7), 0x432aff97, 10)
|
||||
STEP(I, c, d, a, b, GET(14), 0xab9423a7, 15)
|
||||
STEP(I, b, c, d, a, GET(5), 0xfc93a039, 21)
|
||||
STEP(I, a, b, c, d, GET(12), 0x655b59c3, 6)
|
||||
STEP(I, d, a, b, c, GET(3), 0x8f0ccc92, 10)
|
||||
STEP(I, c, d, a, b, GET(10), 0xffeff47d, 15)
|
||||
STEP(I, b, c, d, a, GET(1), 0x85845dd1, 21)
|
||||
STEP(I, a, b, c, d, GET(8), 0x6fa87e4f, 6)
|
||||
STEP(I, d, a, b, c, GET(15), 0xfe2ce6e0, 10)
|
||||
STEP(I, c, d, a, b, GET(6), 0xa3014314, 15)
|
||||
STEP(I, b, c, d, a, GET(13), 0x4e0811a1, 21)
|
||||
STEP(I, a, b, c, d, GET(4), 0xf7537e82, 6)
|
||||
STEP(I, d, a, b, c, GET(11), 0xbd3af235, 10)
|
||||
STEP(I, c, d, a, b, GET(2), 0x2ad7d2bb, 15)
|
||||
STEP(I, b, c, d, a, GET(9), 0xeb86d391, 21)
|
||||
|
||||
a += saved_a;
|
||||
b += saved_b;
|
||||
c += saved_c;
|
||||
d += saved_d;
|
||||
|
||||
ptr += 64;
|
||||
} while (size -= 64);
|
||||
|
||||
ctx->a = a;
|
||||
ctx->b = b;
|
||||
ctx->c = c;
|
||||
ctx->d = d;
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void MD5_Init(MD5_CTX *ctx)
|
||||
{
|
||||
ctx->a = 0x67452301;
|
||||
ctx->b = 0xefcdab89;
|
||||
ctx->c = 0x98badcfe;
|
||||
ctx->d = 0x10325476;
|
||||
|
||||
ctx->lo = 0;
|
||||
ctx->hi = 0;
|
||||
}
|
||||
|
||||
void MD5_Update(MD5_CTX *ctx, const void *data, unsigned long size)
|
||||
{
|
||||
MD5_u32plus saved_lo;
|
||||
unsigned long used, available;
|
||||
|
||||
saved_lo = ctx->lo;
|
||||
if ((ctx->lo = (saved_lo + size) & 0x1fffffff) < saved_lo)
|
||||
ctx->hi++;
|
||||
ctx->hi += size >> 29;
|
||||
|
||||
used = saved_lo & 0x3f;
|
||||
|
||||
if (used) {
|
||||
available = 64 - used;
|
||||
|
||||
if (size < available) {
|
||||
memcpy(&ctx->buffer[used], data, size);
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(&ctx->buffer[used], data, available);
|
||||
data = (const unsigned char *)data + available;
|
||||
size -= available;
|
||||
body(ctx, ctx->buffer, 64);
|
||||
}
|
||||
|
||||
if (size >= 64) {
|
||||
data = body(ctx, data, size & ~(unsigned long)0x3f);
|
||||
size &= 0x3f;
|
||||
}
|
||||
|
||||
memcpy(ctx->buffer, data, size);
|
||||
}
|
||||
|
||||
void MD5_Final(unsigned char *result, MD5_CTX *ctx)
|
||||
{
|
||||
unsigned long used, available;
|
||||
|
||||
used = ctx->lo & 0x3f;
|
||||
|
||||
ctx->buffer[used++] = 0x80;
|
||||
|
||||
available = 64 - used;
|
||||
|
||||
if (available < 8) {
|
||||
memset(&ctx->buffer[used], 0, available);
|
||||
body(ctx, ctx->buffer, 64);
|
||||
used = 0;
|
||||
available = 64;
|
||||
}
|
||||
|
||||
memset(&ctx->buffer[used], 0, available - 8);
|
||||
|
||||
ctx->lo <<= 3;
|
||||
ctx->buffer[56] = ctx->lo;
|
||||
ctx->buffer[57] = ctx->lo >> 8;
|
||||
ctx->buffer[58] = ctx->lo >> 16;
|
||||
ctx->buffer[59] = ctx->lo >> 24;
|
||||
ctx->buffer[60] = ctx->hi;
|
||||
ctx->buffer[61] = ctx->hi >> 8;
|
||||
ctx->buffer[62] = ctx->hi >> 16;
|
||||
ctx->buffer[63] = ctx->hi >> 24;
|
||||
|
||||
body(ctx, ctx->buffer, 64);
|
||||
|
||||
result[0] = ctx->a;
|
||||
result[1] = ctx->a >> 8;
|
||||
result[2] = ctx->a >> 16;
|
||||
result[3] = ctx->a >> 24;
|
||||
result[4] = ctx->b;
|
||||
result[5] = ctx->b >> 8;
|
||||
result[6] = ctx->b >> 16;
|
||||
result[7] = ctx->b >> 24;
|
||||
result[8] = ctx->c;
|
||||
result[9] = ctx->c >> 8;
|
||||
result[10] = ctx->c >> 16;
|
||||
result[11] = ctx->c >> 24;
|
||||
result[12] = ctx->d;
|
||||
result[13] = ctx->d >> 8;
|
||||
result[14] = ctx->d >> 16;
|
||||
result[15] = ctx->d >> 24;
|
||||
|
||||
memset(ctx, 0, sizeof(*ctx));
|
||||
}
|
||||
|
||||
#endif
|
45
embedded8266/web/md5.h
Normal file
45
embedded8266/web/md5.h
Normal file
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* This is an OpenSSL-compatible implementation of the RSA Data Security, Inc.
|
||||
* MD5 Message-Digest Algorithm (RFC 1321).
|
||||
*
|
||||
* Homepage:
|
||||
* http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5
|
||||
*
|
||||
* Author:
|
||||
* Alexander Peslyak, better known as Solar Designer <solar at openwall.com>
|
||||
*
|
||||
* This software was written by Alexander Peslyak in 2001. No copyright is
|
||||
* claimed, and the software is hereby placed in the public domain.
|
||||
* In case this attempt to disclaim copyright and place the software in the
|
||||
* public domain is deemed null and void, then the software is
|
||||
* Copyright (c) 2001 Alexander Peslyak and it is hereby released to the
|
||||
* general public under the following terms:
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted.
|
||||
*
|
||||
* There's ABSOLUTELY NO WARRANTY, express or implied.
|
||||
*
|
||||
* See md5.c for more information.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_OPENSSL
|
||||
#include <openssl/md5.h>
|
||||
#elif !defined(_MD5_H)
|
||||
#define _MD5_H
|
||||
|
||||
/* Any 32-bit or wider unsigned integer data type will do */
|
||||
typedef unsigned int MD5_u32plus;
|
||||
|
||||
typedef struct {
|
||||
MD5_u32plus lo, hi;
|
||||
MD5_u32plus a, b, c, d;
|
||||
unsigned char buffer[64];
|
||||
MD5_u32plus block[16];
|
||||
} MD5_CTX;
|
||||
|
||||
extern void MD5_Init(MD5_CTX *ctx);
|
||||
extern void MD5_Update(MD5_CTX *ctx, const void *data, unsigned long size);
|
||||
extern void MD5_Final(unsigned char *result, MD5_CTX *ctx);
|
||||
|
||||
#endif
|
139
embedded8266/web/mfsmaker.c
Normal file
139
embedded8266/web/mfsmaker.c
Normal file
|
@ -0,0 +1,139 @@
|
|||
|
||||
//Copyright 2015 <>< Charles Lohr Under the MIT/x11 License, NewBSD License or
|
||||
// ColorChord License. You Choose.
|
||||
|
||||
#include <stdio.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/stat.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define SPI_FLASH_SEC_SIZE 4096
|
||||
#define MFS_STARTFLASHSECTOR 0x100
|
||||
#define MFS_START (MFS_STARTFLASHSECTOR*SPI_FLASH_SEC_SIZE)
|
||||
#define MFS_SECTOR 256
|
||||
#define MFS_FILENAMELEN 32-8
|
||||
#define ENTRIES 8192
|
||||
|
||||
#define ENDIAN(x) x//htonl
|
||||
|
||||
struct MFSFileEntry
|
||||
{
|
||||
char name[MFS_FILENAMELEN];
|
||||
uint32_t start; //From beginning of mfs thing.
|
||||
uint32_t len;
|
||||
} mfsfat[ENTRIES];
|
||||
|
||||
unsigned char mfsdata[131072*8];
|
||||
|
||||
unsigned long fatpointer = 0;
|
||||
unsigned long datapointer = 0;
|
||||
|
||||
int main( int argc, char ** argv )
|
||||
{
|
||||
int i;
|
||||
DIR *d;
|
||||
struct dirent *dir;
|
||||
|
||||
if( argc != 3 )
|
||||
{
|
||||
fprintf( stderr, "Error: [tool] [directory to pack] [output packed .dat file]\n" );
|
||||
return -1;
|
||||
}
|
||||
|
||||
d = opendir( argv[1] );
|
||||
|
||||
if (!d)
|
||||
{
|
||||
fprintf( stderr, "Error: cannot open folder for packing.\n" );
|
||||
return -2;
|
||||
}
|
||||
|
||||
while ((dir = readdir(d)) != NULL)
|
||||
{
|
||||
if( dir->d_type & DT_REG )
|
||||
{
|
||||
char thisfile[1024];
|
||||
struct stat buf;
|
||||
int dlen = strlen( dir->d_name );
|
||||
int sprret = snprintf( thisfile, 1023, "%s/%s", argv[1], dir->d_name );
|
||||
|
||||
if( sprret > 1023 || sprret < 1 )
|
||||
{
|
||||
fprintf( stderr, "Error processing \"%s\" (snprintf)\n", dir->d_name );
|
||||
continue;
|
||||
}
|
||||
|
||||
int statret = stat( thisfile, &buf );
|
||||
|
||||
if( statret )
|
||||
{
|
||||
fprintf( stderr, "Error processing \"%s\" (stat)\n", dir->d_name );
|
||||
continue;
|
||||
}
|
||||
|
||||
if( dlen >= MFS_FILENAMELEN )
|
||||
{
|
||||
fprintf( stderr, "Warning: Fle \"%s\" too long.\n", dir->d_name );
|
||||
continue;
|
||||
}
|
||||
if( fatpointer > ENTRIES )
|
||||
{
|
||||
fprintf( stderr, "Warning: Not enough entries to fit \"%s\".\n", dir->d_name );
|
||||
continue;
|
||||
}
|
||||
|
||||
if( buf.st_size + datapointer > sizeof( mfsdata ) )
|
||||
{
|
||||
fprintf( stderr, "Error: no space left.\n" );
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy( mfsfat[fatpointer].name, dir->d_name, dlen );
|
||||
mfsfat[fatpointer].start = datapointer;
|
||||
mfsfat[fatpointer].len = ENDIAN( buf.st_size );
|
||||
fatpointer++;
|
||||
|
||||
if( buf.st_size )
|
||||
{
|
||||
FILE * f = fopen( thisfile, "rb" );
|
||||
if( !f )
|
||||
{
|
||||
fprintf( stderr, "Error: cannot open \"%s\" for reading.\n", dir->d_name );
|
||||
return -9;
|
||||
}
|
||||
fread( &mfsdata[datapointer], 1, buf.st_size, f );
|
||||
fclose( f );
|
||||
int rs = buf.st_size;
|
||||
rs = (rs+1+MFS_SECTOR)&(~(MFS_SECTOR-1));
|
||||
datapointer += rs;
|
||||
printf( "%s: %d (%d)\n", thisfile, rs, datapointer );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
closedir(d);
|
||||
|
||||
int rs = (fatpointer+1)*sizeof(struct MFSFileEntry);
|
||||
rs = (rs+1+MFS_SECTOR)&(~(MFS_SECTOR-1));
|
||||
for( i = 0; i < fatpointer; i++ )
|
||||
{
|
||||
mfsfat[i].start = ENDIAN(mfsfat[i].start + rs );
|
||||
}
|
||||
|
||||
printf( "%d %d\n", rs, datapointer );
|
||||
|
||||
FILE * f = fopen( argv[2], "w" );
|
||||
|
||||
if( !f || ferror( f ) )
|
||||
{
|
||||
fprintf( stderr, "Error: cannot open \"%s\" for writing.\n", argv[2] );
|
||||
}
|
||||
fwrite( mfsfat, rs, 1, f );
|
||||
fwrite( mfsdata, datapointer, 1, f );
|
||||
fclose( f );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
8
embedded8266/web/page/index.html
Normal file
8
embedded8266/web/page/index.html
Normal file
|
@ -0,0 +1,8 @@
|
|||
<HTML>
|
||||
<BODY>
|
||||
Hello! This is a test page.<BR>
|
||||
|
||||
<IMG SRC=dsc.jpg>
|
||||
|
||||
</BODY>
|
||||
</HTML>
|
1
embedded8266/web/page/test.txt
Normal file
1
embedded8266/web/page/test.txt
Normal file
|
@ -0,0 +1 @@
|
|||
test
|
69
embedded8266/web/page/websocket.js
Normal file
69
embedded8266/web/page/websocket.js
Normal file
|
@ -0,0 +1,69 @@
|
|||
var wsUri = "ws://" + location.host + "/d/ws";
|
||||
|
||||
var output;
|
||||
|
||||
function init()
|
||||
{
|
||||
output = document.getElementById("output");
|
||||
console.log( wsUri );
|
||||
testWebSocket();
|
||||
}
|
||||
|
||||
function testWebSocket()
|
||||
{
|
||||
websocket = new WebSocket(wsUri);
|
||||
websocket.onopen = function(evt) { onOpen(evt) };
|
||||
websocket.onclose = function(evt) { onClose(evt) };
|
||||
websocket.onmessage = function(evt) { onMessage(evt) };
|
||||
websocket.onerror = function(evt) { onError(evt) };
|
||||
}
|
||||
|
||||
function repeatsend()
|
||||
{
|
||||
doSend('Hello!' );
|
||||
setTimeout( repeatsend, 1000 );
|
||||
}
|
||||
|
||||
function onOpen(evt)
|
||||
{
|
||||
writeToScreen("CONNECTED");
|
||||
doSend('Hello.' );
|
||||
//repeatsend();
|
||||
// doSend('{"args": ["entity", 1000], "kwargs": {}, "op": "ClientUpdater__requestUpdates", "seq": 1, "context": ["ClientUpdater", 0]}');
|
||||
}
|
||||
|
||||
function onClose(evt)
|
||||
{
|
||||
writeToScreen("DISCONNECTED");
|
||||
}
|
||||
|
||||
function onMessage(evt)
|
||||
{
|
||||
eval( evt.data );
|
||||
// obj = JSON.parse(evt.data);
|
||||
// console.log( obj );
|
||||
// writeToScreen('<span style="color: blue;">RESPONSE: ' + evt.data+'</span>');
|
||||
// websocket.close();
|
||||
}
|
||||
|
||||
function onError(evt)
|
||||
{
|
||||
writeToScreen('<span style="color: red;">ERROR:</span> ' + evt.data);
|
||||
}
|
||||
|
||||
function doSend(message)
|
||||
{
|
||||
writeToScreen("SENT: " + message);
|
||||
websocket.send(message);
|
||||
}
|
||||
|
||||
function writeToScreen(message)
|
||||
{
|
||||
var pre = document.createElement("p");
|
||||
pre.style.wordWrap = "break-word";
|
||||
pre.innerHTML = message;
|
||||
output.appendChild(pre);
|
||||
}
|
||||
|
||||
window.addEventListener("load", init, false);
|
||||
|
10
embedded8266/web/page/wstest.html
Normal file
10
embedded8266/web/page/wstest.html
Normal file
|
@ -0,0 +1,10 @@
|
|||
<HTML>
|
||||
<HEAD>
|
||||
<title>WebSocket Test</title>
|
||||
<script language="javascript" type="text/javascript" src=websocket.js></script>
|
||||
</HEAD>
|
||||
<BODY>
|
||||
<h2>WebSocket Test</h2>
|
||||
<div id="output"></div>
|
||||
</BODY>
|
||||
</HTML>
|
202
embedded8266/web/pushtodev.c
Normal file
202
embedded8266/web/pushtodev.c
Normal file
|
@ -0,0 +1,202 @@
|
|||
//Unless what else is individually marked, all code in this file is
|
||||
//Copyright 2015 <>< Charles Lohr Under the MIT/x11 License, NewBSD License or
|
||||
// ColorChord License. You Choose.
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/poll.h>
|
||||
#include <sys/types.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define sector_SIZE 4096
|
||||
int sockfd;
|
||||
char recvline[10000];
|
||||
|
||||
|
||||
int PushMatch( const char * match )
|
||||
{
|
||||
struct timeval tva, tvb;
|
||||
gettimeofday( &tva, 0 );
|
||||
gettimeofday( &tvb, 0 );
|
||||
while( tvb.tv_sec - tva.tv_sec < 3 ) //3 second timeout.
|
||||
{
|
||||
struct pollfd ufds;
|
||||
ufds.fd = sockfd;
|
||||
ufds.events = POLLIN;
|
||||
int rv = poll(&ufds, 1, 500);
|
||||
if( rv > 0 )
|
||||
{
|
||||
// tbuf = recvline;
|
||||
int n=recvfrom(sockfd,recvline,10000,0,NULL,NULL);
|
||||
// printf( "!!%d ->%s\n", n,recvline );
|
||||
// printf( "%s === %s\n", recvline, match );
|
||||
if( strncmp( recvline, match, strlen( match ) ) == 0 )
|
||||
{
|
||||
// printf( "Ok\n" ); fflush( stdout );
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
gettimeofday( &tvb, 0 );
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char**argv)
|
||||
{
|
||||
int n;
|
||||
struct sockaddr_in servaddr,cliaddr;
|
||||
char sendline[1000];
|
||||
// char recvline[1000];
|
||||
|
||||
if (argc != 4)
|
||||
{
|
||||
printf("usage: pushtodev [IP address] [address offset] [file]\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
int offset = atoi( argv[2] );
|
||||
const char * file = argv[3];
|
||||
|
||||
if( offset <= 0 )
|
||||
{
|
||||
fprintf( stderr, "Error: Cannot write to address 0 or before.\n" );
|
||||
exit(-2);
|
||||
}
|
||||
|
||||
FILE * f = fopen( file, "rb" );
|
||||
if( !f || feof( f ) )
|
||||
{
|
||||
fprintf( stderr, "Error: cannot open file.\n" );
|
||||
exit(-3);
|
||||
}
|
||||
|
||||
|
||||
|
||||
sockfd=socket(AF_INET,SOCK_DGRAM,0);
|
||||
|
||||
bzero(&servaddr,sizeof(servaddr));
|
||||
servaddr.sin_family = AF_INET;
|
||||
servaddr.sin_addr.s_addr=inet_addr(argv[1]);
|
||||
servaddr.sin_port=htons(7878);
|
||||
|
||||
int devo = 0;
|
||||
int lastsector = -1;
|
||||
int resend_times = 0;
|
||||
int r;
|
||||
while( !feof( f ) )
|
||||
{
|
||||
int tries;
|
||||
int thissuccess;
|
||||
char buffer[1024];
|
||||
char bufferout[1600];
|
||||
int reads = fread( buffer, 1, 1024, f );
|
||||
int sendplace = offset + devo;
|
||||
int sendsize = reads;
|
||||
int sector = sendplace / sector_SIZE;
|
||||
|
||||
if( sector != lastsector )
|
||||
{
|
||||
char se[64];
|
||||
int sel = sprintf( se, "FE%d\r\n", sector );
|
||||
|
||||
thissuccess = 0;
|
||||
for( tries = 0; tries < 10; tries++ )
|
||||
{
|
||||
char match[75];
|
||||
printf( "Erase: %d\n", sector );
|
||||
sendto( sockfd, se, sel, MSG_NOSIGNAL, (struct sockaddr *)&servaddr,sizeof(servaddr));
|
||||
sprintf( match, "FE%d", sector );
|
||||
|
||||
if( PushMatch(match) == 0 ) { thissuccess = 1; break; }
|
||||
printf( "Retry.\n" );
|
||||
}
|
||||
if( !thissuccess )
|
||||
{
|
||||
fprintf( stderr, "Error: Timeout in communications.\n" );
|
||||
exit( -6 );
|
||||
}
|
||||
|
||||
lastsector = sector;
|
||||
}
|
||||
|
||||
resend_times = 0;
|
||||
resend:
|
||||
r = sprintf( bufferout, "FW%d:%d:", sendplace, sendsize );
|
||||
printf( "bufferout: %d %d %s\n", sendplace, sendsize, bufferout );
|
||||
memcpy( bufferout + r, buffer, sendsize );
|
||||
|
||||
|
||||
thissuccess = 0;
|
||||
for( tries = 0; tries < 10; tries++ )
|
||||
{
|
||||
char match[75];
|
||||
sendto( sockfd, bufferout, reads + r, MSG_NOSIGNAL, (struct sockaddr *)&servaddr,sizeof(servaddr));
|
||||
|
||||
sprintf( match, "FW%d", sendplace );
|
||||
|
||||
if( PushMatch(match) == 0 ) { thissuccess = 1; break; }
|
||||
printf( "Retry.\n" );
|
||||
}
|
||||
if( !thissuccess )
|
||||
{
|
||||
fprintf( stderr, "Error: Timeout in communications.\n" );
|
||||
exit( -6 );
|
||||
}
|
||||
|
||||
/*
|
||||
printf( "Verifying..." );
|
||||
fflush( stdout );
|
||||
|
||||
int r = sprintf( bufferout, "FR%d:%d", sendplace, sendsize );
|
||||
bufferout[r] = 0;
|
||||
|
||||
thissuccess = 0;
|
||||
for( tries = 0; tries < 10; tries++ )
|
||||
{
|
||||
char match[1600];
|
||||
sendto( sockfd, bufferout, r, MSG_NOSIGNAL, (struct sockaddr *)&servaddr,sizeof(servaddr));
|
||||
devo += reads;
|
||||
sprintf( match, "FR%08d", sendplace );
|
||||
|
||||
if( PushMatch(match) == 0 ) {
|
||||
|
||||
//Check data...
|
||||
//printf( "RR:%s\n", recvline );
|
||||
char * colon1 = strchr( recvline, ':' );
|
||||
char * colon2 = (colon1)?strchr( colon1+1, ':' ):0;
|
||||
//printf( "::%p %p \"%s\"\n", colon1, colon2,recvline );
|
||||
if( colon2 )
|
||||
{
|
||||
if( memcmp( colon2+1, buffer, sendsize ) == 0 )
|
||||
thissuccess = 1;
|
||||
}
|
||||
|
||||
if( !thissuccess )
|
||||
{
|
||||
if( resend_times > 2 )
|
||||
{
|
||||
break;
|
||||
}
|
||||
resend_times++;
|
||||
goto resend;
|
||||
}
|
||||
break;
|
||||
}
|
||||
printf( "Retry.\n" );
|
||||
}
|
||||
if( !thissuccess )
|
||||
{
|
||||
fprintf( stderr, "Error: Fault verifying.\n" );
|
||||
exit( -6 );
|
||||
}
|
||||
*/
|
||||
devo += reads;
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue