1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-18 03:52:11 +01:00

uncrustify

This commit is contained in:
Alessio Morale 2015-02-05 01:42:32 +01:00
parent b9bfcd18d2
commit aa55b1523d
5 changed files with 190 additions and 191 deletions

View File

@ -7,30 +7,30 @@
*/ */
#ifndef _SYS_SHA1_H_ #ifndef _SYS_SHA1_H_
#define _SYS_SHA1_H_ #define _SYS_SHA1_H_
#include <sys/cdefs.h> #include <sys/cdefs.h>
#include <sys/types.h> #include <sys/types.h>
#define SHA1_DIGEST_LENGTH 20 #define SHA1_DIGEST_LENGTH 20
#define SHA1_DIGEST_STRING_LENGTH 41 #define SHA1_DIGEST_STRING_LENGTH 41
typedef struct { typedef struct {
uint32_t state[5]; uint32_t state[5];
uint32_t count[2]; uint32_t count[2];
uint8_t buffer[64]; uint8_t buffer[64];
} SHA1_CTX; } SHA1_CTX;
__BEGIN_DECLS __BEGIN_DECLS
void SHA1Transform(uint32_t[5], const uint8_t[64]); void SHA1Transform(uint32_t[5], const uint8_t[64]);
void SHA1Init(SHA1_CTX *); void SHA1Init(SHA1_CTX *);
void SHA1Update(SHA1_CTX *, const uint8_t *, unsigned int); void SHA1Update(SHA1_CTX *, const uint8_t *, unsigned int);
void SHA1Final(uint8_t[SHA1_DIGEST_LENGTH], SHA1_CTX *); void SHA1Final(uint8_t[SHA1_DIGEST_LENGTH], SHA1_CTX *);
#ifndef _KERNEL #ifndef _KERNEL
char *SHA1End(SHA1_CTX *, char *); char *SHA1End(SHA1_CTX *, char *);
char *SHA1FileChunk(const char *, char *, off_t, off_t); char *SHA1FileChunk(const char *, char *, off_t, off_t);
char *SHA1File(const char *, char *); char *SHA1File(const char *, char *);
char *SHA1Data(const uint8_t *, size_t, char *); char *SHA1Data(const uint8_t *, size_t, char *);
#endif /* _KERNEL */ #endif /* _KERNEL */
__END_DECLS __END_DECLS

View File

