123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548 |
- #ifndef ZEPHYR_INCLUDE_NET_NET_OFFLOAD_H_
- #define ZEPHYR_INCLUDE_NET_NET_OFFLOAD_H_
- #include <net/buf.h>
- #include <net/net_ip.h>
- #include <net/net_context.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- #if defined(CONFIG_NET_OFFLOAD)
- static inline int32_t timeout_to_int32(k_timeout_t timeout)
- {
- if (K_TIMEOUT_EQ(timeout, K_NO_WAIT)) {
- return 0;
- } else if (K_TIMEOUT_EQ(timeout, K_FOREVER)) {
- return -1;
- } else {
- return k_ticks_to_ms_floor32(timeout.ticks);
- }
- }
- struct net_offload {
-
- int (*get)(sa_family_t family,
- enum net_sock_type type,
- enum net_ip_protocol ip_proto,
- struct net_context **context);
-
- int (*bind)(struct net_context *context,
- const struct sockaddr *addr,
- socklen_t addrlen);
-
- int (*listen)(struct net_context *context, int backlog);
-
- int (*connect)(struct net_context *context,
- const struct sockaddr *addr,
- socklen_t addrlen,
- net_context_connect_cb_t cb,
- int32_t timeout,
- void *user_data);
-
- int (*accept)(struct net_context *context,
- net_tcp_accept_cb_t cb,
- int32_t timeout,
- void *user_data);
-
- int (*send)(struct net_pkt *pkt,
- net_context_send_cb_t cb,
- int32_t timeout,
- void *user_data);
-
- int (*sendto)(struct net_pkt *pkt,
- const struct sockaddr *dst_addr,
- socklen_t addrlen,
- net_context_send_cb_t cb,
- int32_t timeout,
- void *user_data);
-
- int (*recv)(struct net_context *context,
- net_context_recv_cb_t cb,
- int32_t timeout,
- void *user_data);
-
- int (*put)(struct net_context *context);
- };
- static inline int net_offload_get(struct net_if *iface,
- sa_family_t family,
- enum net_sock_type type,
- enum net_ip_protocol ip_proto,
- struct net_context **context)
- {
- NET_ASSERT(iface);
- NET_ASSERT(net_if_offload(iface));
- NET_ASSERT(net_if_offload(iface)->get);
- return net_if_offload(iface)->get(family, type, ip_proto, context);
- }
- static inline int net_offload_bind(struct net_if *iface,
- struct net_context *context,
- const struct sockaddr *addr,
- socklen_t addrlen)
- {
- NET_ASSERT(iface);
- NET_ASSERT(net_if_offload(iface));
- NET_ASSERT(net_if_offload(iface)->bind);
- return net_if_offload(iface)->bind(context, addr, addrlen);
- }
- static inline int net_offload_listen(struct net_if *iface,
- struct net_context *context,
- int backlog)
- {
- NET_ASSERT(iface);
- NET_ASSERT(net_if_offload(iface));
- NET_ASSERT(net_if_offload(iface)->listen);
- return net_if_offload(iface)->listen(context, backlog);
- }
- static inline int net_offload_connect(struct net_if *iface,
- struct net_context *context,
- const struct sockaddr *addr,
- socklen_t addrlen,
- net_context_connect_cb_t cb,
- k_timeout_t timeout,
- void *user_data)
- {
- NET_ASSERT(iface);
- NET_ASSERT(net_if_offload(iface));
- NET_ASSERT(net_if_offload(iface)->connect);
- return net_if_offload(iface)->connect(
- context, addr, addrlen, cb,
- timeout_to_int32(timeout),
- user_data);
- }
- static inline int net_offload_accept(struct net_if *iface,
- struct net_context *context,
- net_tcp_accept_cb_t cb,
- k_timeout_t timeout,
- void *user_data)
- {
- NET_ASSERT(iface);
- NET_ASSERT(net_if_offload(iface));
- NET_ASSERT(net_if_offload(iface)->accept);
- return net_if_offload(iface)->accept(
- context, cb,
- timeout_to_int32(timeout),
- user_data);
- }
- static inline int net_offload_send(struct net_if *iface,
- struct net_pkt *pkt,
- net_context_send_cb_t cb,
- k_timeout_t timeout,
- void *user_data)
- {
- NET_ASSERT(iface);
- NET_ASSERT(net_if_offload(iface));
- NET_ASSERT(net_if_offload(iface)->send);
- return net_if_offload(iface)->send(
- pkt, cb,
- timeout_to_int32(timeout),
- user_data);
- }
- static inline int net_offload_sendto(struct net_if *iface,
- struct net_pkt *pkt,
- const struct sockaddr *dst_addr,
- socklen_t addrlen,
- net_context_send_cb_t cb,
- k_timeout_t timeout,
- void *user_data)
- {
- NET_ASSERT(iface);
- NET_ASSERT(net_if_offload(iface));
- NET_ASSERT(net_if_offload(iface)->sendto);
- return net_if_offload(iface)->sendto(
- pkt, dst_addr, addrlen, cb,
- timeout_to_int32(timeout),
- user_data);
- }
- static inline int net_offload_recv(struct net_if *iface,
- struct net_context *context,
- net_context_recv_cb_t cb,
- k_timeout_t timeout,
- void *user_data)
- {
- NET_ASSERT(iface);
- NET_ASSERT(net_if_offload(iface));
- NET_ASSERT(net_if_offload(iface)->recv);
- return net_if_offload(iface)->recv(
- context, cb,
- timeout_to_int32(timeout),
- user_data);
- }
- static inline int net_offload_put(struct net_if *iface,
- struct net_context *context)
- {
- NET_ASSERT(iface);
- NET_ASSERT(net_if_offload(iface));
- NET_ASSERT(net_if_offload(iface)->put);
- return net_if_offload(iface)->put(context);
- }
- #else
- static inline int net_offload_get(struct net_if *iface,
- sa_family_t family,
- enum net_sock_type type,
- enum net_ip_protocol ip_proto,
- struct net_context **context)
- {
- return 0;
- }
- static inline int net_offload_bind(struct net_if *iface,
- struct net_context *context,
- const struct sockaddr *addr,
- socklen_t addrlen)
- {
- return 0;
- }
- static inline int net_offload_listen(struct net_if *iface,
- struct net_context *context,
- int backlog)
- {
- return 0;
- }
- static inline int net_offload_connect(struct net_if *iface,
- struct net_context *context,
- const struct sockaddr *addr,
- socklen_t addrlen,
- net_context_connect_cb_t cb,
- k_timeout_t timeout,
- void *user_data)
- {
- return 0;
- }
- static inline int net_offload_accept(struct net_if *iface,
- struct net_context *context,
- net_tcp_accept_cb_t cb,
- k_timeout_t timeout,
- void *user_data)
- {
- return 0;
- }
- static inline int net_offload_send(struct net_if *iface,
- struct net_pkt *pkt,
- net_context_send_cb_t cb,
- k_timeout_t timeout,
- void *user_data)
- {
- return 0;
- }
- static inline int net_offload_sendto(struct net_if *iface,
- struct net_pkt *pkt,
- const struct sockaddr *dst_addr,
- socklen_t addrlen,
- net_context_send_cb_t cb,
- k_timeout_t timeout,
- void *user_data)
- {
- return 0;
- }
- static inline int net_offload_recv(struct net_if *iface,
- struct net_context *context,
- net_context_recv_cb_t cb,
- k_timeout_t timeout,
- void *user_data)
- {
- return 0;
- }
- static inline int net_offload_put(struct net_if *iface,
- struct net_context *context)
- {
- return 0;
- }
- #endif
- #ifdef __cplusplus
- }
- #endif
- #endif
|