From aa55b1523ddb44f5663bcc1f73499f16ce5a999a Mon Sep 17 00:00:00 2001 From: Alessio Morale Date: Thu, 5 Feb 2015 01:42:32 +0100 Subject: [PATCH] uncrustify --- flight/libraries/inc/sha1.h | 28 +-- flight/libraries/sha1.c | 179 +++++++++--------- flight/pios/common/pios_rfm22b.c | 69 ++++--- flight/pios/inc/pios_rfm22b_priv.h | 2 +- .../boards/oplinkmini/firmware/pios_board.c | 103 +++++----- 5 files changed, 190 insertions(+), 191 deletions(-) diff --git a/flight/libraries/inc/sha1.h b/flight/libraries/inc/sha1.h index b936c3938..fbf18b137 100644 --- a/flight/libraries/inc/sha1.h +++ b/flight/libraries/inc/sha1.h @@ -7,30 +7,30 @@ */ #ifndef _SYS_SHA1_H_ -#define _SYS_SHA1_H_ +#define _SYS_SHA1_H_ #include #include -#define SHA1_DIGEST_LENGTH 20 -#define SHA1_DIGEST_STRING_LENGTH 41 +#define SHA1_DIGEST_LENGTH 20 +#define SHA1_DIGEST_STRING_LENGTH 41 typedef struct { - uint32_t state[5]; - uint32_t count[2]; - uint8_t buffer[64]; + uint32_t state[5]; + uint32_t count[2]; + uint8_t buffer[64]; } SHA1_CTX; __BEGIN_DECLS -void SHA1Transform(uint32_t[5], const uint8_t[64]); -void SHA1Init(SHA1_CTX *); -void SHA1Update(SHA1_CTX *, const uint8_t *, unsigned int); -void SHA1Final(uint8_t[SHA1_DIGEST_LENGTH], SHA1_CTX *); +void SHA1Transform(uint32_t[5], const uint8_t[64]); +void SHA1Init(SHA1_CTX *); +void SHA1Update(SHA1_CTX *, const uint8_t *, unsigned int); +void SHA1Final(uint8_t[SHA1_DIGEST_LENGTH], SHA1_CTX *); #ifndef _KERNEL -char *SHA1End(SHA1_CTX *, char *); -char *SHA1FileChunk(const char *, char *, off_t, off_t); -char *SHA1File(const char *, char *); -char *SHA1Data(const uint8_t *, size_t, char *); +char *SHA1End(SHA1_CTX *, char *); +char *SHA1FileChunk(const char *, char *, off_t, off_t); +char *SHA1File(const char *, char *); +char *SHA1Data(const uint8_t *, size_t, char *); #endif /* _KERNEL */ __END_DECLS diff --git a/flight/libraries/sha1.c b/flight/libraries/sha1.c index 5f2859e15..82bfe060f 100644 --- a/flight/libraries/sha1.c +++ b/flight/libraries/sha1.c @@ -15,7 +15,7 @@ * 34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F */ -#define SHA1HANDSOFF /* Copies data before messing with it. */ +#define SHA1HANDSOFF /* Copies data before messing with it. */ #include @@ -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 $"); #endif /* LIBC_SCCS and not lint */ -//#include "namespace.h" +// #include "namespace.h" #include #include @@ -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 */ #if BYTE_ORDER == LITTLE_ENDIAN -# define blk0(i) (block->l[i] = (rol(block->l[i],24)&0xFF00FF00) \ - |(rol(block->l[i],8)&0x00FF00FF)) +# define blk0(i) \ + (block->l[i] = (rol(block->l[i], 24) & 0xFF00FF00) \ + | (rol(block->l[i], 8) & 0x00FF00FF)) #else -# define blk0(i) block->l[i] +# define blk0(i) block->l[i] #endif -#define blk(i) (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)) +#define blk(i) \ + (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 */ -#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 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 R4(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0xCA62C1D6+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 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 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(__weak_alias) -__weak_alias(SHA1Transform,_SHA1Transform) -__weak_alias(SHA1Init,_SHA1Init) -__weak_alias(SHA1Update,_SHA1Update) -__weak_alias(SHA1Final,_SHA1Final) +__weak_alias(SHA1Transform, _SHA1Transform) +__weak_alias(SHA1Init, _SHA1Init) +__weak_alias(SHA1Update, _SHA1Update) +__weak_alias(SHA1Final, _SHA1Final) #endif #endif typedef union { - uint8_t c[64]; + uint8_t c[64]; uint32_t l[16]; } 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_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 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 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 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 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 nR4(v, w, x, y, z, i) R4(*v, *w, *x, *y, *z, i) -void -do_R01(uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d, uint32_t *e, CHAR64LONG16 *block) +void 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(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(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); + 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(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); + 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 -do_R2(uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d, uint32_t *e, CHAR64LONG16 *block) +void 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(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(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(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(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(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 -do_R3(uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d, uint32_t *e, CHAR64LONG16 *block) +void 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(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(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(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(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(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 -do_R4(uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d, uint32_t *e, CHAR64LONG16 *block) +void 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(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(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(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(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(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. @@ -177,27 +175,27 @@ void SHA1Transform(uint32_t state[5], const uint8_t buffer[64]) do_R4(&a, &b, &c, &d, &e, block); #else /* 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(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(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); - 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(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(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(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(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); - 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(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(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 + 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(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); + 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(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(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); + 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(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(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(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(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); +#endif /* ifdef SPARC64_GCC_WORKAROUND */ /* Add the working vars back into context.state[] */ state[0] += a; @@ -216,7 +214,6 @@ void SHA1Transform(uint32_t state[5], const uint8_t buffer[64]) */ void SHA1Init(SHA1_CTX *context) { - /* SHA1 initialization constants */ context->state[0] = 0x67452301; context->state[1] = 0xEFCDAB89; @@ -235,17 +232,19 @@ void SHA1Update(SHA1_CTX *context, const uint8_t *data, unsigned int len) unsigned int i, j; j = context->count[0]; - if ((context->count[0] += len << 3) < j) - context->count[1] += (len>>29)+1; + if ((context->count[0] += len << 3) < j) { + context->count[1] += (len >> 29) + 1; + } j = (j >> 3) & 63; if ((j + len) > 63) { - (void)memcpy(&context->buffer[j], data, (i = 64-j)); - SHA1Transform(context->state, context->buffer); - for ( ; i + 63 < len; i += 64) - SHA1Transform(context->state, &data[i]); - j = 0; + (void)memcpy(&context->buffer[j], data, (i = 64 - j)); + SHA1Transform(context->state, context->buffer); + for (; i + 63 < len; i += 64) { + SHA1Transform(context->state, &data[i]); + } + j = 0; } else { - i = 0; + i = 0; } (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]; for (i = 0; i < 8; i++) { - finalcount[i] = (uint8_t)((context->count[(i >= 4 ? 0 : 1)] - >> ((3-(i & 3)) * 8) ) & 255); /* Endian independent */ + finalcount[i] = (uint8_t)((context->count[(i >= 4 ? 0 : 1)] + >> ((3 - (i & 3)) * 8)) & 255); /* Endian independent */ } SHA1Update(context, (const uint8_t *)"\200", 1); - while ((context->count[0] & 504) != 448) - SHA1Update(context, (const uint8_t *)"\0", 1); - SHA1Update(context, finalcount, 8); /* Should cause a SHA1Transform() */ + while ((context->count[0] & 504) != 448) { + SHA1Update(context, (const uint8_t *)"\0", 1); + } + SHA1Update(context, finalcount, 8); /* Should cause a SHA1Transform() */ if (digest) { - for (i = 0; i < 20; i++) - digest[i] = (uint8_t) - ((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255); + for (i = 0; i < 20; i++) { + digest[i] = (uint8_t) + ((context->state[i >> 2] >> ((3 - (i & 3)) * 8)) & 255); + } } } diff --git a/flight/pios/common/pios_rfm22b.c b/flight/pios/common/pios_rfm22b.c index 9e8530fbf..36f0c7a96 100644 --- a/flight/pios/common/pios_rfm22b.c +++ b/flight/pios/common/pios_rfm22b.c @@ -124,8 +124,8 @@ #define USB_LED_OFF #endif -#define CONNECTED_TIMEOUT (250 / portTICK_RATE_MS) /* ms */ -#define MAX_CHANNELS 32 +#define CONNECTED_TIMEOUT (250 / portTICK_RATE_MS) /* ms */ +#define MAX_CHANNELS 32 /* 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 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], - 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, - 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 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[] = { - 1, /* 9.6kbps */ - 2, /* 19.2kps */ - 2, /* 32kps */ - 2, /* 57.6kps */ - 2, /* 64kps */ - 3, /* 100kps */ - 4, /* 128kps */ - 4, /* 192kps */ - 4 /* 256kps */ + 1, /* 9.6kbps */ + 2, /* 19.2kps */ + 2, /* 32kps */ + 2, /* 57.6kps */ + 2, /* 64kps */ + 3, /* 100kps */ + 4, /* 128kps */ + 4, /* 192kps */ + 4 /* 256kps */ }; 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; 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; @@ -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->tx_complete_ticks = 0; 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) 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 (!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); 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_corrected = 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) { uint32_t val = rfm22b_dev->rx_packet_stats[i]; 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]); 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? if (idx != rfm22b_dev->channel_index) { if (!rfm22_isCoordinator(rfm22b_dev) && - pios_rfm22_time_difference_ms(rfm22b_dev->last_contact, xTaskGetTickCount()) >= - CONNECTED_TIMEOUT) { - + pios_rfm22_time_difference_ms(rfm22b_dev->last_contact, xTaskGetTickCount()) >= + CONNECTED_TIMEOUT) { // Set the link state to disconnected. if (rfm22b_dev->stats.link_state == OPLINKSTATUS_LINKSTATE_CONNECTED) { 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 -rfm22_hmac_sha1(const uint8_t *data, size_t len, - uint8_t key[SHA1_DIGEST_LENGTH], - uint8_t digest[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 ipad[64] = {0}; - uint8_t opad[64] = {0}; + uint8_t ipad[64] = { 0 }; + uint8_t opad[64] = { 0 }; static SHA1_CTX *ctx; ctx = pios_malloc(sizeof(SHA1_CTX)); @@ -2606,14 +2604,13 @@ rfm22_hmac_sha1(const uint8_t *data, size_t len, pios_free(ctx); } -static bool -rfm22_gen_channels(uint32_t coordid, enum rfm22b_datarate rate, uint8_t min, - uint8_t max, uint8_t channels[MAX_CHANNELS], uint8_t *clen) +static bool rfm22_gen_channels(uint32_t coordid, enum rfm22b_datarate rate, uint8_t min, + uint8_t max, uint8_t channels[MAX_CHANNELS], uint8_t *clen) { 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 key[SHA1_DIGEST_LENGTH] = {0}; + uint8_t key[SHA1_DIGEST_LENGTH] = { 0 }; uint8_t digest[SHA1_DIGEST_LENGTH]; uint8_t *all_channels; @@ -2632,27 +2629,27 @@ rfm22_gen_channels(uint32_t coordid, enum rfm22b_datarate rate, uint8_t min, uint8_t tmp; 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; data++; } rnd = digest[j]; j++; - r = rnd % (chan_range - i) + i; + r = rnd % (chan_range - i) + i; tmp = all_channels[i]; all_channels[i] = all_channels[r]; all_channels[r] = tmp; } 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; pios_free(all_channels); - return (*clen > 0); + return *clen > 0; } #endif /* PIOS_INCLUDE_RFM22B */ diff --git a/flight/pios/inc/pios_rfm22b_priv.h b/flight/pios/inc/pios_rfm22b_priv.h index 63745fd48..47cf9d5c0 100644 --- a/flight/pios/inc/pios_rfm22b_priv.h +++ b/flight/pios/inc/pios_rfm22b_priv.h @@ -578,7 +578,7 @@ enum pios_rfm22b_rx_packet_status { RADIO_GOOD_RX_PACKET = 0x00, RADIO_CORRECTED_RX_PACKET = 0x01, RADIO_ERROR_RX_PACKET = 0x2, - RADIO_FAILURE_RX_PACKET = 0x3 + RADIO_FAILURE_RX_PACKET = 0x3 }; typedef struct { diff --git a/flight/targets/boards/oplinkmini/firmware/pios_board.c b/flight/targets/boards/oplinkmini/firmware/pios_board.c index 4a027c647..34d033db3 100644 --- a/flight/targets/boards/oplinkmini/firmware/pios_board.c +++ b/flight/targets/boards/oplinkmini/firmware/pios_board.c @@ -443,69 +443,70 @@ void PIOS_Board_Init(void) /* Set the PPM callback if we should be receiving PPM. */ 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. - PIOS_RFM22B_Reinit(pios_rfm22b_id); - } else { - oplinkStatus.LinkState = OPLINKSTATUS_LINKSTATE_DISABLED; - } + // Reinitilize the modem to affect te changes. + PIOS_RFM22B_Reinit(pios_rfm22b_id); + } else { + oplinkStatus.LinkState = OPLINKSTATUS_LINKSTATE_DISABLED; + } - // Update the object - OPLinkStatusSet(&oplinkStatus); + // Update the object + OPLinkStatusSet(&oplinkStatus); - // Update the com baud rate. - uint32_t comBaud = 9600; - switch (oplinkSettings.ComSpeed) { - case OPLINKSETTINGS_COMSPEED_4800: - comBaud = 4800; - break; - case OPLINKSETTINGS_COMSPEED_9600: - comBaud = 9600; - break; - case OPLINKSETTINGS_COMSPEED_19200: - comBaud = 19200; - break; - case OPLINKSETTINGS_COMSPEED_38400: - comBaud = 38400; - break; - case OPLINKSETTINGS_COMSPEED_57600: - comBaud = 57600; - break; - case OPLINKSETTINGS_COMSPEED_115200: - comBaud = 115200; - break; - } - if (PIOS_COM_TELEMETRY) { - PIOS_COM_ChangeBaud(PIOS_COM_TELEMETRY, comBaud); - } + // Update the com baud rate. + uint32_t comBaud = 9600; + switch (oplinkSettings.ComSpeed) { + case OPLINKSETTINGS_COMSPEED_4800: + comBaud = 4800; + break; + case OPLINKSETTINGS_COMSPEED_9600: + comBaud = 9600; + break; + case OPLINKSETTINGS_COMSPEED_19200: + comBaud = 19200; + break; + case OPLINKSETTINGS_COMSPEED_38400: + comBaud = 38400; + break; + case OPLINKSETTINGS_COMSPEED_57600: + comBaud = 57600; + break; + case OPLINKSETTINGS_COMSPEED_115200: + comBaud = 115200; + break; + } + if (PIOS_COM_TELEMETRY) { + PIOS_COM_ChangeBaud(PIOS_COM_TELEMETRY, comBaud); + } - /* Remap AFIO pin */ - GPIO_PinRemapConfig(GPIO_Remap_SWJ_NoJTRST, ENABLE); + /* Remap AFIO pin */ + GPIO_PinRemapConfig(GPIO_Remap_SWJ_NoJTRST, ENABLE); #ifdef PIOS_INCLUDE_ADC - PIOS_ADC_Init(); + PIOS_ADC_Init(); #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 (pios_ppm_out_id) { - for (uint8_t i = 0; i < RFM22B_PPM_NUM_CHANNELS; ++i) { - if (channels[i] != PIOS_RCVR_INVALID) { - PIOS_PPM_OUT_Set(PIOS_PPM_OUTPUT, i, channels[i]); - } - } - } + if (pios_ppm_out_id) { + for (uint8_t i = 0; i < RFM22B_PPM_NUM_CHANNELS; ++i) { + if (channels[i] != PIOS_RCVR_INVALID) { + PIOS_PPM_OUT_Set(PIOS_PPM_OUTPUT, i, channels[i]); + } + } + } #if defined(PIOS_INCLUDE_SERVO) - for (uint8_t i = 0; i < servo_count; ++i) { - uint16_t val = (channels[i] == PIOS_RCVR_INVALID) ? 0 : channels[i]; - PIOS_Servo_Set(i, val); - } + for (uint8_t i = 0; i < servo_count; ++i) { + uint16_t val = (channels[i] == PIOS_RCVR_INVALID) ? 0 : channels[i]; + PIOS_Servo_Set(i, val); + } #endif /* PIOS_INCLUDE_SERVO */ #endif /* PIOS_INCLUDE_PPM && PIOS_INCLUDE_PPM_OUT */ - } +} /** * @}