@ -15,7 +15,7 @@
* 34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F * 34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F
*/ */
#define SHA1HANDSOFF /* Copies data before messing with it. */ #define SHA1HANDSOFF /* Copies data before messing with it. */
#include <sys/cdefs.h> #include <sys/cdefs.h>
@ -30,7 +30,7 @@ __KERNEL_RCSID(0, "$NetBSD: sha1.c,v 1.6 2009/11/06 20:31:18 joerg Exp $");
__RCSID("$NetBSD: sha1.c,v 1.6 2009/11/06 20:31:18 joerg Exp $"); __RCSID("$NetBSD: sha1.c,v 1.6 2009/11/06 20:31:18 joerg Exp $");
#endif /* LIBC_SCCS and not lint */ #endif /* LIBC_SCCS and not lint */
//#include "namespace.h" // #include "namespace.h"
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
@ -53,35 +53,37 @@ __RCSID("$NetBSD: sha1.c,v 1.6 2009/11/06 20:31:18 joerg Exp $");
* I got the idea of expanding during the round function from SSLeay * I got the idea of expanding during the round function from SSLeay
*/ */
#if BYTE_ORDER == LITTLE_ENDIAN #if BYTE_ORDER == LITTLE_ENDIAN
# define blk0(i) (block->l[i] = (rol(block->l[i],24)&0xFF00FF00) \ # define blk0(i) \
|(rol(block->l[i],8)&0x00FF00FF)) (block->l[i] = (rol(block->l[i], 24) & 0xFF00FF00) \
| (rol(block->l[i], 8) & 0x00FF00FF))
#else #else
# define blk0(i) block->l[i] # define blk0(i) block->l[i]
#endif #endif
#define blk(i) (block->l[i&15] = rol(block->l[(i+13)&15]^block->l[(i+8)&15] \ #define blk(i) \
^block->l[(i+2)&15]^block->l[i&15],1)) (block->l[i & 15] = rol(block->l[(i + 13) & 15] ^ block->l[(i + 8) & 15] \
^ block->l[(i + 2) & 15] ^ block->l[i & 15], 1))
/* /*
* (R0+R1), R2, R3, R4 are the different operations (rounds) used in SHA1 * (R0+R1), R2, R3, R4 are the different operations (rounds) used in SHA1
*/ */
#define R0(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk0(i)+0x5A827999+rol(v,5);w=rol(w,30); #define R0(v, w, x, y, z, i) z += ((w & (x ^ y)) ^ y) + blk0(i) + 0x5A827999 + rol(v, 5); w = rol(w, 30);
#define R1(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk(i)+0x5A827999+rol(v,5);w=rol(w,30); #define R1(v, w, x, y, z, i) z += ((w & (x ^ y)) ^ y) + blk(i) + 0x5A827999 + rol(v, 5); w = rol(w, 30);
#define R2(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0x6ED9EBA1+rol(v,5);w=rol(w,30); #define R2(v, w, x, y, z, i) z += (w ^ x ^ y) + blk(i) + 0x6ED9EBA1 + rol(v, 5); w = rol(w, 30);
#define R3(v,w,x,y,z,i) z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=rol(w,30); #define R3(v, w, x, y, z, i) z += (((w | x) & y) | (w & x)) + blk(i) + 0x8F1BBCDC + rol(v, 5); w = rol(w, 30);
#define R4(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=rol(w,30); #define R4(v, w, x, y, z, i) z += (w ^ x ^ y) + blk(i) + 0xCA62C1D6 + rol(v, 5); w = rol(w, 30);
#if !defined(_KERNEL) && !defined(_STANDALONE) #if !defined(_KERNEL) && !defined(_STANDALONE)
#if defined(__weak_alias) #if defined(__weak_alias)
__weak_alias(SHA1Transform,_SHA1Transform) __weak_alias(SHA1Transform, _SHA1Transform)
__weak_alias(SHA1Init,_SHA1Init) __weak_alias(SHA1Init, _SHA1Init)
__weak_alias(SHA1Update,_SHA1Update) __weak_alias(SHA1Update, _SHA1Update)
__weak_alias(SHA1Final,_SHA1Final) __weak_alias(SHA1Final, _SHA1Final)
#endif #endif
#endif #endif
typedef union { typedef union {
uint8_t c[64]; uint8_t c[64];
uint32_t l[16]; uint32_t l[16];
} CHAR64LONG16; } CHAR64LONG16;
@ -97,52 +99,48 @@ void do_R2(uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d, uint32_t *e, CHAR
void do_R3(uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d, uint32_t *e, CHAR64LONG16 *); void do_R3(uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d, uint32_t *e, CHAR64LONG16 *);
void do_R4(uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d, uint32_t *e, CHAR64LONG16 *); void do_R4(uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d, uint32_t *e, CHAR64LONG16 *);
#define nR0(v,w,x,y,z,i) R0(*v,*w,*x,*y,*z,i) #define nR0(v, w, x, y, z, i) R0(*v, *w, *x, *y, *z, i)
#define nR1(v,w,x,y,z,i) R1(*v,*w,*x,*y,*z,i) #define nR1(v, w, x, y, z, i) R1(*v, *w, *x, *y, *z, i)
#define nR2(v,w,x,y,z,i) R2(*v,*w,*x,*y,*z,i) #define nR2(v, w, x, y, z, i) R2(*v, *w, *x, *y, *z, i)
#define nR3(v,w,x,y,z,i) R3(*v,*w,*x,*y,*z,i) #define nR3(v, w, x, y, z, i) R3(*v, *w, *x, *y, *z, i)
#define nR4(v,w,x,y,z,i) R4(*v,*w,*x,*y,*z,i) #define nR4(v, w, x, y, z, i) R4(*v, *w, *x, *y, *z, i)
void void do_R01(uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d, uint32_t *e, CHAR64LONG16 *block)
do_R01(uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d, uint32_t *e, CHAR64LONG16 *block)
{ {
nR0(a,b,c,d,e, 0); nR0(e,a,b,c,d, 1); nR0(d,e,a,b,c, 2); nR0(c,d,e,a,b, 3); nR0(a, b, c, d, e, 0); nR0(e, a, b, c, d, 1); nR0(d, e, a, b, c, 2); nR0(c, d, e, a, b, 3);
nR0(b,c,d,e,a, 4); nR0(a,b,c,d,e, 5); nR0(e,a,b,c,d, 6); nR0(d,e,a,b,c, 7); nR0(b, c, d, e, a, 4); nR0(a, b, c, d, e, 5); nR0(e, a, b, c, d, 6); nR0(d, e, a, b, c, 7);
nR0(c,d,e,a,b, 8); nR0(b,c,d,e,a, 9); nR0(a,b,c,d,e,10); nR0(e,a,b,c,d,11); nR0(c, d, e, a, b, 8); nR0(b, c, d, e, a, 9); nR0(a, b, c, d, e, 10); nR0(e, a, b, c, d, 11);
nR0(d,e,a,b,c,12); nR0(c,d,e,a,b,13); nR0(b,c,d,e,a,14); nR0(a,b,c,d,e,15); nR0(d, e, a, b, c, 12); nR0(c, d, e, a, b, 13); nR0(b, c, d, e, a, 14); nR0(a, b, c, d, e, 15);
nR1(e,a,b,c,d,16); nR1(d,e,a,b,c,17); nR1(c,d,e,a,b,18); nR1(b,c,d,e,a,19); nR1(e, a, b, c, d, 16); nR1(d, e, a, b, c, 17); nR1(c, d, e, a, b, 18); nR1(b, c, d, e, a, 19);
} }
void void do_R2(uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d, uint32_t *e, CHAR64LONG16 *block)
do_R2(uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d, uint32_t *e, CHAR64LONG16 *block)
{ {
nR2(a,b,c,d,e,20); nR2(e,a,b,c,d,21); nR2(d,e,a,b,c,22); nR2(c,d,e,a,b,23); nR2(a, b, c, d, e, 20); nR2(e, a, b, c, d, 21); nR2(d, e, a, b, c, 22); nR2(c, d, e, a, b, 23);
nR2(b,c,d,e,a,24); nR2(a,b,c,d,e,25); nR2(e,a,b,c,d,26); nR2(d,e,a,b,c,27); nR2(b, c, d, e, a, 24); nR2(a, b, c, d, e, 25); nR2(e, a, b, c, d, 26); nR2(d, e, a, b, c, 27);
nR2(c,d,e,a,b,28); nR2(b,c,d,e,a,29); nR2(a,b,c,d,e,30); nR2(e,a,b,c,d,31); nR2(c, d, e, a, b, 28); nR2(b, c, d, e, a, 29); nR2(a, b, c, d, e, 30); nR2(e, a, b, c, d, 31);
nR2(d,e,a,b,c,32); nR2(c,d,e,a,b,33); nR2(b,c,d,e,a,34); nR2(a,b,c,d,e,35); nR2(d, e, a, b, c, 32); nR2(c, d, e, a, b, 33); nR2(b, c, d, e, a, 34); nR2(a, b, c, d, e, 35);
nR2(e,a,b,c,d,36); nR2(d,e,a,b,c,37); nR2(c,d,e,a,b,38); nR2(b,c,d,e,a,39); nR2(e, a, b, c, d, 36); nR2(d, e, a, b, c, 37); nR2(c, d, e, a, b, 38); nR2(b, c, d, e, a, 39);
} }
void void do_R3(uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d, uint32_t *e, CHAR64LONG16 *block)
do_R3(uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d, uint32_t *e, CHAR64LONG16 *block)
{ {
nR3(a,b,c,d,e,40); nR3(e,a,b,c,d,41); nR3(d,e,a,b,c,42); nR3(c,d,e,a,b,43); nR3(a, b, c, d, e, 40); nR3(e, a, b, c, d, 41); nR3(d, e, a, b, c, 42); nR3(c, d, e, a, b, 43);
nR3(b,c,d,e,a,44); nR3(a,b,c,d,e,45); nR3(e,a,b,c,d,46); nR3(d,e,a,b,c,47); nR3(b, c, d, e, a, 44); nR3(a, b, c, d, e, 45); nR3(e, a, b, c, d, 46); nR3(d, e, a, b, c, 47);
nR3(c,d,e,a,b,48); nR3(b,c,d,e,a,49); nR3(a,b,c,d,e,50); nR3(e,a,b,c,d,51); nR3(c, d, e, a, b, 48); nR3(b, c, d, e, a, 49); nR3(a, b, c, d, e, 50); nR3(e, a, b, c, d, 51);
nR3(d,e,a,b,c,52); nR3(c,d,e,a,b,53); nR3(b,c,d,e,a,54); nR3(a,b,c,d,e,55); nR3(d, e, a, b, c, 52); nR3(c, d, e, a, b, 53); nR3(b, c, d, e, a, 54); nR3(a, b, c, d, e, 55);
nR3(e,a,b,c,d,56); nR3(d,e,a,b,c,57); nR3(c,d,e,a,b,58); nR3(b,c,d,e,a,59); nR3(e, a, b, c, d, 56); nR3(d, e, a, b, c, 57); nR3(c, d, e, a, b, 58); nR3(b, c, d, e, a, 59);
} }
void void do_R4(uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d, uint32_t *e, CHAR64LONG16 *block)
do_R4(uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d, uint32_t *e, CHAR64LONG16 *block)
{ {
nR4(a,b,c,d,e,60); nR4(e,a,b,c,d,61); nR4(d,e,a,b,c,62); nR4(c,d,e,a,b,63); nR4(a, b, c, d, e, 60); nR4(e, a, b, c, d, 61); nR4(d, e, a, b, c, 62); nR4(c, d, e, a, b, 63);
nR4(b,c,d,e,a,64); nR4(a,b,c,d,e,65); nR4(e,a,b,c,d,66); nR4(d,e,a,b,c,67); nR4(b, c, d, e, a, 64); nR4(a, b, c, d, e, 65); nR4(e, a, b, c, d, 66); nR4(d, e, a, b, c, 67);
nR4(c,d,e,a,b,68); nR4(b,c,d,e,a,69); nR4(a,b,c,d,e,70); nR4(e,a,b,c,d,71); nR4(c, d, e, a, b, 68); nR4(b, c, d, e, a, 69); nR4(a, b, c, d, e, 70); nR4(e, a, b, c, d, 71);
nR4(d,e,a,b,c,72); nR4(c,d,e,a,b,73); nR4(b,c,d,e,a,74); nR4(a,b,c,d,e,75); nR4(d, e, a, b, c, 72); nR4(c, d, e, a, b, 73); nR4(b, c, d, e, a, 74); nR4(a, b, c, d, e, 75);
nR4(e,a,b,c,d,76); nR4(d,e,a,b,c,77); nR4(c,d,e,a,b,78); nR4(b,c,d,e,a,79); nR4(e, a, b, c, d, 76); nR4(d, e, a, b, c, 77); nR4(c, d, e, a, b, 78); nR4(b, c, d, e, a, 79);
} }
#endif #endif /* ifdef SPARC64_GCC_WORKAROUND */
/* /*
* Hash a single 512-bit block. This is the core of the algorithm. * Hash a single 512-bit block. This is the core of the algorithm.
@ -177,27 +175,27 @@ void SHA1Transform(uint32_t state[5], const uint8_t buffer[64])
do_R4(&a, &b, &c, &d, &e, block); do_R4(&a, &b, &c, &d, &e, block);
#else #else
/* 4 rounds of 20 operations each. Loop unrolled. */ /* 4 rounds of 20 operations each. Loop unrolled. */
R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3); R0(a, b, c, d, e, 0); R0(e, a, b, c, d, 1); R0(d, e, a, b, c, 2); R0(c, d, e, a, b, 3);
R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7); R0(b, c, d, e, a, 4); R0(a, b, c, d, e, 5); R0(e, a, b, c, d, 6); R0(d, e, a, b, c, 7);
R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11); R0(c, d, e, a, b, 8); R0(b, c, d, e, a, 9); R0(a, b, c, d, e, 10); R0(e, a, b, c, d, 11);
R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15); R0(d, e, a, b, c, 12); R0(c, d, e, a, b, 13); R0(b, c, d, e, a, 14); R0(a, b, c, d, e, 15);
R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19); R1(e, a, b, c, d, 16); R1(d, e, a, b, c, 17); R1(c, d, e, a, b, 18); R1(b, c, d, e, a, 19);
R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23); R2(a, b, c, d, e, 20); R2(e, a, b, c, d, 21); R2(d, e, a, b, c, 22); R2(c, d, e, a, b, 23);
R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27); R2(b, c, d, e, a, 24); R2(a, b, c, d, e, 25); R2(e, a, b, c, d, 26); R2(d, e, a, b, c, 27);
R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31); R2(c, d, e, a, b, 28); R2(b, c, d, e, a, 29); R2(a, b, c, d, e, 30); R2(e, a, b, c, d, 31);
R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35); R2(d, e, a, b, c, 32); R2(c, d, e, a, b, 33); R2(b, c, d, e, a, 34); R2(a, b, c, d, e, 35);
R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39); R2(e, a, b, c, d, 36); R2(d, e, a, b, c, 37); R2(c, d, e, a, b, 38); R2(b, c, d, e, a, 39);
R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43); R3(a, b, c, d, e, 40); R3(e, a, b, c, d, 41); R3(d, e, a, b, c, 42); R3(c, d, e, a, b, 43);
R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47); R3(b, c, d, e, a, 44); R3(a, b, c, d, e, 45); R3(e, a, b, c, d, 46); R3(d, e, a, b, c, 47);
R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51); R3(c, d, e, a, b, 48); R3(b, c, d, e, a, 49); R3(a, b, c, d, e, 50); R3(e, a, b, c, d, 51);
R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55); R3(d, e, a, b, c, 52); R3(c, d, e, a, b, 53); R3(b, c, d, e, a, 54); R3(a, b, c, d, e, 55);
R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59); R3(e, a, b, c, d, 56); R3(d, e, a, b, c, 57); R3(c, d, e, a, b, 58); R3(b, c, d, e, a, 59);
R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63); R4(a, b, c, d, e, 60); R4(e, a, b, c, d, 61); R4(d, e, a, b, c, 62); R4(c, d, e, a, b, 63);
R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67); R4(b, c, d, e, a, 64); R4(a, b, c, d, e, 65); R4(e, a, b, c, d, 66); R4(d, e, a, b, c, 67);
R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71); R4(c, d, e, a, b, 68); R4(b, c, d, e, a, 69); R4(a, b, c, d, e, 70); R4(e, a, b, c, d, 71);
R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75); R4(d, e, a, b, c, 72); R4(c, d, e, a, b, 73); R4(b, c, d, e, a, 74); R4(a, b, c, d, e, 75);
R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79); R4(e, a, b, c, d, 76); R4(d, e, a, b, c, 77); R4(c, d, e, a, b, 78); R4(b, c, d, e, a, 79);
#endif #endif /* ifdef SPARC64_GCC_WORKAROUND */
/* Add the working vars back into context.state[] */ /* Add the working vars back into context.state[] */
state[0] += a; state[0] += a;
@ -216,7 +214,6 @@ void SHA1Transform(uint32_t state[5], const uint8_t buffer[64])
*/ */
void SHA1Init(SHA1_CTX *context) void SHA1Init(SHA1_CTX *context)
{ {
/* SHA1 initialization constants */ /* SHA1 initialization constants */
context->state[0] = 0x67452301; context->state[0] = 0x67452301;
context->state[1] = 0xEFCDAB89; context->state[1] = 0xEFCDAB89;
@ -235,17 +232,19 @@ void SHA1Update(SHA1_CTX *context, const uint8_t *data, unsigned int len)
unsigned int i, j; unsigned int i, j;
j = context->count[0]; j = context->count[0];
if ((context->count[0] += len << 3) < j) if ((context->count[0] += len << 3) < j) {
context->count[1] += (len>>29)+1; context->count[1] += (len >> 29) + 1;
}
j = (j >> 3) & 63; j = (j >> 3) & 63;
if ((j + len) > 63) { if ((j + len) > 63) {
(void)memcpy(&context->buffer[j], data, (i = 64-j)); (void)memcpy(&context->buffer[j], data, (i = 64 - j));
SHA1Transform(context->state, context->buffer); SHA1Transform(context->state, context->buffer);
for ( ; i + 63 < len; i += 64) for (; i + 63 < len; i += 64) {
SHA1Transform(context->state, &data[i]); SHA1Transform(context->state, &data[i]);
j = 0; }
j = 0;
} else { } else {
i = 0; i = 0;
} }
(void)memcpy(&context->buffer[j], &data[i], len - i); (void)memcpy(&context->buffer[j], &data[i], len - i);
} }
@ -260,18 +259,20 @@ void SHA1Final(uint8_t digest[20], SHA1_CTX *context)
uint8_t finalcount[8]; uint8_t finalcount[8];
for (i = 0; i < 8; i++) { for (i = 0; i < 8; i++) {
finalcount[i] = (uint8_t)((context->count[(i >= 4 ? 0 : 1)] finalcount[i] = (uint8_t)((context->count[(i >= 4 ? 0 : 1)]
>> ((3-(i & 3)) * 8) ) & 255); /* Endian independent */ >> ((3 - (i & 3)) * 8)) & 255); /* Endian independent */
} }
SHA1Update(context, (const uint8_t *)"\200", 1); SHA1Update(context, (const uint8_t *)"\200", 1);
while ((context->count[0] & 504) != 448) while ((context->count[0] & 504) != 448) {
SHA1Update(context, (const uint8_t *)"\0", 1); SHA1Update(context, (const uint8_t *)"\0", 1);
SHA1Update(context, finalcount, 8); /* Should cause a SHA1Transform() */ }
SHA1Update(context, finalcount, 8); /* Should cause a SHA1Transform() */
if (digest) { if (digest) {
for (i = 0; i < 20; i++) for (i = 0; i < 20; i++) {
digest[i] = (uint8_t) digest[i] = (uint8_t)
((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255); ((context->state[i >> 2] >> ((3 - (i & 3)) * 8)) & 255);
}
} }
} }

