summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@intec.ugent.be>2017-02-13 10:55:33 +0000
committerSander Vrijders <sander.vrijders@intec.ugent.be>2017-02-13 10:55:33 +0000
commit5ea091f9cde6090c4829e78b7d2ac5a566ede8f1 (patch)
treed4926c7856344dcc4aba9838b734ad0c67acb4ce /src/lib
parent344f834e85e9c7afc47e19226157c8e834725d2e (diff)
parent5cc79cfeb7a33c93ae9ef5781f9b0ecd4a958bee (diff)
downloadouroboros-5ea091f9cde6090c4829e78b7d2ac5a566ede8f1.tar.gz
ouroboros-5ea091f9cde6090c4829e78b7d2ac5a566ede8f1.zip
Merged in dstaesse/ouroboros/be-endian (pull request #371)
Check time synchronization upon enrollment
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/byte_order.h89
-rw-r--r--src/lib/cdap.c26
-rw-r--r--src/lib/dev.c5
3 files changed, 21 insertions, 99 deletions
diff --git a/src/lib/byte_order.h b/src/lib/byte_order.h
index 364b06cc..a0c72cf5 100644
--- a/src/lib/byte_order.h
+++ b/src/lib/byte_order.h
@@ -40,62 +40,10 @@
* or FITNESS FOR A PARTICULAR PURPOSE. Use this program at your own risk!
*/
-/* byte_order.h */
#ifndef OUROBOROS_BYTE_ORDER_H
#define OUROBOROS_BYTE_ORDER_H
-#include <stdint.h>
-#include <unistd.h>
-#include <stdlib.h>
-
-#ifdef __GLIBC__
-#include <endian.h>
-#elif defined(__FreeBSD__)
-#include <sys/endian.h>
-#endif
-
-/* if x86 compatible cpu */
-#if defined(i386) || defined(__i386__) || defined(__i486__) || \
- defined(__i586__) || defined(__i686__) || defined(__pentium__) || \
- defined(__pentiumpro__) || defined(__pentium4__) || \
- defined(__nocona__) || defined(prescott) || defined(__core2__) || \
- defined(__k6__) || defined(__k8__) || defined(__athlon__) || \
- defined(__amd64) || defined(__amd64__) || \
- defined(__x86_64) || defined(__x86_64__) || defined(_M_IX86) || \
- defined(_M_AMD64) || defined(_M_IA64) || defined(_M_X64)
-/* detect if x86-64 instruction set is supported */
-# if defined(_LP64) || defined(__LP64__) || defined(__x86_64) || \
- defined(__x86_64__) || defined(_M_AMD64) || defined(_M_X64)
-# define CPU_X64
-# else
-# define CPU_IA32
-# endif
-#endif
-
-/* detect CPU endianness */
-#if (defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && \
- __BYTE_ORDER == __LITTLE_ENDIAN) || \
- defined(CPU_IA32) || defined(CPU_X64) || \
- defined(__ia64) || defined(__ia64__) || defined(__alpha__) || \
- defined(_M_ALPHA) || defined(vax) || defined(MIPSEL) || \
- defined(_ARM_) || defined(__arm__)
-#define CPU_LITTLE_ENDIAN
-#define IS_BIG_ENDIAN 0
-#define IS_LITTLE_ENDIAN 1
-#elif (defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) && \
- __BYTE_ORDER == __BIG_ENDIAN) || \
- defined(__sparc) || defined(__sparc__) || defined(sparc) || \
- defined(_ARCH_PPC) || defined(_ARCH_PPC64) || defined(_POWER) || \
- defined(__POWERPC__) || defined(POWERPC) || defined(__powerpc) || \
- defined(__powerpc__) || defined(__powerpc64__) || defined(__ppc__) || \
- defined(__hpux) || defined(_MIPSEB) || defined(mc68000) || \
- defined(__s390__) || defined(__s390x__) || defined(sel)
-#define CPU_BIG_ENDIAN
-#define IS_BIG_ENDIAN 1
-#define IS_LITTLE_ENDIAN 0
-#else
-# error "Can't detect CPU architecture."
-#endif
+#include <ouroboros/endian.h>
#define IS_ALIGNED_32(p) (0 == (3 & ((const char*)(p) - (const char*)0)))
#define IS_ALIGNED_64(p) (0 == (7 & ((const char*)(p) - (const char*)0)))
@@ -115,41 +63,6 @@
unsigned rhash_ctz(unsigned); /* define as function */
#endif
-#if defined(__GNUC__) && (__GNUC__ >= 4) && \
- (__GNUC__ > 4 || __GNUC_MINOR__ >= 3)
-/* for GCC >= 4.3 */
-#define bswap_32(x) __builtin_bswap32(x)
-#elif !defined(__STRICT_ANSI__)
-/* general bswap_32 definition */
-static inline uint32_t bswap_32(uint32_t x) {
- x = ((x << 8) & 0xFF00FF00) | ((x >> 8) & 0x00FF00FF);
- return (x >> 16) | (x << 16);
-}
-#else
-#define bswap_32(x) ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
- (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
-#endif /* bswap_32 */
-
-#if defined(__GNUC__) && (__GNUC__ >= 4) && \
- (__GNUC__ > 4 || __GNUC_MINOR__ >= 3)
-#define bswap_64(x) __builtin_bswap64(x)
-#elif !defined (bswap64)
-#if !defined(__STRICT_ANSI__)
-static inline uint64_t bswap_64(uint64_t x) {
- union {
- uint64_t ll;
- uint32_t l[2];
- } w, r;
- w.ll = x;
- r.l[0] = bswap_32(w.l[1]);
- r.l[1] = bswap_32(w.l[0]);
- return r.ll;
-}
-#else
-#error "bswap_64 unsupported"
-#endif
-#endif
-
#ifdef CPU_BIG_ENDIAN
#define be2me_32(x) (x)
#define be2me_64(x) (x)
diff --git a/src/lib/cdap.c b/src/lib/cdap.c
index 956486d1..6c46775c 100644
--- a/src/lib/cdap.c
+++ b/src/lib/cdap.c
@@ -67,7 +67,7 @@ struct cdap_rcvd {
enum cdap_opcode opcode;
char * name;
- uint8_t * data;
+ void * data;
size_t len;
uint32_t flags;
};
@@ -89,7 +89,8 @@ static int next_invoke_id(struct cdap * instance)
return ret;
}
-static int release_invoke_id(struct cdap * instance, int id)
+static int release_invoke_id(struct cdap * instance,
+ int id)
{
int ret;
@@ -130,7 +131,8 @@ static struct cdap_req * cdap_sent_get_by_key(struct cdap * instance,
return NULL;
}
-static struct cdap_req * cdap_sent_add(struct cdap * instance, cdap_key_t key)
+static struct cdap_req * cdap_sent_add(struct cdap * instance,
+ cdap_key_t key)
{
struct cdap_req * req;
@@ -151,7 +153,8 @@ static struct cdap_req * cdap_sent_add(struct cdap * instance, cdap_key_t key)
return req;
}
-static void cdap_sent_del(struct cdap * instance, struct cdap_req * req)
+static void cdap_sent_del(struct cdap * instance,
+ struct cdap_req * req)
{
assert(instance);
assert(req);
@@ -405,7 +408,8 @@ int cdap_destroy(struct cdap * instance)
return 0;
}
-static int write_msg(struct cdap * instance, cdap_t * msg)
+static int write_msg(struct cdap * instance,
+ cdap_t * msg)
{
int ret;
uint8_t * data;
@@ -449,8 +453,8 @@ static invoke_id_t key_to_invoke_id(cdap_key_t key)
cdap_key_t cdap_request_send(struct cdap * instance,
enum cdap_opcode code,
- char * name,
- uint8_t * data,
+ const char * name,
+ const void * data,
size_t len,
uint32_t flags)
{
@@ -491,13 +495,13 @@ cdap_key_t cdap_request_send(struct cdap * instance,
return -EINVAL;
}
- msg.name = name;
+ msg.name = (char *) name;
msg.has_flags = true;
msg.flags = flags;
msg.invoke_id = iid;
if (data != NULL) {
msg.has_value = true;
- msg.value.data = data;
+ msg.value.data = (uint8_t *) data;
msg.value.len = len;
}
@@ -599,7 +603,7 @@ cdap_key_t cdap_request_wait(struct cdap * instance,
int cdap_reply_send(struct cdap * instance,
cdap_key_t key,
int result,
- uint8_t * data,
+ const void * data,
size_t len)
{
cdap_t msg = CDAP__INIT;
@@ -615,7 +619,7 @@ int cdap_reply_send(struct cdap * instance,
if (data != NULL) {
msg.has_value = true;
- msg.value.data = data;
+ msg.value.data = (uint8_t *) data;
msg.value.len = len;
}
diff --git a/src/lib/dev.c b/src/lib/dev.c
index 38f7cddf..4d85a5d9 100644
--- a/src/lib/dev.c
+++ b/src/lib/dev.c
@@ -402,6 +402,11 @@ int flow_accept(char ** ae_name,
if (recv_msg == NULL)
return -EIRMD;
+ if (recv_msg->has_result) {
+ irm_msg__free_unpacked(recv_msg, NULL);
+ return -EIRMD;
+ }
+
if (!recv_msg->has_api || !recv_msg->has_port_id) {
irm_msg__free_unpacked(recv_msg, NULL);
return -1;