socket.h 77 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573
  1. /*
  2. * socket.h - CC31xx/CC32xx Host Driver Implementation
  3. *
  4. * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
  5. *
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. *
  14. * Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the
  17. * distribution.
  18. *
  19. * Neither the name of Texas Instruments Incorporated nor the names of
  20. * its contributors may be used to endorse or promote products derived
  21. * from this software without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  24. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  25. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  26. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  27. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  28. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  29. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  30. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  31. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  32. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  33. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. */
  36. /*****************************************************************************/
  37. /* Include files */
  38. /*****************************************************************************/
  39. #include "simplelink.h"
  40. #ifndef __SL_SOCKET_H__
  41. #define __SL_SOCKET_H__
  42. #ifdef __cplusplus
  43. extern "C" {
  44. #endif
  45. /*!
  46. \addtogroup socket
  47. @{
  48. */
  49. /*****************************************************************************/
  50. /* Macro declarations */
  51. /*****************************************************************************/
  52. #define SL_FD_SETSIZE SL_MAX_SOCKETS /* Number of sockets to select on - same is max sockets! */
  53. #define BSD_SOCKET_ID_MASK (0x0F) /* Index using the LBS 4 bits for socket id 0-7 */
  54. /* Define some BSD protocol constants. */
  55. #define SL_SOCK_STREAM (1) /* TCP Socket */
  56. #define SL_SOCK_DGRAM (2) /* UDP Socket */
  57. #define SL_SOCK_RAW (3) /* Raw socket */
  58. #define SL_IPPROTO_TCP (6) /* TCP Raw Socket */
  59. #define SL_IPPROTO_UDP (17) /* UDP Raw Socket */
  60. #define SL_IPPROTO_RAW (255) /* Raw Socket */
  61. #define SL_SEC_SOCKET (100) /* Secured Socket Layer (SSL,TLS) */
  62. /* Address families. */
  63. #define SL_AF_INET (2) /* IPv4 socket (UDP, TCP, etc) */
  64. #define SL_AF_INET6 (3) /* IPv6 socket (UDP, TCP, etc) */
  65. #define SL_AF_INET6_EUI_48 (9)
  66. #define SL_AF_RF (6) /* data include RF parameter, All layer by user (Wifi could be disconnected) */
  67. #define SL_AF_PACKET (17)
  68. /* Protocol families, same as address families. */
  69. #define SL_PF_INET AF_INET
  70. #define SL_PF_INET6 AF_INET6
  71. #define SL_INADDR_ANY (0) /* bind any address */
  72. /* error codes */
  73. #define SL_SOC_ERROR (-1) /* Failure. */
  74. #define SL_SOC_OK ( 0) /* Success. */
  75. #define SL_INEXE (-8) /* socket command in execution */
  76. #define SL_EBADF (-9) /* Bad file number */
  77. #define SL_ENSOCK (-10) /* The system limit on the total number of open socket, has been reached */
  78. #define SL_EAGAIN (-11) /* Try again */
  79. #define SL_EWOULDBLOCK SL_EAGAIN
  80. #define SL_ENOMEM (-12) /* Out of memory */
  81. #define SL_EACCES (-13) /* Permission denied */
  82. #define SL_EFAULT (-14) /* Bad address */
  83. #define SL_ECLOSE (-15) /* close socket operation failed to transmit all queued packets */
  84. #define SL_EALREADY_ENABLED (-21) /* Transceiver - Transceiver already ON. there could be only one */
  85. #define SL_EINVAL (-22) /* Invalid argument */
  86. #define SL_EAUTO_CONNECT_OR_CONNECTING (-69) /* Transceiver - During connection, connected or auto mode started */
  87. #define SL_CONNECTION_PENDING (-72) /* Transceiver - Device is connected, disconnect first to open transceiver */
  88. #define SL_EUNSUPPORTED_ROLE (-86) /* Transceiver - Trying to start when WLAN role is AP or P2P GO */
  89. #define SL_EDESTADDRREQ (-89) /* Destination address required */
  90. #define SL_EPROTOTYPE (-91) /* Protocol wrong type for socket */
  91. #define SL_ENOPROTOOPT (-92) /* Protocol not available */
  92. #define SL_EPROTONOSUPPORT (-93) /* Protocol not supported */
  93. #define SL_ESOCKTNOSUPPORT (-94) /* Socket type not supported */
  94. #define SL_EOPNOTSUPP (-95) /* Operation not supported on transport endpoint */
  95. #define SL_EAFNOSUPPORT (-97) /* Address family not supported by protocol */
  96. #define SL_EADDRINUSE (-98) /* Address already in use */
  97. #define SL_EADDRNOTAVAIL (-99) /* Cannot assign requested address */
  98. #define SL_ENETUNREACH (-101) /* Network is unreachable */
  99. #define SL_ENOBUFS (-105) /* No buffer space available */
  100. #define SL_EOBUFF SL_ENOBUFS
  101. #define SL_EISCONN (-106) /* Transport endpoint is already connected */
  102. #define SL_ENOTCONN (-107) /* Transport endpoint is not connected */
  103. #define SL_ETIMEDOUT (-110) /* Connection timed out */
  104. #define SL_ECONNREFUSED (-111) /* Connection refused */
  105. #define SL_EALREADY (-114) /* Non blocking connect in progress, try again */
  106. #define SL_ESEC_RSA_WRONG_TYPE_E (-130) /* RSA wrong block type for RSA function */
  107. #define SL_ESEC_RSA_BUFFER_E (-131) /* RSA buffer error, output too small or */
  108. #define SL_ESEC_BUFFER_E (-132) /* output buffer too small or input too large */
  109. #define SL_ESEC_ALGO_ID_E (-133) /* setting algo id error */
  110. #define SL_ESEC_PUBLIC_KEY_E (-134) /* setting public key error */
  111. #define SL_ESEC_DATE_E (-135) /* setting date validity error */
  112. #define SL_ESEC_SUBJECT_E (-136) /* setting subject name error */
  113. #define SL_ESEC_ISSUER_E (-137) /* setting issuer name error */
  114. #define SL_ESEC_CA_TRUE_E (-138) /* setting CA basic constraint true error */
  115. #define SL_ESEC_EXTENSIONS_E (-139) /* setting extensions error */
  116. #define SL_ESEC_ASN_PARSE_E (-140) /* ASN parsing error, invalid input */
  117. #define SL_ESEC_ASN_VERSION_E (-141) /* ASN version error, invalid number */
  118. #define SL_ESEC_ASN_GETINT_E (-142) /* ASN get big _i16 error, invalid data */
  119. #define SL_ESEC_ASN_RSA_KEY_E (-143) /* ASN key init error, invalid input */
  120. #define SL_ESEC_ASN_OBJECT_ID_E (-144) /* ASN object id error, invalid id */
  121. #define SL_ESEC_ASN_TAG_NULL_E (-145) /* ASN tag error, not null */
  122. #define SL_ESEC_ASN_EXPECT_0_E (-146) /* ASN expect error, not zero */
  123. #define SL_ESEC_ASN_BITSTR_E (-147) /* ASN bit string error, wrong id */
  124. #define SL_ESEC_ASN_UNKNOWN_OID_E (-148) /* ASN oid error, unknown sum id */
  125. #define SL_ESEC_ASN_DATE_SZ_E (-149) /* ASN date error, bad size */
  126. #define SL_ESEC_ASN_BEFORE_DATE_E (-150) /* ASN date error, current date before */
  127. #define SL_ESEC_ASN_AFTER_DATE_E (-151) /* ASN date error, current date after */
  128. #define SL_ESEC_ASN_SIG_OID_E (-152) /* ASN signature error, mismatched oid */
  129. #define SL_ESEC_ASN_TIME_E (-153) /* ASN time error, unknown time type */
  130. #define SL_ESEC_ASN_INPUT_E (-154) /* ASN input error, not enough data */
  131. #define SL_ESEC_ASN_SIG_CONFIRM_E (-155) /* ASN sig error, confirm failure */
  132. #define SL_ESEC_ASN_SIG_HASH_E (-156) /* ASN sig error, unsupported hash type */
  133. #define SL_ESEC_ASN_SIG_KEY_E (-157) /* ASN sig error, unsupported key type */
  134. #define SL_ESEC_ASN_DH_KEY_E (-158) /* ASN key init error, invalid input */
  135. #define SL_ESEC_ASN_NTRU_KEY_E (-159) /* ASN ntru key decode error, invalid input */
  136. #define SL_ESEC_ECC_BAD_ARG_E (-170) /* ECC input argument of wrong type */
  137. #define SL_ESEC_ASN_ECC_KEY_E (-171) /* ASN ECC bad input */
  138. #define SL_ESEC_ECC_CURVE_OID_E (-172) /* Unsupported ECC OID curve type */
  139. #define SL_ESEC_BAD_FUNC_ARG (-173) /* Bad function argument provided */
  140. #define SL_ESEC_NOT_COMPILED_IN (-174) /* Feature not compiled in */
  141. #define SL_ESEC_UNICODE_SIZE_E (-175) /* Unicode password too big */
  142. #define SL_ESEC_NO_PASSWORD (-176) /* no password provided by user */
  143. #define SL_ESEC_ALT_NAME_E (-177) /* alt name size problem, too big */
  144. #define SL_ESEC_AES_GCM_AUTH_E (-180) /* AES-GCM Authentication check failure */
  145. #define SL_ESEC_AES_CCM_AUTH_E (-181) /* AES-CCM Authentication check failure */
  146. #define SL_SOCKET_ERROR_E (-208) /* Error state on socket */
  147. #define SL_ESEC_MEMORY_ERROR (-203) /* out of memory */
  148. #define SL_ESEC_VERIFY_FINISHED_ERROR (-204) /* verify problem on finished */
  149. #define SL_ESEC_VERIFY_MAC_ERROR (-205) /* verify mac problem */
  150. #define SL_ESEC_UNKNOWN_HANDSHAKE_TYPE (-207) /* weird handshake type */
  151. #define SL_ESEC_SOCKET_ERROR_E (-208) /* error state on socket */
  152. #define SL_ESEC_SOCKET_NODATA (-209) /* expected data, not there */
  153. #define SL_ESEC_INCOMPLETE_DATA (-210) /* don't have enough data to complete task */
  154. #define SL_ESEC_UNKNOWN_RECORD_TYPE (-211) /* unknown type in record hdr */
  155. #define SL_ESEC_FATAL_ERROR (-213) /* recvd alert fatal error */
  156. #define SL_ESEC_ENCRYPT_ERROR (-214) /* error during encryption */
  157. #define SL_ESEC_NO_PEER_KEY (-216) /* need peer's key */
  158. #define SL_ESEC_NO_PRIVATE_KEY (-217) /* need the private key */
  159. #define SL_ESEC_RSA_PRIVATE_ERROR (-218) /* error during rsa priv op */
  160. #define SL_ESEC_NO_DH_PARAMS (-219) /* server missing DH params */
  161. #define SL_ESEC_BUILD_MSG_ERROR (-220) /* build message failure */
  162. #define SL_ESEC_BAD_HELLO (-221) /* client hello malformed */
  163. #define SL_ESEC_DOMAIN_NAME_MISMATCH (-222) /* peer subject name mismatch */
  164. #define SL_ESEC_WANT_READ (-223) /* want read, call again */
  165. #define SL_ESEC_NOT_READY_ERROR (-224) /* handshake layer not ready */
  166. #define SL_ESEC_PMS_VERSION_ERROR (-225) /* pre m secret version error */
  167. #define SL_ESEC_VERSION_ERROR (-226) /* record layer version error */
  168. #define SL_ESEC_WANT_WRITE (-227) /* want write, call again */
  169. #define SL_ESEC_BUFFER_ERROR (-228) /* malformed buffer input */
  170. #define SL_ESEC_VERIFY_CERT_ERROR (-229) /* verify cert error */
  171. #define SL_ESEC_VERIFY_SIGN_ERROR (-230) /* verify sign error */
  172. #define SL_ESEC_LENGTH_ERROR (-241) /* record layer length error */
  173. #define SL_ESEC_PEER_KEY_ERROR (-242) /* can't decode peer key */
  174. #define SL_ESEC_ZERO_RETURN (-243) /* peer sent close notify */
  175. #define SL_ESEC_SIDE_ERROR (-244) /* wrong client/server type */
  176. #define SL_ESEC_NO_PEER_CERT (-245) /* peer didn't send key */
  177. #define SL_ESEC_ECC_CURVETYPE_ERROR (-250) /* Bad ECC Curve Type */
  178. #define SL_ESEC_ECC_CURVE_ERROR (-251) /* Bad ECC Curve */
  179. #define SL_ESEC_ECC_PEERKEY_ERROR (-252) /* Bad Peer ECC Key */
  180. #define SL_ESEC_ECC_MAKEKEY_ERROR (-253) /* Bad Make ECC Key */
  181. #define SL_ESEC_ECC_EXPORT_ERROR (-254) /* Bad ECC Export Key */
  182. #define SL_ESEC_ECC_SHARED_ERROR (-255) /* Bad ECC Shared Secret */
  183. #define SL_ESEC_NOT_CA_ERROR (-257) /* Not a CA cert error */
  184. #define SL_ESEC_BAD_PATH_ERROR (-258) /* Bad path for opendir */
  185. #define SL_ESEC_BAD_CERT_MANAGER_ERROR (-259) /* Bad Cert Manager */
  186. #define SL_ESEC_MAX_CHAIN_ERROR (-268) /* max chain depth exceeded */
  187. #define SL_ESEC_SUITES_ERROR (-271) /* suites pointer error */
  188. #define SL_ESEC_SSL_NO_PEM_HEADER (-272) /* no PEM header found */
  189. #define SL_ESEC_OUT_OF_ORDER_E (-273) /* out of order message */
  190. #define SL_ESEC_SANITY_CIPHER_E (-275) /* sanity check on cipher error */
  191. #define SL_ESEC_GEN_COOKIE_E (-277) /* Generate Cookie Error */
  192. #define SL_ESEC_NO_PEER_VERIFY (-278) /* Need peer cert verify Error */
  193. #define SL_ESEC_UNKNOWN_SNI_HOST_NAME_E (-281) /* Unrecognized host name Error */
  194. /* begin negotiation parameter errors */
  195. #define SL_ESEC_UNSUPPORTED_SUITE (-290) /* unsupported cipher suite */
  196. #define SL_ESEC_MATCH_SUITE_ERROR (-291 ) /* can't match cipher suite */
  197. /* ssl tls security start with -300 offset */
  198. #define SL_ESEC_CLOSE_NOTIFY (-300) /* ssl/tls alerts */
  199. #define SL_ESEC_UNEXPECTED_MESSAGE (-310) /* ssl/tls alerts */
  200. #define SL_ESEC_BAD_RECORD_MAC (-320) /* ssl/tls alerts */
  201. #define SL_ESEC_DECRYPTION_FAILED (-321) /* ssl/tls alerts */
  202. #define SL_ESEC_RECORD_OVERFLOW (-322) /* ssl/tls alerts */
  203. #define SL_ESEC_DECOMPRESSION_FAILURE (-330) /* ssl/tls alerts */
  204. #define SL_ESEC_HANDSHAKE_FAILURE (-340) /* ssl/tls alerts */
  205. #define SL_ESEC_NO_CERTIFICATE (-341) /* ssl/tls alerts */
  206. #define SL_ESEC_BAD_CERTIFICATE (-342) /* ssl/tls alerts */
  207. #define SL_ESEC_UNSUPPORTED_CERTIFICATE (-343) /* ssl/tls alerts */
  208. #define SL_ESEC_CERTIFICATE_REVOKED (-344) /* ssl/tls alerts */
  209. #define SL_ESEC_CERTIFICATE_EXPIRED (-345) /* ssl/tls alerts */
  210. #define SL_ESEC_CERTIFICATE_UNKNOWN (-346) /* ssl/tls alerts */
  211. #define SL_ESEC_ILLEGAL_PARAMETER (-347) /* ssl/tls alerts */
  212. #define SL_ESEC_UNKNOWN_CA (-348) /* ssl/tls alerts */
  213. #define SL_ESEC_ACCESS_DENIED (-349) /* ssl/tls alerts */
  214. #define SL_ESEC_DECODE_ERROR (-350) /* ssl/tls alerts */
  215. #define SL_ESEC_DECRYPT_ERROR (-351) /* ssl/tls alerts */
  216. #define SL_ESEC_EXPORT_RESTRICTION (-360) /* ssl/tls alerts */
  217. #define SL_ESEC_PROTOCOL_VERSION (-370) /* ssl/tls alerts */
  218. #define SL_ESEC_INSUFFICIENT_SECURITY (-371) /* ssl/tls alerts */
  219. #define SL_ESEC_INTERNAL_ERROR (-380) /* ssl/tls alerts */
  220. #define SL_ESEC_USER_CANCELLED (-390) /* ssl/tls alerts */
  221. #define SL_ESEC_NO_RENEGOTIATION (-400) /* ssl/tls alerts */
  222. #define SL_ESEC_UNSUPPORTED_EXTENSION (-410) /* ssl/tls alerts */
  223. #define SL_ESEC_CERTIFICATE_UNOBTAINABLE (-411) /* ssl/tls alerts */
  224. #define SL_ESEC_UNRECOGNIZED_NAME (-412) /* ssl/tls alerts */
  225. #define SL_ESEC_BAD_CERTIFICATE_STATUS_RESPONSE (-413) /* ssl/tls alerts */
  226. #define SL_ESEC_BAD_CERTIFICATE_HASH_VALUE (-414) /* ssl/tls alerts */
  227. /* propierty secure */
  228. #define SL_ESECGENERAL (-450) /* error secure level general error */
  229. #define SL_ESECDECRYPT (-451) /* error secure level, decrypt recv packet fail */
  230. #define SL_ESECCLOSED (-452) /* secure layrer is closed by other size , tcp is still connected */
  231. #define SL_ESECSNOVERIFY (-453) /* Connected without server verification */
  232. #define SL_ESECNOCAFILE (-454) /* error secure level CA file not found*/
  233. #define SL_ESECMEMORY (-455) /* error secure level No memory space available */
  234. #define SL_ESECBADCAFILE (-456) /* error secure level bad CA file */
  235. #define SL_ESECBADCERTFILE (-457) /* error secure level bad Certificate file */
  236. #define SL_ESECBADPRIVATEFILE (-458) /* error secure level bad private file */
  237. #define SL_ESECBADDHFILE (-459) /* error secure level bad DH file */
  238. #define SL_ESECT00MANYSSLOPENED (-460) /* MAX SSL Sockets are opened */
  239. #define SL_ESECDATEERROR (-461) /* connected with certificate date verification error */
  240. #define SL_ESECHANDSHAKETIMEDOUT (-462) /* connection timed out due to handshake time */
  241. /* end error codes */
  242. /* Max payload size by protocol */
  243. #define SL_SOCKET_PAYLOAD_TYPE_MASK (0xF0) /*4 bits type, 4 bits sockets id */
  244. #define SL_SOCKET_PAYLOAD_TYPE_UDP_IPV4 (0x00) /* 1472 bytes */
  245. #define SL_SOCKET_PAYLOAD_TYPE_TCP_IPV4 (0x10) /* 1460 bytes */
  246. #define SL_SOCKET_PAYLOAD_TYPE_UDP_IPV6 (0x20) /* 1452 bytes */
  247. #define SL_SOCKET_PAYLOAD_TYPE_TCP_IPV6 (0x30) /* 1440 bytes */
  248. #define SL_SOCKET_PAYLOAD_TYPE_UDP_IPV4_SECURE (0x40) /* */
  249. #define SL_SOCKET_PAYLOAD_TYPE_TCP_IPV4_SECURE (0x50) /* */
  250. #define SL_SOCKET_PAYLOAD_TYPE_UDP_IPV6_SECURE (0x60) /* */
  251. #define SL_SOCKET_PAYLOAD_TYPE_TCP_IPV6_SECURE (0x70) /* */
  252. #define SL_SOCKET_PAYLOAD_TYPE_RAW_TRANCEIVER (0x80) /* 1536 bytes */
  253. #define SL_SOCKET_PAYLOAD_TYPE_RAW_PACKET (0x90) /* 1536 bytes */
  254. #define SL_SOCKET_PAYLOAD_TYPE_RAW_IP4 (0xa0)
  255. #define SL_SOCKET_PAYLOAD_TYPE_RAW_IP6 (SL_SOCKET_PAYLOAD_TYPE_RAW_IP4 )
  256. #define SL_SOL_SOCKET (1) /* Define the socket option category. */
  257. #define SL_IPPROTO_IP (2) /* Define the IP option category. */
  258. #define SL_SOL_PHY_OPT (3) /* Define the PHY option category. */
  259. #define SL_SO_RCVBUF (8) /* Setting TCP receive buffer size */
  260. #define SL_SO_KEEPALIVE (9) /* Connections are kept alive with periodic messages */
  261. #define SL_SO_RCVTIMEO (20) /* Enable receive timeout */
  262. #define SL_SO_NONBLOCKING (24) /* Enable . disable nonblocking mode */
  263. #define SL_SO_SECMETHOD (25) /* security metohd */
  264. #define SL_SO_SECURE_MASK (26) /* security mask */
  265. #define SL_SO_SECURE_FILES (27) /* security files */
  266. #define SL_SO_CHANGE_CHANNEL (28) /* This option is available only when transceiver started */
  267. #define SL_SO_SECURE_FILES_PRIVATE_KEY_FILE_NAME (30) /* This option used to configue secure file */
  268. #define SL_SO_SECURE_FILES_CERTIFICATE_FILE_NAME (31) /* This option used to configue secure file */
  269. #define SL_SO_SECURE_FILES_CA_FILE_NAME (32) /* This option used to configue secure file */
  270. #define SL_SO_SECURE_FILES_DH_KEY_FILE_NAME (33) /* This option used to configue secure file */
  271. #define SL_IP_MULTICAST_IF (60) /* Specify outgoing multicast interface */
  272. #define SL_IP_MULTICAST_TTL (61) /* Specify the TTL value to use for outgoing multicast packet. */
  273. #define SL_IP_ADD_MEMBERSHIP (65) /* Join IPv4 multicast membership */
  274. #define SL_IP_DROP_MEMBERSHIP (66) /* Leave IPv4 multicast membership */
  275. #define SL_IP_HDRINCL (67) /* Raw socket IPv4 header included. */
  276. #define SL_IP_RAW_RX_NO_HEADER (68) /* Proprietary socket option that does not includeIPv4/IPv6 header (and extension headers) on received raw sockets*/
  277. #define SL_IP_RAW_IPV6_HDRINCL (69) /* Transmitted buffer over IPv6 socket contains IPv6 header. */
  278. #define SL_SO_PHY_RATE (100) /* WLAN Transmit rate */
  279. #define SL_SO_PHY_TX_POWER (101) /* TX Power level */
  280. #define SL_SO_PHY_NUM_FRAMES_TO_TX (102) /* Number of frames to transmit */
  281. #define SL_SO_PHY_PREAMBLE (103) /* Preamble for transmission */
  282. #define SL_SO_SEC_METHOD_SSLV3 (0) /* security metohd SSL v3*/
  283. #define SL_SO_SEC_METHOD_TLSV1 (1) /* security metohd TLS v1*/
  284. #define SL_SO_SEC_METHOD_TLSV1_1 (2) /* security metohd TLS v1_1*/
  285. #define SL_SO_SEC_METHOD_TLSV1_2 (3) /* security metohd TLS v1_2*/
  286. #define SL_SO_SEC_METHOD_SSLv3_TLSV1_2 (4) /* use highest possible version from SSLv3 - TLS 1.2*/
  287. #define SL_SO_SEC_METHOD_DLSV1 (5) /* security metohd DTL v1 */
  288. #define SL_SEC_MASK_SSL_RSA_WITH_RC4_128_SHA (1 << 0)
  289. #define SL_SEC_MASK_SSL_RSA_WITH_RC4_128_MD5 (1 << 1)
  290. #define SL_SEC_MASK_TLS_RSA_WITH_AES_256_CBC_SHA (1 << 2)
  291. #define SL_SEC_MASK_TLS_DHE_RSA_WITH_AES_256_CBC_SHA (1 << 3)
  292. #define SL_SEC_MASK_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA (1 << 4)
  293. #define SL_SEC_MASK_TLS_ECDHE_RSA_WITH_RC4_128_SHA (1 << 5)
  294. #define SL_SEC_MASK_TLS_RSA_WITH_AES_128_CBC_SHA256 (1 << 6)
  295. #define SL_SEC_MASK_TLS_RSA_WITH_AES_256_CBC_SHA256 (1 << 7)
  296. #define SL_SEC_MASK_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 (1 << 8)
  297. #define SL_SEC_MASK_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 (1 << 9)
  298. #define SL_SEC_MASK_SECURE_DEFAULT ((SL_SEC_MASK_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 << 1) - 1)
  299. #define SL_MSG_DONTWAIT (0x00000008) /* Nonblocking IO */
  300. /* AP DHCP Server - IP Release reason code */
  301. #define SL_IP_LEASE_PEER_RELEASE (0)
  302. #define SL_IP_LEASE_PEER_DECLINE (1)
  303. #define SL_IP_LEASE_EXPIRED (2)
  304. /* possible types when receiving SL_SOCKET_ASYNC_EVENT*/
  305. #define SSL_ACCEPT (1) /* accept failed due to ssl issue ( tcp pass) */
  306. #define RX_FRAGMENTATION_TOO_BIG (2) /* connection less mode, rx packet fragmentation > 16K, packet is being released */
  307. #define OTHER_SIDE_CLOSE_SSL_DATA_NOT_ENCRYPTED (3) /* remote side down from secure to unsecure */
  308. #ifdef SL_INC_STD_BSD_API_NAMING
  309. #define FD_SETSIZE SL_FD_SETSIZE
  310. #define SOCK_STREAM SL_SOCK_STREAM
  311. #define SOCK_DGRAM SL_SOCK_DGRAM
  312. #define SOCK_RAW SL_SOCK_RAW
  313. #define IPPROTO_TCP SL_IPPROTO_TCP
  314. #define IPPROTO_UDP SL_IPPROTO_UDP
  315. #define IPPROTO_RAW SL_IPPROTO_RAW
  316. #define AF_INET SL_AF_INET
  317. #define AF_INET6 SL_AF_INET6
  318. #define AF_INET6_EUI_48 SL_AF_INET6_EUI_48
  319. #define AF_RF SL_AF_RF
  320. #define AF_PACKET SL_AF_PACKET
  321. #define PF_INET SL_PF_INET
  322. #define PF_INET6 SL_PF_INET6
  323. #define INADDR_ANY SL_INADDR_ANY
  324. #define ERROR SL_SOC_ERROR
  325. #define INEXE SL_INEXE
  326. #define EBADF SL_EBADF
  327. #define ENSOCK SL_ENSOCK
  328. #define EAGAIN SL_EAGAIN
  329. #define EWOULDBLOCK SL_EWOULDBLOCK
  330. #define ENOMEM SL_ENOMEM
  331. #define EACCES SL_EACCES
  332. #define EFAULT SL_EFAULT
  333. #define EINVAL SL_EINVAL
  334. #define EDESTADDRREQ SL_EDESTADDRREQ
  335. #define EPROTOTYPE SL_EPROTOTYPE
  336. #define ENOPROTOOPT SL_ENOPROTOOPT
  337. #define EPROTONOSUPPORT SL_EPROTONOSUPPORT
  338. #define ESOCKTNOSUPPORT SL_ESOCKTNOSUPPORT
  339. #define EOPNOTSUPP SL_EOPNOTSUPP
  340. #define EAFNOSUPPORT SL_EAFNOSUPPORT
  341. #define EADDRINUSE SL_EADDRINUSE
  342. #define EADDRNOTAVAIL SL_EADDRNOTAVAIL
  343. #define ENETUNREACH SL_ENETUNREACH
  344. #define ENOBUFS SL_ENOBUFS
  345. #define EOBUFF SL_EOBUFF
  346. #define EISCONN SL_EISCONN
  347. #define ENOTCONN SL_ENOTCONN
  348. #define ETIMEDOUT SL_ETIMEDOUT
  349. #define ECONNREFUSED SL_ECONNREFUSED
  350. #define SOL_SOCKET SL_SOL_SOCKET
  351. #define IPPROTO_IP SL_IPPROTO_IP
  352. #define SO_KEEPALIVE SL_SO_KEEPALIVE
  353. #define SO_RCVTIMEO SL_SO_RCVTIMEO
  354. #define SO_NONBLOCKING SL_SO_NONBLOCKING
  355. #define IP_MULTICAST_IF SL_IP_MULTICAST_IF
  356. #define IP_MULTICAST_TTL SL_IP_MULTICAST_TTL
  357. #define IP_ADD_MEMBERSHIP SL_IP_ADD_MEMBERSHIP
  358. #define IP_DROP_MEMBERSHIP SL_IP_DROP_MEMBERSHIP
  359. #define socklen_t SlSocklen_t
  360. #define timeval SlTimeval_t
  361. #define sockaddr SlSockAddr_t
  362. #define in6_addr SlIn6Addr_t
  363. #define sockaddr_in6 SlSockAddrIn6_t
  364. #define in_addr SlInAddr_t
  365. #define sockaddr_in SlSockAddrIn_t
  366. #define MSG_DONTWAIT SL_MSG_DONTWAIT
  367. #define FD_SET SL_FD_SET
  368. #define FD_CLR SL_FD_CLR
  369. #define FD_ISSET SL_FD_ISSET
  370. #define FD_ZERO SL_FD_ZERO
  371. #define fd_set SlFdSet_t
  372. #define socket sl_Socket
  373. #define close sl_Close
  374. #define accept sl_Accept
  375. #define bind sl_Bind
  376. #define listen sl_Listen
  377. #define connect sl_Connect
  378. #define select sl_Select
  379. #define setsockopt sl_SetSockOpt
  380. #define getsockopt sl_GetSockOpt
  381. #define recv sl_Recv
  382. #define recvfrom sl_RecvFrom
  383. #define write sl_Write
  384. #define send sl_Send
  385. #define sendto sl_SendTo
  386. #define gethostbyname sl_NetAppDnsGetHostByName
  387. #define htonl sl_Htonl
  388. #define ntohl sl_Ntohl
  389. #define htons sl_Htons
  390. #define ntohs sl_Ntohs
  391. #endif
  392. /*****************************************************************************/
  393. /* Structure/Enum declarations */
  394. /*****************************************************************************/
  395. /* Internet address */
  396. typedef struct SlInAddr_t
  397. {
  398. #ifndef s_addr
  399. _u32 s_addr; /* Internet address 32 bits */
  400. #else
  401. union S_un {
  402. struct { _u8 s_b1,s_b2,s_b3,s_b4; } S_un_b;
  403. struct { _u8 s_w1,s_w2; } S_un_w;
  404. _u32 S_addr;
  405. } S_un;
  406. #endif
  407. }SlInAddr_t;
  408. /* sockopt */
  409. typedef struct
  410. {
  411. _u32 KeepaliveEnabled; /* 0 = disabled;1 = enabled; default = 1*/
  412. }SlSockKeepalive_t;
  413. typedef struct
  414. {
  415. _u32 ReuseaddrEnabled; /* 0 = disabled; 1 = enabled; default = 1*/
  416. }SlSockReuseaddr_t;
  417. typedef struct
  418. {
  419. _u32 Winsize; /* receive window size for tcp sockets */
  420. }SlSockWinsize_t;
  421. typedef struct
  422. {
  423. _u32 NonblockingEnabled;/* 0 = disabled;1 = enabled;default = 1*/
  424. }SlSockNonblocking_t;
  425. typedef struct
  426. {
  427. _u8 sd;
  428. _u8 type;
  429. _i16 val;
  430. _u8* pExtraInfo;
  431. } SlSocketAsyncEvent_t;
  432. typedef struct
  433. {
  434. _i16 status;
  435. _u8 sd;
  436. _u8 padding;
  437. } SlSockTxFailEventData_t;
  438. typedef union
  439. {
  440. SlSockTxFailEventData_t SockTxFailData;
  441. SlSocketAsyncEvent_t SockAsyncData;
  442. } SlSockEventData_u;
  443. typedef struct
  444. {
  445. _u32 Event;
  446. SlSockEventData_u socketAsyncEvent;
  447. } SlSockEvent_t;
  448. typedef struct
  449. {
  450. _u32 secureMask;
  451. } SlSockSecureMask;
  452. typedef struct
  453. {
  454. _u8 secureMethod;
  455. } SlSockSecureMethod;
  456. typedef enum
  457. {
  458. SL_BSD_SECURED_PRIVATE_KEY_IDX = 0,
  459. SL_BSD_SECURED_CERTIFICATE_IDX,
  460. SL_BSD_SECURED_CA_IDX,
  461. SL_BSD_SECURED_DH_IDX
  462. }slBsd_secureSocketFilesIndex_e;
  463. typedef struct
  464. {
  465. SlInAddr_t imr_multiaddr; /* The IPv4 multicast address to join */
  466. SlInAddr_t imr_interface; /* The interface to use for this group */
  467. } SlSockIpMreq;
  468. /* sockopt */
  469. typedef _u32 SlTime_t;
  470. typedef _u32 SlSuseconds_t;
  471. typedef struct SlTimeval_t
  472. {
  473. SlTime_t tv_sec; /* Seconds */
  474. SlSuseconds_t tv_usec; /* Microseconds */
  475. }SlTimeval_t;
  476. typedef _u16 SlSocklen_t;
  477. /* IpV4 socket address */
  478. typedef struct SlSockAddr_t
  479. {
  480. _u16 sa_family; /* Address family (e.g. , AF_INET) */
  481. _u8 sa_data[14]; /* Protocol- specific address information*/
  482. }SlSockAddr_t;
  483. /* IpV6 or Ipv6 EUI64 */
  484. typedef struct SlIn6Addr_t
  485. {
  486. union
  487. {
  488. _u8 _S6_u8[16];
  489. _u32 _S6_u32[4];
  490. } _S6_un;
  491. }SlIn6Addr_t;
  492. typedef struct SlSockAddrIn6_t
  493. {
  494. _u16 sin6_family; /* AF_INET6 || AF_INET6_EUI_48*/
  495. _u16 sin6_port; /* Transport layer port. */
  496. _u32 sin6_flowinfo; /* IPv6 flow information. */
  497. SlIn6Addr_t sin6_addr; /* IPv6 address. */
  498. _u32 sin6_scope_id; /* set of interfaces for a scope. */
  499. }SlSockAddrIn6_t;
  500. /* Socket address, Internet style. */
  501. typedef struct SlSockAddrIn_t
  502. {
  503. _u16 sin_family; /* Internet Protocol (AF_INET). */
  504. _u16 sin_port; /* Address port (16 bits). */
  505. SlInAddr_t sin_addr; /* Internet address (32 bits). */
  506. _i8 sin_zero[8]; /* Not used. */
  507. }SlSockAddrIn_t;
  508. typedef struct
  509. {
  510. _u32 ip;
  511. _u32 gateway;
  512. _u32 dns;
  513. }SlIpV4AcquiredAsync_t;
  514. typedef struct
  515. {
  516. _u32 type;
  517. _u32 ip[4];
  518. _u32 gateway[4];
  519. _u32 dns[4];
  520. }SlIpV6AcquiredAsync_t;
  521. typedef struct
  522. {
  523. _u32 ip_address;
  524. _u32 lease_time;
  525. _u8 mac[6];
  526. _u16 padding;
  527. }SlIpLeasedAsync_t;
  528. typedef struct
  529. {
  530. _u32 ip_address;
  531. _u8 mac[6];
  532. _u16 reason;
  533. }SlIpReleasedAsync_t;
  534. typedef union
  535. {
  536. SlIpV4AcquiredAsync_t ipAcquiredV4; /*SL_NETAPP_IPV4_IPACQUIRED_EVENT*/
  537. SlIpV6AcquiredAsync_t ipAcquiredV6; /*SL_NETAPP_IPV6_IPACQUIRED_EVENT*/
  538. _u32 sd; /*SL_SOCKET_TX_FAILED_EVENT*/
  539. SlIpLeasedAsync_t ipLeased; /* SL_NETAPP_IP_LEASED_EVENT */
  540. SlIpReleasedAsync_t ipReleased; /* SL_NETAPP_IP_RELEASED_EVENT */
  541. } SlNetAppEventData_u;
  542. typedef struct
  543. {
  544. _u32 Event;
  545. SlNetAppEventData_u EventData;
  546. }SlNetAppEvent_t;
  547. typedef struct sock_secureFiles
  548. {
  549. _u8 secureFiles[4];
  550. }SlSockSecureFiles_t;
  551. typedef struct SlFdSet_t /* The select socket array manager */
  552. {
  553. _u32 fd_array[(SL_FD_SETSIZE + 31)/32]; /* Bit map of SOCKET Descriptors */
  554. } SlFdSet_t;
  555. typedef struct
  556. {
  557. _u8 rate; /* Recevied Rate */
  558. _u8 channel; /* The received channel*/
  559. _i8 rssi; /* The computed RSSI value in db of current frame */
  560. _u8 padding; /* pad to align to 32 bits */
  561. _u32 timestamp; /* Timestamp in microseconds, */
  562. }SlTransceiverRxOverHead_t;
  563. /*****************************************************************************/
  564. /* Function prototypes */
  565. /*****************************************************************************/
  566. /*!
  567. \brief create an endpoint for communication
  568. The socket function creates a new socket of a certain socket type, identified
  569. by an integer number, and allocates system resources to it.
  570. This function is called by the application layer to obtain a socket handle.
  571. \param[in] domain specifies the protocol family of the created socket.
  572. For example:
  573. AF_INET for network protocol IPv4
  574. AF_RF for starting transceiver mode. Notes:
  575. - sending and receiving any packet overriding 802.11 header
  576. - for optimized power consumption the socket will be started in TX
  577. only mode until receive command is activated
  578. AF_INET6 for IPv6
  579. \param[in] type specifies the communication semantic, one of:
  580. SOCK_STREAM (reliable stream-oriented service or Stream Sockets)
  581. SOCK_DGRAM (datagram service or Datagram Sockets)
  582. SOCK_RAW (raw protocols atop the network layer)
  583. when used with AF_RF:
  584. SOCK_DGRAM - L2 socket
  585. SOCK_RAW - L1 socket - bypass WLAN CCA (Clear Channel Assessment)
  586. \param[in] protocol specifies a particular transport to be used with
  587. the socket.
  588. The most common are IPPROTO_TCP, IPPROTO_SCTP, IPPROTO_UDP,
  589. IPPROTO_DCCP.
  590. The value 0 may be used to select a default
  591. protocol from the selected domain and type
  592. \return On success, socket handle that is used for consequent socket operations.
  593. A successful return code should be a positive number (int16)
  594. On error, a negative (int16) value will be returned specifying the error code.
  595. SL_EAFNOSUPPORT - illegal domain parameter
  596. SL_EPROTOTYPE - illegal type parameter
  597. SL_EACCES - permission denied
  598. SL_ENSOCK - exceeded maximal number of socket
  599. SL_ENOMEM - memory allocation error
  600. SL_EINVAL - error in socket configuration
  601. SL_EPROTONOSUPPORT - illegal protocol parameter
  602. SL_EOPNOTSUPP - illegal combination of protocol and type parameters
  603. \sa sl_Close
  604. \note belongs to \ref basic_api
  605. \warning
  606. */
  607. #if _SL_INCLUDE_FUNC(sl_Socket)
  608. _i16 sl_Socket(_i16 Domain, _i16 Type, _i16 Protocol);
  609. #endif
  610. /*!
  611. \brief gracefully close socket
  612. This function causes the system to release resources allocated to a socket. \n
  613. In case of TCP, the connection is terminated.
  614. \param[in] sd socket handle (received in sl_Socket)
  615. \return On success, zero is returned.
  616. On error, a negative number is returned.
  617. \sa sl_Socket
  618. \note belongs to \ref ext_api
  619. \warning
  620. */
  621. #if _SL_INCLUDE_FUNC(sl_Close)
  622. _i16 sl_Close(_i16 sd);
  623. #endif
  624. /*!
  625. \brief Accept a connection on a socket
  626. This function is used with connection-based socket types (SOCK_STREAM).
  627. It extracts the first connection request on the queue of pending
  628. connections, creates a new connected socket, and returns a new file
  629. descriptor referring to that socket.
  630. The newly created socket is not in the listening state. The
  631. original socket sd is unaffected by this call.
  632. The argument sd is a socket that has been created with
  633. sl_Socket(), bound to a local address with sl_Bind(), and is
  634. listening for connections after a sl_Listen(). The argument \b
  635. \e addr is a pointer to a sockaddr structure. This structure
  636. is filled in with the address of the peer socket, as known to
  637. the communications layer. The exact format of the address
  638. returned addr is determined by the socket's address family.
  639. The \b \e addrlen argument is a value-result argument: it
  640. should initially contain the size of the structure pointed to
  641. by addr, on return it will contain the actual length (in
  642. bytes) of the address returned.
  643. \param[in] sd socket descriptor (handle)
  644. \param[out] addr the argument addr is a pointer
  645. to a sockaddr structure. This
  646. structure is filled in with the
  647. address of the peer socket, as
  648. known to the communications
  649. layer. The exact format of the
  650. address returned addr is
  651. determined by the socket's
  652. address\n
  653. sockaddr:\n - code for the
  654. address format. On this version
  655. only AF_INET is supported.\n -
  656. socket address, the length
  657. depends on the code format
  658. \param[out] addrlen the addrlen argument is a value-result
  659. argument: it should initially contain the
  660. size of the structure pointed to by addr
  661. \return On success, a socket handle.
  662. On a non-blocking accept a possible negative value is SL_EAGAIN.
  663. On failure, negative value.
  664. SL_POOL_IS_EMPTY may be return in case there are no resources in the system
  665. In this case try again later or increase MAX_CONCURRENT_ACTIONS
  666. \sa sl_Socket sl_Bind sl_Listen
  667. \note belongs to \ref server_side
  668. \warning
  669. */
  670. #if _SL_INCLUDE_FUNC(sl_Accept)
  671. _i16 sl_Accept(_i16 sd, SlSockAddr_t *addr, SlSocklen_t *addrlen);
  672. #endif
  673. /*!
  674. \brief assign a name to a socket
  675. This function gives the socket the local address addr.
  676. addr is addrlen bytes long. Traditionally, this is called
  677. When a socket is created with socket, it exists in a name
  678. space (address family) but has no name assigned.
  679. It is necessary to assign a local address before a SOCK_STREAM
  680. socket may receive connections.
  681. \param[in] sd socket descriptor (handle)
  682. \param[in] addr specifies the destination
  683. addrs\n sockaddr:\n - code for
  684. the address format. On this
  685. version only AF_INET is
  686. supported.\n - socket address,
  687. the length depends on the code
  688. format
  689. \param[in] addrlen contains the size of the structure pointed to by addr
  690. \return On success, zero is returned. On error, a negative error code is returned.
  691. \sa sl_Socket sl_Accept sl_Listen
  692. \note belongs to \ref basic_api
  693. \warning
  694. */
  695. #if _SL_INCLUDE_FUNC(sl_Bind)
  696. _i16 sl_Bind(_i16 sd, const SlSockAddr_t *addr, _i16 addrlen);
  697. #endif
  698. /*!
  699. \brief listen for connections on a socket
  700. The willingness to accept incoming connections and a queue
  701. limit for incoming connections are specified with listen(),
  702. and then the connections are accepted with accept.
  703. The listen() call applies only to sockets of type SOCK_STREAM
  704. The backlog parameter defines the maximum length the queue of
  705. pending connections may grow to.
  706. \param[in] sd socket descriptor (handle)
  707. \param[in] backlog specifies the listen queue depth.
  708. \return On success, zero is returned. On error, a negative error code is returned.
  709. \sa sl_Socket sl_Accept sl_Bind
  710. \note belongs to \ref server_side
  711. \warning
  712. */
  713. #if _SL_INCLUDE_FUNC(sl_Listen)
  714. _i16 sl_Listen(_i16 sd, _i16 backlog);
  715. #endif
  716. /*!
  717. \brief Initiate a connection on a socket
  718. Function connects the socket referred to by the socket
  719. descriptor sd, to the address specified by addr. The addrlen
  720. argument specifies the size of addr. The format of the
  721. address in addr is determined by the address space of the
  722. socket. If it is of type SOCK_DGRAM, this call specifies the
  723. peer with which the socket is to be associated; this address
  724. is that to which datagrams are to be sent, and the only
  725. address from which datagrams are to be received. If the
  726. socket is of type SOCK_STREAM, this call attempts to make a
  727. connection to another socket. The other socket is specified
  728. by address, which is an address in the communications space
  729. of the socket.
  730. \param[in] sd socket descriptor (handle)
  731. \param[in] addr specifies the destination addr\n
  732. sockaddr:\n - code for the
  733. address format. On this version
  734. only AF_INET is supported.\n -
  735. socket address, the length
  736. depends on the code format
  737. \param[in] addrlen contains the size of the structure pointed
  738. to by addr
  739. \return On success, a socket handle.
  740. On a non-blocking connect a possible negative value is SL_EALREADY.
  741. On failure, negative value.
  742. SL_POOL_IS_EMPTY may be return in case there are no resources in the system
  743. In this case try again later or increase MAX_CONCURRENT_ACTIONS
  744. \sa sl_Socket
  745. \note belongs to \ref client_side
  746. \warning
  747. */
  748. #if _SL_INCLUDE_FUNC(sl_Connect)
  749. _i16 sl_Connect(_i16 sd, const SlSockAddr_t *addr, _i16 addrlen);
  750. #endif
  751. /*!
  752. \brief Monitor socket activity
  753. Select allow a program to monitor multiple file descriptors,
  754. waiting until one or more of the file descriptors become
  755. "ready" for some class of I/O operation
  756. \param[in] nfds the highest-numbered file descriptor in any of the
  757. three sets, plus 1.
  758. \param[out] readsds socket descriptors list for read monitoring and accept monitoring
  759. \param[out] writesds socket descriptors list for connect monitoring only, write monitoring is not supported, non blocking connect is supported
  760. \param[out] exceptsds socket descriptors list for exception monitoring, not supported.
  761. \param[in] timeout is an upper bound on the amount of time elapsed
  762. before select() returns. Null or above 0xffff seconds means
  763. infinity timeout. The minimum timeout is 10 milliseconds,
  764. less than 10 milliseconds will be set automatically to 10 milliseconds.
  765. Max microseconds supported is 0xfffc00.
  766. \return On success, select() returns the number of
  767. file descriptors contained in the three returned
  768. descriptor sets (that is, the total number of bits that
  769. are set in readfds, writefds, exceptfds) which may be
  770. zero if the timeout expires before anything interesting
  771. happens. On error, a negative value is returned.
  772. readsds - return the sockets on which Read request will
  773. return without delay with valid data.
  774. writesds - return the sockets on which Write request
  775. will return without delay.
  776. exceptsds - return the sockets closed recently.
  777. SL_POOL_IS_EMPTY may be return in case there are no resources in the system
  778. In this case try again later or increase MAX_CONCURRENT_ACTIONS
  779. \sa sl_Socket
  780. \note If the timeout value set to less than 5ms it will automatically set
  781. to 5ms to prevent overload of the system
  782. belongs to \ref basic_api
  783. Only one sl_Select can be handled at a time.
  784. Calling this API while the same command is called from another thread, may result
  785. in one of the two scenarios:
  786. 1. The command will wait (internal) until the previous command finish, and then be executed.
  787. 2. There are not enough resources and SL_POOL_IS_EMPTY error will return.
  788. In this case, MAX_CONCURRENT_ACTIONS can be increased (result in memory increase) or try
  789. again later to issue the command.
  790. \warning
  791. */
  792. #if _SL_INCLUDE_FUNC(sl_Select)
  793. _i16 sl_Select(_i16 nfds, SlFdSet_t *readsds, SlFdSet_t *writesds, SlFdSet_t *exceptsds, struct SlTimeval_t *timeout);
  794. /*!
  795. \brief Select's SlFdSet_t SET function
  796. Sets current socket descriptor on SlFdSet_t container
  797. */
  798. void SL_FD_SET(_i16 fd, SlFdSet_t *fdset);
  799. /*!
  800. \brief Select's SlFdSet_t CLR function
  801. Clears current socket descriptor on SlFdSet_t container
  802. */
  803. void SL_FD_CLR(_i16 fd, SlFdSet_t *fdset);
  804. /*!
  805. \brief Select's SlFdSet_t ISSET function
  806. Checks if current socket descriptor is set (TRUE/FALSE)
  807. \return Returns TRUE if set, FALSE if unset
  808. */
  809. _i16 SL_FD_ISSET(_i16 fd, SlFdSet_t *fdset);
  810. /*!
  811. \brief Select's SlFdSet_t ZERO function
  812. Clears all socket descriptors from SlFdSet_t
  813. */
  814. void SL_FD_ZERO(SlFdSet_t *fdset);
  815. #endif
  816. /*!
  817. \brief set socket options
  818. This function manipulate the options associated with a socket.
  819. Options may exist at multiple protocol levels; they are always
  820. present at the uppermost socket level.
  821. When manipulating socket options the level at which the option resides
  822. and the name of the option must be specified. To manipulate options at
  823. the socket level, level is specified as SOL_SOCKET. To manipulate
  824. options at any other level the protocol number of the appropriate proto-
  825. col controlling the option is supplied. For example, to indicate that an
  826. option is to be interpreted by the TCP protocol, level should be set to
  827. the protocol number of TCP;
  828. The parameters optval and optlen are used to access optval -
  829. ues for setsockopt(). For getsockopt() they identify a
  830. buffer in which the value for the requested option(s) are to
  831. be returned. For getsockopt(), optlen is a value-result
  832. parameter, initially containing the size of the buffer
  833. pointed to by option_value, and modified on return to
  834. indicate the actual size of the value returned. If no option
  835. value is to be supplied or returned, option_value may be
  836. NULL.
  837. \param[in] sd socket handle
  838. \param[in] level defines the protocol level for this option
  839. - <b>SL_SOL_SOCKET</b> Socket level configurations (L4, transport layer)
  840. - <b>SL_IPPROTO_IP</b> IP level configurations (L3, network layer)
  841. - <b>SL_SOL_PHY_OPT</b> Link level configurations (L2, link layer)
  842. \param[in] optname defines the option name to interrogate
  843. - <b>SL_SOL_SOCKET</b>
  844. - <b>SL_SO_KEEPALIVE</b> \n
  845. Enable/Disable periodic keep alive.
  846. Keeps TCP connections active by enabling the periodic transmission of messages \n
  847. Timeout is 5 minutes.\n
  848. Default: Enabled \n
  849. This options takes SlSockKeepalive_t struct as parameter
  850. - <b>SL_SO_RCVTIMEO</b> \n
  851. Sets the timeout value that specifies the maximum amount of time an input function waits until it completes. \n
  852. Default: No timeout \n
  853. This options takes SlTimeval_t struct as parameter
  854. - <b>SL_SO_RCVBUF</b> \n
  855. Sets tcp max recv window size. \n
  856. This options takes SlSockWinsize_t struct as parameter
  857. - <b>SL_SO_NONBLOCKING</b> \n
  858. Sets socket to non-blocking operation Impacts: connect, accept, send, sendto, recv and recvfrom. \n
  859. Default: Blocking.
  860. This options takes SlSockNonblocking_t struct as parameter
  861. - <b>SL_SO_SECMETHOD</b> \n
  862. Sets method to tcp secured socket (SL_SEC_SOCKET) \n
  863. Default: SL_SO_SEC_METHOD_SSLv3_TLSV1_2 \n
  864. This options takes SlSockSecureMethod struct as parameter
  865. - <b>SL_SO_SEC_MASK</b> \n
  866. Sets specific cipher to tcp secured socket (SL_SEC_SOCKET) \n
  867. Default: "Best" cipher suitable to method \n
  868. This options takes SlSockSecureMask struct as parameter
  869. - <b>SL_SO_SECURE_FILES_CA_FILE_NAME</b> \n
  870. Map secured socket to CA file by name \n
  871. This options takes <b>_u8</b> buffer as parameter
  872. - <b>SL_SO_SECURE_FILES_PRIVATE_KEY_FILE_NAME</b> \n
  873. Map secured socket to private key by name \n
  874. This options takes <b>_u8</b> buffer as parameter
  875. - <b>SL_SO_SECURE_FILES_CERTIFICATE_FILE_NAME</b> \n
  876. Map secured socket to certificate file by name \n
  877. This options takes <b>_u8</b> buffer as parameter
  878. - <b>SL_SO_SECURE_FILES_DH_KEY_FILE_NAME</b> \n
  879. Map secured socket to Diffie Hellman file by name \n
  880. This options takes <b>_u8</b> buffer as parameter
  881. - <b>SL_SO_CHANGE_CHANNEL</b> \n
  882. Sets channel in transceiver mode.
  883. This options takes <b>_u32</b> as channel number parameter
  884. - <b>SL_IPPROTO_IP</b>
  885. - <b>SL_IP_MULTICAST_TTL</b> \n
  886. Set the time-to-live value of outgoing multicast packets for this socket. \n
  887. This options takes <b>_u8</b> as parameter
  888. - <b>SL_IP_ADD_MEMBERSHIP</b> \n
  889. UDP socket, Join a multicast group. \n
  890. This options takes SlSockIpMreq struct as parameter
  891. - <b>SL_IP_DROP_MEMBERSHIP</b> \n
  892. UDP socket, Leave a multicast group \n
  893. This options takes SlSockIpMreq struct as parameter
  894. - <b>SL_IP_RAW_RX_NO_HEADER</b> \n
  895. Raw socket remove IP header from received data. \n
  896. Default: data includes ip header \n
  897. This options takes <b>_u32</b> as parameter
  898. - <b>SL_IP_HDRINCL</b> \n
  899. RAW socket only, the IPv4 layer generates an IP header when sending a packet unless \n
  900. the IP_HDRINCL socket option is enabled on the socket. \n
  901. When it is enabled, the packet must contain an IP header. \n
  902. Default: disabled, IPv4 header generated by Network Stack \n
  903. This options takes <b>_u32</b> as parameter
  904. - <b>SL_IP_RAW_IPV6_HDRINCL</b> (inactive) \n
  905. RAW socket only, the IPv6 layer generates an IP header when sending a packet unless \n
  906. the IP_HDRINCL socket option is enabled on the socket. When it is enabled, the packet must contain an IP header \n
  907. Default: disabled, IPv4 header generated by Network Stack \n
  908. This options takes <b>_u32</b> as parameter
  909. - <b>SL_SOL_PHY_OPT</b>
  910. - <b>SL_SO_PHY_RATE</b> \n
  911. RAW socket, set WLAN PHY transmit rate \n
  912. The values are based on RateIndex_e \n
  913. This options takes <b>_u32</b> as parameter
  914. - <b>SL_SO_PHY_TX_POWER</b> \n
  915. RAW socket, set WLAN PHY TX power \n
  916. Valid rage is 1-15 \n
  917. This options takes <b>_u32</b> as parameter
  918. - <b>SL_SO_PHY_NUM_FRAMES_TO_TX</b> \n
  919. RAW socket, set number of frames to transmit in transceiver mode.
  920. Default: 1 packet
  921. This options takes <b>_u32</b> as parameter
  922. - <b>SL_SO_PHY_PREAMBLE</b> \n
  923. RAW socket, set WLAN PHY preamble for Long/Short\n
  924. This options takes <b>_u32</b> as parameter
  925. \param[in] optval specifies a value for the option
  926. \param[in] optlen specifies the length of the
  927. option value
  928. \return On success, zero is returned.
  929. On error, a negative value is returned.
  930. \sa sl_getsockopt
  931. \note belongs to \ref basic_api
  932. \warning
  933. \par Examples:
  934. \par
  935. <b> SL_SO_KEEPALIVE: </b>(disable Keepalive)
  936. \code
  937. SlSockKeepalive_t enableOption;
  938. enableOption.KeepaliveEnabled = 0;
  939. sl_SetSockOpt(SockID,SL_SOL_SOCKET,SL_SO_KEEPALIVE, (_u8 *)&enableOption,sizeof(enableOption));
  940. \endcode
  941. \par
  942. <b> SL_SO_RCVTIMEO: </b>
  943. \code
  944. struct SlTimeval_t timeVal;
  945. timeVal.tv_sec = 1; // Seconds
  946. timeVal.tv_usec = 0; // Microseconds. 10000 microseconds resolution
  947. sl_SetSockOpt(SockID,SL_SOL_SOCKET,SL_SO_RCVTIMEO, (_u8 *)&timeVal, sizeof(timeVal)); // Enable receive timeout
  948. \endcode
  949. \par
  950. <b> SL_SO_RCVBUF: </b>
  951. \code
  952. SlSockWinsize_t size;
  953. size.Winsize = 3000; // bytes
  954. sl_SetSockOpt(SockID,SL_SOL_SOCKET,SL_SO_RCVBUF, (_u8 *)&size, sizeof(size));
  955. \endcode
  956. \par
  957. <b> SL_SO_NONBLOCKING: </b>
  958. \code
  959. SlSockNonblocking_t enableOption;
  960. enableOption.NonblockingEnabled = 1;
  961. sl_SetSockOpt(SockID,SL_SOL_SOCKET,SL_SO_NONBLOCKING, (_u8 *)&enableOption,sizeof(enableOption)); // Enable/disable nonblocking mode
  962. \endcode
  963. \par
  964. <b> SL_SO_SECMETHOD:</b>
  965. \code
  966. SlSockSecureMethod method;
  967. method.secureMethod = SL_SO_SEC_METHOD_SSLV3; // security method we want to use
  968. SockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, SL_SEC_SOCKET);
  969. sl_SetSockOpt(SockID, SL_SOL_SOCKET, SL_SO_SECMETHOD, (_u8 *)&method, sizeof(method));
  970. \endcode
  971. \par
  972. <b> SL_SO_SECURE_MASK:</b>
  973. \code
  974. SlSockSecureMask cipher;
  975. cipher.secureMask = SL_SEC_MASK_SSL_RSA_WITH_RC4_128_SHA; // cipher type
  976. SockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, SL_SEC_SOCKET);
  977. sl_SetSockOpt(SockID, SL_SOL_SOCKET, SL_SO_SEC_MASK,(_u8 *)&cipher, sizeof(cipher));
  978. \endcode
  979. \par
  980. <b> SL_SO_SECURE_FILES_CA_FILE_NAME:</b>
  981. \code
  982. sl_SetSockOpt(SockID,SL_SOL_SOCKET,SL_SO_SECURE_FILES_CA_FILE_NAME,"exuifaxCaCert.der",strlen("exuifaxCaCert.der"));
  983. \endcode
  984. \par
  985. <b> SL_SO_SECURE_FILES_PRIVATE_KEY_FILE_NAME:</b>
  986. \code
  987. sl_SetSockOpt(SockID,SL_SOL_SOCKET,SL_SO_SECURE_FILES_PRIVATE_KEY_FILE_NAME,"myPrivateKey.der",strlen("myPrivateKey.der"));
  988. \endcode
  989. \par
  990. <b> SL_SO_SECURE_FILES_CERTIFICATE_FILE_NAME:</b>
  991. \code
  992. sl_SetSockOpt(SockID,SL_SOL_SOCKET,SL_SO_SECURE_FILES_CERTIFICATE_FILE_NAME,"myCertificate.der",strlen("myCertificate.der"));
  993. \endcode
  994. \par
  995. <b> SL_SO_SECURE_FILES_DH_KEY_FILE_NAME:</b>
  996. \code
  997. sl_SetSockOpt(SockID,SL_SOL_SOCKET,SL_SO_SECURE_FILES_DH_KEY_FILE_NAME,"myDHinServerMode.der",strlen("myDHinServerMode.der"));
  998. \endcode
  999. \par
  1000. <b> SL_IP_MULTICAST_TTL:</b>
  1001. \code
  1002. _u8 ttl = 20;
  1003. sl_SetSockOpt(SockID, SL_IPPROTO_IP, SL_IP_MULTICAST_TTL, &ttl, sizeof(ttl));
  1004. \endcode
  1005. \par
  1006. <b> SL_IP_ADD_MEMBERSHIP:</b>
  1007. \code
  1008. SlSockIpMreq mreq;
  1009. sl_SetSockOpt(SockID, SL_IPPROTO_IP, SL_IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq));
  1010. \endcode
  1011. \par
  1012. <b> SL_IP_DROP_MEMBERSHIP:</b>
  1013. \code
  1014. SlSockIpMreq mreq;
  1015. sl_SetSockOpt(SockID, SL_IPPROTO_IP, SL_IP_DROP_MEMBERSHIP, &mreq, sizeof(mreq));
  1016. \endcode
  1017. \par
  1018. <b> SL_SO_CHANGE_CHANNEL:</b>
  1019. \code
  1020. _u32 newChannel = 6; // range is 1-13
  1021. sl_SetSockOpt(SockID, SL_SOL_SOCKET, SL_SO_CHANGE_CHANNEL, &newChannel, sizeof(newChannel));
  1022. \endcode
  1023. \par
  1024. <b> SL_IP_RAW_RX_NO_HEADER:</b>
  1025. \code
  1026. _u32 header = 1; // remove ip header
  1027. sl_SetSockOpt(SockID, SL_IPPROTO_IP, SL_IP_RAW_RX_NO_HEADER, &header, sizeof(header));
  1028. \endcode
  1029. \par
  1030. <b> SL_IP_HDRINCL:</b>
  1031. \code
  1032. _u32 header = 1;
  1033. sl_SetSockOpt(SockID, SL_IPPROTO_IP, SL_IP_HDRINCL, &header, sizeof(header));
  1034. \endcode
  1035. \par
  1036. <b> SL_IP_RAW_IPV6_HDRINCL:</b>
  1037. \code
  1038. _u32 header = 1;
  1039. sl_SetSockOpt(SockID, SL_IPPROTO_IP, SL_IP_RAW_IPV6_HDRINCL, &header, sizeof(header));
  1040. \endcode
  1041. \par
  1042. <b> SL_SO_PHY_RATE:</b>
  1043. \code
  1044. _u32 rate = 6; // see wlan.h RateIndex_e for values
  1045. sl_SetSockOpt(SockID, SL_SOL_PHY_OPT, SL_SO_PHY_RATE, &rate, sizeof(rate));
  1046. \endcode
  1047. \par
  1048. <b> SL_SO_PHY_TX_POWER:</b>
  1049. \code
  1050. _u32 txpower = 1; // valid range is 1-15
  1051. sl_SetSockOpt(SockID, SL_SOL_PHY_OPT, SL_SO_PHY_TX_POWER, &txpower, sizeof(txpower));
  1052. \endcode
  1053. \par
  1054. <b> SL_SO_PHY_NUM_FRAMES_TO_TX:</b>
  1055. \code
  1056. _u32 numframes = 1;
  1057. sl_SetSockOpt(SockID, SL_SOL_PHY_OPT, SL_SO_PHY_NUM_FRAMES_TO_TX, &numframes, sizeof(numframes));
  1058. \endcode
  1059. \par
  1060. <b> SL_SO_PHY_PREAMBLE:</b>
  1061. \code
  1062. _u32 preamble = 1;
  1063. sl_SetSockOpt(SockID, SL_SOL_PHY_OPT, SL_SO_PHY_PREAMBLE, &preamble, sizeof(preamble));
  1064. \endcode
  1065. */
  1066. #if _SL_INCLUDE_FUNC(sl_SetSockOpt)
  1067. _i16 sl_SetSockOpt(_i16 sd, _i16 level, _i16 optname, const void *optval, SlSocklen_t optlen);
  1068. #endif
  1069. /*!
  1070. \brief Get socket options
  1071. This function manipulate the options associated with a socket.
  1072. Options may exist at multiple protocol levels; they are always
  1073. present at the uppermost socket level.
  1074. When manipulating socket options the level at which the option resides
  1075. and the name of the option must be specified. To manipulate options at
  1076. the socket level, level is specified as SOL_SOCKET. To manipulate
  1077. options at any other level the protocol number of the appropriate proto-
  1078. col controlling the option is supplied. For example, to indicate that an
  1079. option is to be interpreted by the TCP protocol, level should be set to
  1080. the protocol number of TCP;
  1081. The parameters optval and optlen are used to access optval -
  1082. ues for setsockopt(). For getsockopt() they identify a
  1083. buffer in which the value for the requested option(s) are to
  1084. be returned. For getsockopt(), optlen is a value-result
  1085. parameter, initially containing the size of the buffer
  1086. pointed to by option_value, and modified on return to
  1087. indicate the actual size of the value returned. If no option
  1088. value is to be supplied or returned, option_value may be
  1089. NULL.
  1090. \param[in] sd socket handle
  1091. \param[in] level defines the protocol level for this option
  1092. \param[in] optname defines the option name to interrogate
  1093. \param[out] optval specifies a value for the option
  1094. \param[out] optlen specifies the length of the
  1095. option value
  1096. \return On success, zero is returned.
  1097. On error, a negative value is returned.
  1098. \sa sl_SetSockOpt
  1099. \note See sl_SetSockOpt
  1100. belongs to \ref ext_api
  1101. \warning
  1102. */
  1103. #if _SL_INCLUDE_FUNC(sl_GetSockOpt)
  1104. _i16 sl_GetSockOpt(_i16 sd, _i16 level, _i16 optname, void *optval, SlSocklen_t *optlen);
  1105. #endif
  1106. /*!
  1107. \brief read data from TCP socket
  1108. function receives a message from a connection-mode socket
  1109. \param[in] sd socket handle
  1110. \param[out] buf Points to the buffer where the
  1111. message should be stored.
  1112. \param[in] Len Specifies the length in bytes of
  1113. the buffer pointed to by the buffer argument.
  1114. Range: 1-16000 bytes
  1115. \param[in] flags Specifies the type of message
  1116. reception. On this version, this parameter is not
  1117. supported.
  1118. \return return the number of bytes received,
  1119. or a negative value if an error occurred.
  1120. using a non-blocking recv a possible negative value is SL_EAGAIN.
  1121. SL_POOL_IS_EMPTY may be return in case there are no resources in the system
  1122. In this case try again later or increase MAX_CONCURRENT_ACTIONS
  1123. \sa sl_RecvFrom
  1124. \note belongs to \ref recv_api
  1125. \warning
  1126. \par Examples:
  1127. \code An example of receiving data using TCP socket:
  1128. SlSockAddrIn_t Addr;
  1129. SlSockAddrIn_t LocalAddr;
  1130. _i16 AddrSize = sizeof(SlSockAddrIn_t);
  1131. _i16 SockID, newSockID;
  1132. _i16 Status;
  1133. _i8 Buf[RECV_BUF_LEN];
  1134. LocalAddr.sin_family = SL_AF_INET;
  1135. LocalAddr.sin_port = sl_Htons(5001);
  1136. LocalAddr.sin_addr.s_addr = 0;
  1137. Addr.sin_family = SL_AF_INET;
  1138. Addr.sin_port = sl_Htons(5001);
  1139. Addr.sin_addr.s_addr = sl_Htonl(SL_IPV4_VAL(10,1,1,200));
  1140. SockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0);
  1141. Status = sl_Bind(SockID, (SlSockAddr_t *)&LocalAddr, AddrSize);
  1142. Status = sl_Listen(SockID, 0);
  1143. newSockID = sl_Accept(SockID, (SlSockAddr_t*)&Addr, (SlSocklen_t*) &AddrSize);
  1144. Status = sl_Recv(newSockID, Buf, 1460, 0);
  1145. \endcode
  1146. \code Example code for Rx transceiver mode using a raw socket
  1147. _i8 buffer[1536];
  1148. _i16 sd;
  1149. _u16 size;
  1150. SlTransceiverRxOverHead_t *transHeader;
  1151. sd = sl_Socket(SL_AF_RF,SL_SOCK_RAW,11); // channel 11
  1152. while(1)
  1153. {
  1154. size = sl_Recv(sd,buffer,1536,0);
  1155. transHeader = (SlTransceiverRxOverHead_t *)buffer;
  1156. printf("RSSI is %d frame type is 0x%x size %d\n",transHeader->rssi,buffer[sizeof(SlTransceiverRxOverHead_t)],size);
  1157. }
  1158. \endcode
  1159. */
  1160. #if _SL_INCLUDE_FUNC(sl_Recv)
  1161. _i16 sl_Recv(_i16 sd, void *buf, _i16 Len, _i16 flags);
  1162. #endif
  1163. /*!
  1164. \brief read data from socket
  1165. function receives a message from a connection-mode or
  1166. connectionless-mode socket
  1167. \param[in] sd socket handle
  1168. \param[out] buf Points to the buffer where the message should be stored.
  1169. \param[in] Len Specifies the length in bytes of the buffer pointed to by the buffer argument.
  1170. Range: 1-16000 bytes
  1171. \param[in] flags Specifies the type of message
  1172. reception. On this version, this parameter is not
  1173. supported.
  1174. \param[in] from pointer to an address structure
  1175. indicating the source
  1176. address.\n sockaddr:\n - code
  1177. for the address format. On this
  1178. version only AF_INET is
  1179. supported.\n - socket address,
  1180. the length depends on the code
  1181. format
  1182. \param[in] fromlen source address structure
  1183. size. This parameter MUST be set to the size of the structure pointed to by addr.
  1184. \return return the number of bytes received,
  1185. or a negative value if an error occurred.
  1186. using a non-blocking recv a possible negative value is SL_EAGAIN.
  1187. SL_RET_CODE_INVALID_INPUT (-2) will be returned if fromlen has incorrect length.
  1188. SL_POOL_IS_EMPTY may be return in case there are no resources in the system
  1189. In this case try again later or increase MAX_CONCURRENT_ACTIONS
  1190. \sa sl_Recv
  1191. \note belongs to \ref recv_api
  1192. \warning
  1193. \par Example:
  1194. \code An example of receiving data:
  1195. SlSockAddrIn_t Addr;
  1196. SlSockAddrIn_t LocalAddr;
  1197. _i16 AddrSize = sizeof(SlSockAddrIn_t);
  1198. _i16 SockID;
  1199. _i16 Status;
  1200. _i8 Buf[RECV_BUF_LEN];
  1201. LocalAddr.sin_family = SL_AF_INET;
  1202. LocalAddr.sin_port = sl_Htons(5001);
  1203. LocalAddr.sin_addr.s_addr = 0;
  1204. SockID = sl_Socket(SL_AF_INET,SL_SOCK_DGRAM, 0);
  1205. Status = sl_Bind(SockID, (SlSockAddr_t *)&LocalAddr, AddrSize);
  1206. Status = sl_RecvFrom(SockID, Buf, 1472, 0, (SlSockAddr_t *)&Addr, (SlSocklen_t*)&AddrSize);
  1207. \endcode
  1208. */
  1209. #if _SL_INCLUDE_FUNC(sl_RecvFrom)
  1210. _i16 sl_RecvFrom(_i16 sd, void *buf, _i16 Len, _i16 flags, SlSockAddr_t *from, SlSocklen_t *fromlen);
  1211. #endif
  1212. /*!
  1213. \brief write data to TCP socket
  1214. This function is used to transmit a message to another socket.
  1215. Returns immediately after sending data to device.
  1216. In case of TCP failure an async event SL_SOCKET_TX_FAILED_EVENT is going to
  1217. be received.
  1218. In case of a RAW socket (transceiver mode), extra 4 bytes should be reserved at the end of the
  1219. frame data buffer for WLAN FCS
  1220. \param[in] sd socket handle
  1221. \param[in] buf Points to a buffer containing
  1222. the message to be sent
  1223. \param[in] Len message size in bytes. Range: 1-1460 bytes
  1224. \param[in] flags Specifies the type of message
  1225. transmission. On this version, this parameter is not
  1226. supported for TCP.
  1227. For transceiver mode, the SL_RAW_RF_TX_PARAMS macro can be used to determine
  1228. transmission parameters (channel,rate,tx_power,preamble)
  1229. \return Return the number of bytes transmitted,
  1230. or -1 if an error occurred
  1231. \sa sl_SendTo
  1232. \note belongs to \ref send_api
  1233. \warning
  1234. \par Example:
  1235. \code An example of sending data:
  1236. SlSockAddrIn_t Addr;
  1237. _i16 AddrSize = sizeof(SlSockAddrIn_t);
  1238. _i16 SockID;
  1239. _i16 Status;
  1240. _i8 Buf[SEND_BUF_LEN];
  1241. Addr.sin_family = SL_AF_INET;
  1242. Addr.sin_port = sl_Htons(5001);
  1243. Addr.sin_addr.s_addr = sl_Htonl(SL_IPV4_VAL(10,1,1,200));
  1244. SockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0);
  1245. Status = sl_Connect(SockID, (SlSockAddr_t *)&Addr, AddrSize);
  1246. Status = sl_Send(SockID, Buf, 1460, 0 );
  1247. \endcode
  1248. */
  1249. #if _SL_INCLUDE_FUNC(sl_Send )
  1250. _i16 sl_Send(_i16 sd, const void *buf, _i16 Len, _i16 flags);
  1251. #endif
  1252. /*!
  1253. \brief write data to socket
  1254. This function is used to transmit a message to another socket
  1255. (connection less socket SOCK_DGRAM, SOCK_RAW).
  1256. Returns immediately after sending data to device.
  1257. In case of transmission failure an async event SL_SOCKET_TX_FAILED_EVENT is going to
  1258. be received.
  1259. \param[in] sd socket handle
  1260. \param[in] buf Points to a buffer containing
  1261. the message to be sent
  1262. \param[in] Len message size in bytes. Range: 1-1460 bytes
  1263. \param[in] flags Specifies the type of message
  1264. transmission. On this version, this parameter is not
  1265. supported
  1266. \param[in] to pointer to an address structure
  1267. indicating the destination
  1268. address.\n sockaddr:\n - code
  1269. for the address format. On this
  1270. version only AF_INET is
  1271. supported.\n - socket address,
  1272. the length depends on the code
  1273. format
  1274. \param[in] tolen destination address structure size
  1275. \return Return the number of transmitted bytes,
  1276. or -1 if an error occurred
  1277. \sa sl_Send
  1278. \note belongs to \ref send_api
  1279. \warning
  1280. \par Example:
  1281. \code An example of sending data:
  1282. SlSockAddrIn_t Addr;
  1283. _i16 AddrSize = sizeof(SlSockAddrIn_t);
  1284. _i16 SockID;
  1285. _i16 Status;
  1286. _i8 Buf[SEND_BUF_LEN];
  1287. Addr.sin_family = SL_AF_INET;
  1288. Addr.sin_port = sl_Htons(5001);
  1289. Addr.sin_addr.s_addr = sl_Htonl(SL_IPV4_VAL(10,1,1,200));
  1290. SockID = sl_Socket(SL_AF_INET,SL_SOCK_DGRAM, 0);
  1291. Status = sl_SendTo(SockID, Buf, 1472, 0, (SlSockAddr_t *)&Addr, AddrSize);
  1292. \endcode
  1293. */
  1294. #if _SL_INCLUDE_FUNC(sl_SendTo)
  1295. _i16 sl_SendTo(_i16 sd, const void *buf, _i16 Len, _i16 flags, const SlSockAddr_t *to, SlSocklen_t tolen);
  1296. #endif
  1297. /*!
  1298. \brief Reorder the bytes of a 32-bit unsigned value
  1299. This function is used to Reorder the bytes of a 32-bit unsigned value from processor order to network order.
  1300. \param[in] var variable to reorder
  1301. \return Return the reorder variable,
  1302. \sa sl_SendTo sl_Bind sl_Connect sl_RecvFrom sl_Accept
  1303. \note belongs to \ref send_api
  1304. \warning
  1305. */
  1306. #if _SL_INCLUDE_FUNC(sl_Htonl )
  1307. _u32 sl_Htonl( _u32 val );
  1308. #define sl_Ntohl sl_Htonl /* Reorder the bytes of a 16-bit unsigned value from network order to processor orde. */
  1309. #endif
  1310. /*!
  1311. \brief Reorder the bytes of a 16-bit unsigned value
  1312. This function is used to Reorder the bytes of a 16-bit unsigned value from processor order to network order.
  1313. \param[in] var variable to reorder
  1314. \return Return the reorder variable,
  1315. \sa sl_SendTo sl_Bind sl_Connect sl_RecvFrom sl_Accept
  1316. \note belongs to \ref send_api
  1317. \warning
  1318. */
  1319. #if _SL_INCLUDE_FUNC(sl_Htons )
  1320. _u16 sl_Htons( _u16 val );
  1321. #define sl_Ntohs sl_Htons /* Reorder the bytes of a 16-bit unsigned value from network order to processor orde. */
  1322. #endif
  1323. /*!
  1324. Close the Doxygen group.
  1325. @}
  1326. */
  1327. #ifdef __cplusplus
  1328. }
  1329. #endif /* __cplusplus */
  1330. #endif /* __SOCKET_H__ */