View File

@ -124,8 +124,8 @@
#define USB_LED_OFF #define USB_LED_OFF
#endif #endif
#define CONNECTED_TIMEOUT (250 / portTICK_RATE_MS) /* ms */ #define CONNECTED_TIMEOUT (250 / portTICK_RATE_MS) /* ms */
#define MAX_CHANNELS 32 #define MAX_CHANNELS 32
/* Local type definitions */ /* Local type definitions */
@ -204,9 +204,9 @@ static void rfm22_clearLEDs();
static uint32_t pios_rfm22_time_difference_ms(portTickType start_time, portTickType end_time); static uint32_t pios_rfm22_time_difference_ms(portTickType start_time, portTickType end_time);
static struct pios_rfm22b_dev *pios_rfm22_alloc(void); static struct pios_rfm22b_dev *pios_rfm22_alloc(void);
static void rfm22_hmac_sha1(const uint8_t *data, size_t len, uint8_t key[SHA1_DIGEST_LENGTH], static void rfm22_hmac_sha1(const uint8_t *data, size_t len, uint8_t key[SHA1_DIGEST_LENGTH],
uint8_t digest[SHA1_DIGEST_LENGTH]); uint8_t digest[SHA1_DIGEST_LENGTH]);
static bool rfm22_gen_channels(uint32_t coordid, enum rfm22b_datarate datarate, uint8_t min, static bool rfm22_gen_channels(uint32_t coordid, enum rfm22b_datarate datarate, uint8_t min,
uint8_t max, uint8_t channels[MAX_CHANNELS], uint8_t *clen); uint8_t max, uint8_t channels[MAX_CHANNELS], uint8_t *clen);
// SPI read/write functions // SPI read/write functions
static void rfm22_assertCs(struct pios_rfm22b_dev *rfm22b_dev); static void rfm22_assertCs(struct pios_rfm22b_dev *rfm22b_dev);
@ -332,15 +332,15 @@ static const uint32_t data_rate[] = {
}; };
static const uint8_t channel_spacing[] = { static const uint8_t channel_spacing[] = {
1, /* 9.6kbps */ 1, /* 9.6kbps */
2, /* 19.2kps */ 2, /* 19.2kps */
2, /* 32kps */ 2, /* 32kps */
2, /* 57.6kps */ 2, /* 57.6kps */
2, /* 64kps */ 2, /* 64kps */
3, /* 100kps */ 3, /* 100kps */
4, /* 128kps */ 4, /* 128kps */
4, /* 192kps */ 4, /* 192kps */
4 /* 256kps */ 4 /* 256kps */
}; };
static const uint8_t reg_1C[] = { 0x01, 0x05, 0x06, 0x95, 0x95, 0x81, 0x88, 0x8B, 0x8D }; // rfm22_if_filter_bandwidth static const uint8_t reg_1C[] = { 0x01, 0x05, 0x06, 0x95, 0x95, 0x81, 0x88, 0x8B, 0x8D }; // rfm22_if_filter_bandwidth
@ -609,7 +609,7 @@ void PIOS_RFM22B_SetChannelConfig(uint32_t rfm22b_id, enum rfm22b_datarate datar
uint8_t num_found = 0; uint8_t num_found = 0;
rfm22_gen_channels(rfm22_destinationID(rfm22b_dev), datarate, min_chan, max_chan, rfm22_gen_channels(rfm22_destinationID(rfm22b_dev), datarate, min_chan, max_chan,
rfm22b_dev->channels, &num_found); rfm22b_dev->channels, &num_found);
rfm22b_dev->num_channels = num_found; rfm22b_dev->num_channels = num_found;
@ -1361,7 +1361,7 @@ static enum pios_radio_event rfm22_init(struct pios_rfm22b_dev *rfm22b_dev)
rfm22b_dev->packet_start_ticks = 0; rfm22b_dev->packet_start_ticks = 0;
rfm22b_dev->tx_complete_ticks = 0; rfm22b_dev->tx_complete_ticks = 0;
rfm22b_dev->rfm22b_state = RFM22B_STATE_INITIALIZING; rfm22b_dev->rfm22b_state = RFM22B_STATE_INITIALIZING;
rfm22b_dev->last_contact = 0; rfm22b_dev->last_contact = 0;
// software reset the RF chip .. following procedure according to Si4x3x Errata (rev. B) // software reset the RF chip .. following procedure according to Si4x3x Errata (rev. B)
rfm22_write_claim(rfm22b_dev, RFM22_op_and_func_ctrl1, RFM22_opfc1_swres); rfm22_write_claim(rfm22b_dev, RFM22_op_and_func_ctrl1, RFM22_opfc1_swres);
@ -1984,7 +1984,7 @@ static enum pios_radio_event radio_receivePacket(struct pios_rfm22b_dev *radio_d
* If the packet is valid and destined for us we synchronize the clock. * If the packet is valid and destined for us we synchronize the clock.
*/ */
if (!rfm22_isCoordinator(radio_dev) && if (!rfm22_isCoordinator(radio_dev) &&
radio_dev->rx_destination_id == rfm22_destinationID(radio_dev)) { radio_dev->rx_destination_id == rfm22_destinationID(radio_dev)) {
rfm22_synchronizeClock(radio_dev); rfm22_synchronizeClock(radio_dev);
radio_dev->stats.link_state = OPLINKSTATUS_LINKSTATE_CONNECTED; radio_dev->stats.link_state = OPLINKSTATUS_LINKSTATE_CONNECTED;
} }
@ -2094,7 +2094,7 @@ static void rfm22_calculateLinkQuality(struct pios_rfm22b_dev *rfm22b_dev)
rfm22b_dev->stats.rx_good = 0; rfm22b_dev->stats.rx_good = 0;
rfm22b_dev->stats.rx_corrected = 0; rfm22b_dev->stats.rx_corrected = 0;
rfm22b_dev->stats.rx_error = 0; rfm22b_dev->stats.rx_error = 0;
rfm22b_dev->stats.rx_failure = 0; rfm22b_dev->stats.rx_failure = 0;
for (uint8_t i = 0; i < RFM22B_RX_PACKET_STATS_LEN; ++i) { for (uint8_t i = 0; i < RFM22B_RX_PACKET_STATS_LEN; ++i) {
uint32_t val = rfm22b_dev->rx_packet_stats[i]; uint32_t val = rfm22b_dev->rx_packet_stats[i];
for (uint8_t j = 0; j < 16; ++j) { for (uint8_t j = 0; j < 16; ++j) {
@ -2192,7 +2192,7 @@ static void rfm22_synchronizeClock(struct pios_rfm22b_dev *rfm22b_dev)
uint8_t offset = (uint8_t)ceil(35000.0F / data_rate[rfm22b_dev->datarate]); uint8_t offset = (uint8_t)ceil(35000.0F / data_rate[rfm22b_dev->datarate]);
rfm22b_dev->time_delta = frequency_hop_cycle_time - time_delta + offset + rfm22b_dev->time_delta = frequency_hop_cycle_time - time_delta + offset +
rfm22b_dev->packet_time * rfm22b_dev->channel_index; rfm22b_dev->packet_time * rfm22b_dev->channel_index;
} }
/** /**
@ -2252,9 +2252,8 @@ static uint8_t rfm22_calcChannel(struct pios_rfm22b_dev *rfm22b_dev, uint8_t ind
// Are we switching to a new channel? // Are we switching to a new channel?
if (idx != rfm22b_dev->channel_index) { if (idx != rfm22b_dev->channel_index) {
if (!rfm22_isCoordinator(rfm22b_dev) && if (!rfm22_isCoordinator(rfm22b_dev) &&
pios_rfm22_time_difference_ms(rfm22b_dev->last_contact, xTaskGetTickCount()) >= pios_rfm22_time_difference_ms(rfm22b_dev->last_contact, xTaskGetTickCount()) >=
CONNECTED_TIMEOUT) { CONNECTED_TIMEOUT) {
// Set the link state to disconnected. // Set the link state to disconnected.
if (rfm22b_dev->stats.link_state == OPLINKSTATUS_LINKSTATE_CONNECTED) { if (rfm22b_dev->stats.link_state == OPLINKSTATUS_LINKSTATE_CONNECTED) {
rfm22b_dev->stats.link_state = OPLINKSTATUS_LINKSTATE_DISCONNECTED; rfm22b_dev->stats.link_state = OPLINKSTATUS_LINKSTATE_DISCONNECTED;
@ -2574,13 +2573,12 @@ static uint8_t rfm22_read(struct pios_rfm22b_dev *rfm22b_dev, uint8_t addr)
} }
static void static void rfm22_hmac_sha1(const uint8_t *data, size_t len,
rfm22_hmac_sha1(const uint8_t *data, size_t len, uint8_t key[SHA1_DIGEST_LENGTH],
uint8_t key[SHA1_DIGEST_LENGTH], uint8_t digest[SHA1_DIGEST_LENGTH])
uint8_t digest[SHA1_DIGEST_LENGTH])
{ {
uint8_t ipad[64] = {0}; uint8_t ipad[64] = { 0 };
uint8_t opad[64] = {0}; uint8_t opad[64] = { 0 };
static SHA1_CTX *ctx; static SHA1_CTX *ctx;
ctx = pios_malloc(sizeof(SHA1_CTX)); ctx = pios_malloc(sizeof(SHA1_CTX));
@ -2606,14 +2604,13 @@ rfm22_hmac_sha1(const uint8_t *data, size_t len,
pios_free(ctx); pios_free(ctx);
} }
static bool static bool rfm22_gen_channels(uint32_t coordid, enum rfm22b_datarate rate, uint8_t min,
rfm22_gen_channels(uint32_t coordid, enum rfm22b_datarate rate, uint8_t min, uint8_t max, uint8_t channels[MAX_CHANNELS], uint8_t *clen)
uint8_t max, uint8_t channels[MAX_CHANNELS], uint8_t *clen)
{ {
uint32_t data = 0; uint32_t data = 0;
uint8_t cpos = 0; uint8_t cpos = 0;
uint8_t chan_range = (max / channel_spacing[rate] - min / channel_spacing[rate]) + 1; uint8_t chan_range = (max / channel_spacing[rate] - min / channel_spacing[rate]) + 1;
uint8_t key[SHA1_DIGEST_LENGTH] = {0}; uint8_t key[SHA1_DIGEST_LENGTH] = { 0 };
uint8_t digest[SHA1_DIGEST_LENGTH]; uint8_t digest[SHA1_DIGEST_LENGTH];
uint8_t *all_channels; uint8_t *all_channels;
@ -2632,27 +2629,27 @@ rfm22_gen_channels(uint32_t coordid, enum rfm22b_datarate rate, uint8_t min,
uint8_t tmp; uint8_t tmp;
if (j == SHA1_DIGEST_LENGTH) { if (j == SHA1_DIGEST_LENGTH) {
rfm22_hmac_sha1((uint8_t *) &data, sizeof(data), key, digest); rfm22_hmac_sha1((uint8_t *)&data, sizeof(data), key, digest);
j = 0; j = 0;
data++; data++;
} }
rnd = digest[j]; rnd = digest[j];
j++; j++;
r = rnd % (chan_range - i) + i; r = rnd % (chan_range - i) + i;
tmp = all_channels[i]; tmp = all_channels[i];
all_channels[i] = all_channels[r]; all_channels[i] = all_channels[r];
all_channels[r] = tmp; all_channels[r] = tmp;
} }
for (int i = 0; i < chan_range && cpos < MAX_CHANNELS; i++, cpos++) { for (int i = 0; i < chan_range && cpos < MAX_CHANNELS; i++, cpos++) {
channels[cpos] =all_channels[i] * channel_spacing[rate]; channels[cpos] = all_channels[i] * channel_spacing[rate];
} }
*clen = cpos & 0xfe; *clen = cpos & 0xfe;
pios_free(all_channels); pios_free(all_channels);
return (*clen > 0); return *clen > 0;
} }
#endif /* PIOS_INCLUDE_RFM22B */ #endif /* PIOS_INCLUDE_RFM22B */

View File

@ -578,7 +578,7 @@ enum pios_rfm22b_rx_packet_status {
RADIO_GOOD_RX_PACKET = 0x00, RADIO_GOOD_RX_PACKET = 0x00,
RADIO_CORRECTED_RX_PACKET = 0x01, RADIO_CORRECTED_RX_PACKET = 0x01,
RADIO_ERROR_RX_PACKET = 0x2, RADIO_ERROR_RX_PACKET = 0x2,
RADIO_FAILURE_RX_PACKET = 0x3 RADIO_FAILURE_RX_PACKET = 0x3
}; };
typedef struct { typedef struct {

View File

@ -443,69 +443,70 @@ void PIOS_Board_Init(void)
/* Set the PPM callback if we should be receiving PPM. */ /* Set the PPM callback if we should be receiving PPM. */
if (ppm_mode || (ppm_only && !is_coordinator)) { if (ppm_mode || (ppm_only && !is_coordinator)) {
PIOS_RFM22B_SetPPMCallback(pios_rfm22b_id, PIOS_Board_PPM_callback); PIOS_RFM22B_SetPPMCallback(pios_rfm22b_id, PIOS_Board_PPM_callback);
} }
// Reinitilize the modem to affect te changes. // Reinitilize the modem to affect te changes.
PIOS_RFM22B_Reinit(pios_rfm22b_id); PIOS_RFM22B_Reinit(pios_rfm22b_id);
} else { } else {
oplinkStatus.LinkState = OPLINKSTATUS_LINKSTATE_DISABLED; oplinkStatus.LinkState = OPLINKSTATUS_LINKSTATE_DISABLED;
} }
// Update the object // Update the object
OPLinkStatusSet(&oplinkStatus); OPLinkStatusSet(&oplinkStatus);
// Update the com baud rate. // Update the com baud rate.
uint32_t comBaud = 9600; uint32_t comBaud = 9600;
switch (oplinkSettings.ComSpeed) { switch (oplinkSettings.ComSpeed) {
case OPLINKSETTINGS_COMSPEED_4800: case OPLINKSETTINGS_COMSPEED_4800:
comBaud = 4800; comBaud = 4800;
break; break;
case OPLINKSETTINGS_COMSPEED_9600: case OPLINKSETTINGS_COMSPEED_9600:
comBaud = 9600; comBaud = 9600;
break; break;
case OPLINKSETTINGS_COMSPEED_19200: case OPLINKSETTINGS_COMSPEED_19200:
comBaud = 19200; comBaud = 19200;
break; break;
case OPLINKSETTINGS_COMSPEED_38400: case OPLINKSETTINGS_COMSPEED_38400:
comBaud = 38400; comBaud = 38400;
break; break;
case OPLINKSETTINGS_COMSPEED_57600: case OPLINKSETTINGS_COMSPEED_57600:
comBaud = 57600; comBaud = 57600;
break; break;
case OPLINKSETTINGS_COMSPEED_115200: case OPLINKSETTINGS_COMSPEED_115200:
comBaud = 115200; comBaud = 115200;
break; break;
} }
if (PIOS_COM_TELEMETRY) { if (PIOS_COM_TELEMETRY) {
PIOS_COM_ChangeBaud(PIOS_COM_TELEMETRY, comBaud); PIOS_COM_ChangeBaud(PIOS_COM_TELEMETRY, comBaud);
} }
/* Remap AFIO pin */ /* Remap AFIO pin */
GPIO_PinRemapConfig(GPIO_Remap_SWJ_NoJTRST, ENABLE); GPIO_PinRemapConfig(GPIO_Remap_SWJ_NoJTRST, ENABLE);
#ifdef PIOS_INCLUDE_ADC #ifdef PIOS_INCLUDE_ADC
PIOS_ADC_Init(); PIOS_ADC_Init();
#endif #endif
} }
static void PIOS_Board_PPM_callback(const int16_t * channels) { static void PIOS_Board_PPM_callback(const int16_t *channels)
{
#if defined(PIOS_INCLUDE_PPM) && defined(PIOS_INCLUDE_PPM_OUT) #if defined(PIOS_INCLUDE_PPM) && defined(PIOS_INCLUDE_PPM_OUT)
if (pios_ppm_out_id) { if (pios_ppm_out_id) {
for (uint8_t i = 0; i < RFM22B_PPM_NUM_CHANNELS; ++i) { for (uint8_t i = 0; i < RFM22B_PPM_NUM_CHANNELS; ++i) {
if (channels[i] != PIOS_RCVR_INVALID) { if (channels[i] != PIOS_RCVR_INVALID) {
PIOS_PPM_OUT_Set(PIOS_PPM_OUTPUT, i, channels[i]); PIOS_PPM_OUT_Set(PIOS_PPM_OUTPUT, i, channels[i]);
} }
} }
} }
#if defined(PIOS_INCLUDE_SERVO) #if defined(PIOS_INCLUDE_SERVO)
for (uint8_t i = 0; i < servo_count; ++i) { for (uint8_t i = 0; i < servo_count; ++i) {
uint16_t val = (channels[i] == PIOS_RCVR_INVALID) ? 0 : channels[i]; uint16_t val = (channels[i] == PIOS_RCVR_INVALID) ? 0 : channels[i];
PIOS_Servo_Set(i, val); PIOS_Servo_Set(i, val);
} }
#endif /* PIOS_INCLUDE_SERVO */ #endif /* PIOS_INCLUDE_SERVO */
#endif /* PIOS_INCLUDE_PPM && PIOS_INCLUDE_PPM_OUT */ #endif /* PIOS_INCLUDE_PPM && PIOS_INCLUDE_PPM_OUT */
} }
/** /**
* @} * @}