Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RIOT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cm-projects
RIOT
Commits
36ecaa6e
Commit
36ecaa6e
authored
6 years ago
by
Hauke Petersen
Browse files
Options
Downloads
Patches
Plain Diff
net/emcute: use global byteorder functions
parent
baf9a62a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
sys/net/application_layer/emcute/emcute.c
+14
-32
14 additions, 32 deletions
sys/net/application_layer/emcute/emcute.c
with
14 additions
and
32 deletions
sys/net/application_layer/emcute/emcute.c
+
14
−
32
View file @
36ecaa6e
...
@@ -24,6 +24,7 @@
...
@@ -24,6 +24,7 @@
#include
"mutex.h"
#include
"mutex.h"
#include
"sched.h"
#include
"sched.h"
#include
"xtimer.h"
#include
"xtimer.h"
#include
"byteorder.h"
#include
"thread_flags.h"
#include
"thread_flags.h"
#include
"net/emcute.h"
#include
"net/emcute.h"
...
@@ -59,26 +60,6 @@ static volatile uint8_t waiton = 0xff;
...
@@ -59,26 +60,6 @@ static volatile uint8_t waiton = 0xff;
static
volatile
uint16_t
waitonid
=
0
;
static
volatile
uint16_t
waitonid
=
0
;
static
volatile
int
result
;
static
volatile
int
result
;
static
inline
uint16_t
get_u16
(
const
uint8_t
*
buf
)
{
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
return
(
uint16_t
)((
buf
[
0
]
<<
8
)
|
buf
[
1
]);
#else
return
(
uint16_t
)((
buf
[
1
]
<<
8
)
|
buf
[
0
]);
#endif
}
static
inline
void
set_u16
(
uint8_t
*
buf
,
uint16_t
val
)
{
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
buf
[
0
]
=
(
uint8_t
)(
val
>>
8
);
buf
[
1
]
=
(
uint8_t
)(
val
&
0xff
);
#else
buf
[
0
]
=
(
uint8_t
)(
val
&
0xff
);
buf
[
1
]
=
(
uint8_t
)(
val
>>
8
);
#endif
}
static
size_t
set_len
(
uint8_t
*
buf
,
size_t
len
)
static
size_t
set_len
(
uint8_t
*
buf
,
size_t
len
)
{
{
if
(
len
<
(
0xff
-
7
))
{
if
(
len
<
(
0xff
-
7
))
{
...
@@ -87,7 +68,7 @@ static size_t set_len(uint8_t *buf, size_t len)
...
@@ -87,7 +68,7 @@ static size_t set_len(uint8_t *buf, size_t len)
}
}
else
{
else
{
buf
[
0
]
=
0x01
;
buf
[
0
]
=
0x01
;
set_u16
(
&
tbuf
[
1
],
(
uint16_t
)(
len
+
3
));
byteorder_htolebufs
(
&
tbuf
[
1
],
(
uint16_t
)(
len
+
3
));
return
3
;
return
3
;
}
}
}
}
...
@@ -99,7 +80,7 @@ static size_t get_len(uint8_t *buf, uint16_t *len)
...
@@ -99,7 +80,7 @@ static size_t get_len(uint8_t *buf, uint16_t *len)
return
1
;
return
1
;
}
}
else
{
else
{
*
len
=
get_u16
(
&
buf
[
1
]);
*
len
=
byteorder_lebuftohs
(
&
buf
[
1
]);
return
3
;
return
3
;
}
}
}
}
...
@@ -151,12 +132,13 @@ static void on_disconnect(void)
...
@@ -151,12 +132,13 @@ static void on_disconnect(void)
static
void
on_ack
(
uint8_t
type
,
int
id_pos
,
int
ret_pos
,
int
res_pos
)
static
void
on_ack
(
uint8_t
type
,
int
id_pos
,
int
ret_pos
,
int
res_pos
)
{
{
if
((
waiton
==
type
)
&&
(
!
id_pos
||
(
waitonid
==
get_u16
(
&
rbuf
[
id_pos
]))))
{
if
((
waiton
==
type
)
&&
(
!
id_pos
||
(
waitonid
==
byteorder_lebuftohs
(
&
rbuf
[
id_pos
]))))
{
if
(
!
ret_pos
||
(
rbuf
[
ret_pos
]
==
ACCEPT
))
{
if
(
!
ret_pos
||
(
rbuf
[
ret_pos
]
==
ACCEPT
))
{
if
(
res_pos
==
0
)
{
if
(
res_pos
==
0
)
{
result
=
EMCUTE_OK
;
result
=
EMCUTE_OK
;
}
else
{
}
else
{
result
=
(
int
)
get_u16
(
&
rbuf
[
res_pos
]);
result
=
(
int
)
byteorder_lebuftohs
(
&
rbuf
[
res_pos
]);
}
}
}
else
{
}
else
{
result
=
EMCUTE_REJECT
;
result
=
EMCUTE_REJECT
;
...
@@ -173,7 +155,7 @@ static void on_publish(size_t len, size_t pos)
...
@@ -173,7 +155,7 @@ static void on_publish(size_t len, size_t pos)
}
}
emcute_sub_t
*
sub
;
emcute_sub_t
*
sub
;
uint16_t
tid
=
get_u16
(
&
rbuf
[
pos
+
2
]);
uint16_t
tid
=
byteorder_lebuftohs
(
&
rbuf
[
pos
+
2
]);
/* allocate a response packet */
/* allocate a response packet */
uint8_t
buf
[
7
]
=
{
7
,
PUBACK
,
0
,
0
,
0
,
0
,
ACCEPT
};
uint8_t
buf
[
7
]
=
{
7
,
PUBACK
,
0
,
0
,
0
,
0
,
ACCEPT
};
...
@@ -255,7 +237,7 @@ int emcute_con(sock_udp_ep_t *remote, bool clean, const char *will_topic,
...
@@ -255,7 +237,7 @@ int emcute_con(sock_udp_ep_t *remote, bool clean, const char *will_topic,
tbuf
[
1
]
=
CONNECT
;
tbuf
[
1
]
=
CONNECT
;
tbuf
[
2
]
=
flags
;
tbuf
[
2
]
=
flags
;
tbuf
[
3
]
=
PROTOCOL_VERSION
;
tbuf
[
3
]
=
PROTOCOL_VERSION
;
set_u16
(
&
tbuf
[
4
],
EMCUTE_KEEPALIVE
);
byteorder_htolebufs
(
&
tbuf
[
4
],
EMCUTE_KEEPALIVE
);
memcpy
(
&
tbuf
[
6
],
cli_id
,
strlen
(
cli_id
));
memcpy
(
&
tbuf
[
6
],
cli_id
,
strlen
(
cli_id
));
/* configure 'state machine' and send the connection request */
/* configure 'state machine' and send the connection request */
...
@@ -329,8 +311,8 @@ int emcute_reg(emcute_topic_t *topic)
...
@@ -329,8 +311,8 @@ int emcute_reg(emcute_topic_t *topic)
tbuf
[
0
]
=
(
strlen
(
topic
->
name
)
+
6
);
tbuf
[
0
]
=
(
strlen
(
topic
->
name
)
+
6
);
tbuf
[
1
]
=
REGISTER
;
tbuf
[
1
]
=
REGISTER
;
set_u16
(
&
tbuf
[
2
],
0
);
byteorder_htolebufs
(
&
tbuf
[
2
],
0
);
set_u16
(
&
tbuf
[
4
],
id_next
);
byteorder_htolebufs
(
&
tbuf
[
4
],
id_next
);
waitonid
=
id_next
++
;
waitonid
=
id_next
++
;
memcpy
(
&
tbuf
[
6
],
topic
->
name
,
strlen
(
topic
->
name
));
memcpy
(
&
tbuf
[
6
],
topic
->
name
,
strlen
(
topic
->
name
));
...
@@ -365,9 +347,9 @@ int emcute_pub(emcute_topic_t *topic, const void *data, size_t len,
...
@@ -365,9 +347,9 @@ int emcute_pub(emcute_topic_t *topic, const void *data, size_t len,
len
+=
(
pos
+
6
);
len
+=
(
pos
+
6
);
tbuf
[
pos
++
]
=
PUBLISH
;
tbuf
[
pos
++
]
=
PUBLISH
;
tbuf
[
pos
++
]
=
flags
;
tbuf
[
pos
++
]
=
flags
;
set_u16
(
&
tbuf
[
pos
],
topic
->
id
);
byteorder_htolebufs
(
&
tbuf
[
pos
],
topic
->
id
);
pos
+=
2
;
pos
+=
2
;
set_u16
(
&
tbuf
[
pos
],
id_next
);
byteorder_htolebufs
(
&
tbuf
[
pos
],
id_next
);
waitonid
=
id_next
++
;
waitonid
=
id_next
++
;
pos
+=
2
;
pos
+=
2
;
memcpy
(
&
tbuf
[
pos
],
data
,
len
);
memcpy
(
&
tbuf
[
pos
],
data
,
len
);
...
@@ -399,7 +381,7 @@ int emcute_sub(emcute_sub_t *sub, unsigned flags)
...
@@ -399,7 +381,7 @@ int emcute_sub(emcute_sub_t *sub, unsigned flags)
tbuf
[
0
]
=
(
strlen
(
sub
->
topic
.
name
)
+
5
);
tbuf
[
0
]
=
(
strlen
(
sub
->
topic
.
name
)
+
5
);
tbuf
[
1
]
=
SUBSCRIBE
;
tbuf
[
1
]
=
SUBSCRIBE
;
tbuf
[
2
]
=
flags
;
tbuf
[
2
]
=
flags
;
set_u16
(
&
tbuf
[
3
],
id_next
);
byteorder_htolebufs
(
&
tbuf
[
3
],
id_next
);
waitonid
=
id_next
++
;
waitonid
=
id_next
++
;
memcpy
(
&
tbuf
[
5
],
sub
->
topic
.
name
,
strlen
(
sub
->
topic
.
name
));
memcpy
(
&
tbuf
[
5
],
sub
->
topic
.
name
,
strlen
(
sub
->
topic
.
name
));
...
@@ -435,7 +417,7 @@ int emcute_unsub(emcute_sub_t *sub)
...
@@ -435,7 +417,7 @@ int emcute_unsub(emcute_sub_t *sub)
tbuf
[
0
]
=
(
strlen
(
sub
->
topic
.
name
)
+
5
);
tbuf
[
0
]
=
(
strlen
(
sub
->
topic
.
name
)
+
5
);
tbuf
[
1
]
=
UNSUBSCRIBE
;
tbuf
[
1
]
=
UNSUBSCRIBE
;
tbuf
[
2
]
=
0
;
tbuf
[
2
]
=
0
;
set_u16
(
&
tbuf
[
3
],
id_next
);
byteorder_htolebufs
(
&
tbuf
[
3
],
id_next
);
waitonid
=
id_next
++
;
waitonid
=
id_next
++
;
memcpy
(
&
tbuf
[
5
],
sub
->
topic
.
name
,
strlen
(
sub
->
topic
.
name
));
memcpy
(
&
tbuf
[
5
],
sub
->
topic
.
name
,
strlen
(
sub
->
topic
.
name
));
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment