rpc.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  1. /****************************************************************************
  2. * fs/nfs/rpc.h
  3. *
  4. * Copyright (C) 2012 Gregory Nutt. All rights reserved.
  5. * Copyright (C) 2012 Jose Pablo Rojas Vargas. All rights reserved.
  6. * Author: Jose Pablo Rojas Vargas <jrojas@nx-engineering.com>
  7. * Gregory Nutt <gnutt@nuttx.org>
  8. *
  9. * Leveraged from OpenBSD:
  10. *
  11. * copyright (c) 2003
  12. * the regents of the university of michigan
  13. * all rights reserved
  14. *
  15. * permission is granted to use, copy, create derivative works and redistribute
  16. * this software and such derivative works for any purpose, so long as the name
  17. * of the university of michigan is not used in any advertising or publicity
  18. * pertaining to the use or distribution of this software without specific,
  19. * written prior authorization. if the above copyright notice or any other
  20. * identification of the university of michigan is included in any copy of any
  21. * portion of this software, then the disclaimer below must also be included.
  22. *
  23. * this software is provided as is, without representation from the university
  24. * of michigan as to its fitness for any purpose, and without warranty by the
  25. * university of michigan of any kind, either express or implied, including
  26. * without limitation the implied warranties of merchantability and fitness for
  27. * a particular purpose. the regents of the university of michigan shall not be
  28. * liable for any damages, including special, indirect, incidental, or
  29. * consequential damages, with respect to any claim arising out of or in
  30. * connection with the use of the software, even if it has been or is hereafter
  31. * advised of the possibility of such damages.
  32. *
  33. * Copyright (c) 1989, 1993
  34. * The Regents of the University of California. All rights reserved.
  35. *
  36. * This code is derived from software contributed to Berkeley by
  37. * Rick Macklem at The University of Guelph.
  38. *
  39. * Redistribution and use in source and binary forms, with or without
  40. * modification, are permitted provided that the following conditions
  41. * are met:
  42. *
  43. * 1. Redistributions of source code must retain the above copyright
  44. * notice, this list of conditions and the following disclaimer.
  45. * 2. Redistributions in binary form must reproduce the above copyright
  46. * notice, this list of conditions and the following disclaimer in the
  47. * documentation and/or other materials provided with the distribution.
  48. * 3. All advertising materials mentioning features or use of this software
  49. * must display the following acknowledgement:
  50. * This product includes software developed by the University of
  51. * California, Berkeley and its contributors.
  52. * 4. Neither the name of the University nor the names of its contributors
  53. * may be used to endorse or promote products derived from this software
  54. * without specific prior written permission.
  55. *
  56. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  57. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  58. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  59. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  60. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  61. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  62. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  63. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  64. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  65. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  66. * SUCH DAMAGE.
  67. *
  68. ****************************************************************************/
  69. #ifndef __FS_NFS_RPC_H
  70. #define __FS_NFS_RPC_H
  71. /****************************************************************************
  72. * Included Files
  73. ****************************************************************************/
  74. #include <sys/types.h>
  75. #include <nuttx/net/net.h>
  76. #include "nfs_proto.h"
  77. /****************************************************************************
  78. * Pre-processor Definitions
  79. ****************************************************************************/
  80. /* Version # */
  81. #define RPC_VER2 2
  82. /* Authentication */
  83. #define RPCAUTH_NULL 0
  84. #define RPCAUTH_UNIX 1
  85. #define RPCAUTH_SHORT 2
  86. #define RPCAUTH_KERB4 4
  87. #define RPCAUTH_MAXSIZ 400
  88. #define RPCVERF_MAXSIZ 12
  89. /* For Kerb, can actually be 400 */
  90. #define RPCAUTH_UNIXGIDS 16
  91. /* Constants associated with authentication flavours. */
  92. #define RPCAKN_FULLNAME 0
  93. #define RPCAKN_NICKNAME 1
  94. /* RPC Constants */
  95. #define RPC_CALL 0
  96. #define RPC_REPLY 1
  97. #define RPC_MSGACCEPTED 0
  98. #define RPC_MSGDENIED 1
  99. #define RPC_PROGUNAVAIL 1
  100. #define RPC_PROGMISMATCH 2
  101. #define RPC_PROCUNAVAIL 3
  102. #define RPC_GARBAGE 4
  103. #define RPC_MISMATCH 0
  104. #define RPC_AUTHERR 1
  105. /* Authentication failures */
  106. #define AUTH_BADCRED 1
  107. #define AUTH_REJECTCRED 2
  108. #define AUTH_BADVERF 3
  109. #define AUTH_REJECTVERF 4
  110. #define AUTH_TOOWEAK 5
  111. /* Sizes of RPC header parts */
  112. #define RPC_SIZ 24
  113. #define RPC_REPLYSIZ 28
  114. /* RPC Prog definitions */
  115. #define RPCPROG_MNT 100005
  116. #define RPCMNT_VER1 1
  117. #define RPCMNT_VER3 3
  118. #define RPCMNT_MOUNT 1
  119. #define RPCMNT_DUMP 2
  120. #define RPCMNT_UMOUNT 3
  121. #define RPCMNT_UMNTALL 4
  122. #define RPCMNT_EXPORT 5
  123. #define RPCMNT_NAMELEN 255
  124. #define RPCMNT_PATHLEN 1024
  125. #define RPCPROG_NFS 100003
  126. /* RPC definitions for the portmapper. */
  127. #define PMAPPROG 100000
  128. #define PMAPVERS 2
  129. #define PMAPPROC_NULL 0
  130. #define PMAPPROC_SET 1
  131. #define PMAPPROC_UNSET 2
  132. #define PMAPPROC_GETPORT 3
  133. #define PMAPPROC_DUMP 4
  134. #define PMAPPROC_CALLIT 5
  135. #define RPC_SUCCESS 0
  136. /****************************************************************************
  137. * Public Types
  138. ****************************************************************************/
  139. /* PMAP headers */
  140. struct call_args_pmap
  141. {
  142. uint32_t prog;
  143. uint32_t vers;
  144. uint32_t prot;
  145. uint32_t port;
  146. };
  147. struct call_result_pmap
  148. {
  149. uint32_t port;
  150. };
  151. /* MOUNTD headers */
  152. struct call_args_mount
  153. {
  154. uint32_t len;
  155. char rpath[90];
  156. };
  157. struct call_args_umount
  158. {
  159. uint32_t len;
  160. char rpath[90];
  161. };
  162. enum auth_flavor
  163. {
  164. AUTH_NONE = 0,
  165. AUTH_SYS = 1,
  166. AUTH_SHORT = 2,
  167. AUTH_DES = 3,
  168. AUTH_MAX
  169. /* and more to be defined */
  170. };
  171. struct call_result_mount
  172. {
  173. uint32_t status;
  174. struct file_handle fhandle;
  175. uint32_t authlen;
  176. uint32_t authlist[AUTH_MAX];
  177. };
  178. /* Generic RPC call headers */
  179. struct rpc_auth_info
  180. {
  181. uint32_t authtype; /* auth type */
  182. uint32_t authlen; /* auth length */
  183. };
  184. struct rpc_auth_unix
  185. {
  186. uint32_t stamp;
  187. uint32_t hostname; /* null */
  188. uint32_t uid;
  189. uint32_t gid;
  190. uint32_t gidlist; /* null */
  191. };
  192. struct rpc_call_header
  193. {
  194. uint32_t rp_xid; /* request transaction id */
  195. int32_t rp_direction; /* call direction (0) */
  196. uint32_t rp_rpcvers; /* RPC version (2) */
  197. uint32_t rp_prog; /* program */
  198. uint32_t rp_vers; /* version */
  199. uint32_t rp_proc; /* procedure */
  200. struct rpc_auth_info rpc_auth;
  201. struct rpc_auth_unix rpc_unix;
  202. struct rpc_auth_info rpc_verf;
  203. };
  204. struct rpc_call_pmap
  205. {
  206. struct rpc_call_header ch;
  207. struct call_args_pmap pmap;
  208. };
  209. struct rpc_call_mount
  210. {
  211. struct rpc_call_header ch;
  212. struct call_args_mount mount;
  213. };
  214. struct rpc_call_umount
  215. {
  216. struct rpc_call_header ch;
  217. struct call_args_umount umount;
  218. };
  219. struct rpc_call_create
  220. {
  221. struct rpc_call_header ch;
  222. struct CREATE3args create;
  223. };
  224. struct rpc_call_lookup
  225. {
  226. struct rpc_call_header ch;
  227. struct LOOKUP3args lookup;
  228. };
  229. #define SIZEOF_rpc_call_lookup(n) (sizeof(struct rpc_call_header) + SIZEOF_LOOKUP3args(n))
  230. struct rpc_call_read
  231. {
  232. struct rpc_call_header ch;
  233. struct READ3args read;
  234. };
  235. struct rpc_call_write
  236. {
  237. struct rpc_call_header ch;
  238. struct WRITE3args write; /* Variable length */
  239. };
  240. #define SIZEOF_rpc_call_write(n) (sizeof(struct rpc_call_header) + SIZEOF_WRITE3args(n))
  241. struct rpc_call_remove
  242. {
  243. struct rpc_call_header ch;
  244. struct REMOVE3args remove;
  245. };
  246. struct rpc_call_rename
  247. {
  248. struct rpc_call_header ch;
  249. struct RENAME3args rename;
  250. };
  251. struct rpc_call_mkdir
  252. {
  253. struct rpc_call_header ch;
  254. struct MKDIR3args mkdir;
  255. };
  256. struct rpc_call_rmdir
  257. {
  258. struct rpc_call_header ch;
  259. struct RMDIR3args rmdir;
  260. };
  261. struct rpc_call_readdir
  262. {
  263. struct rpc_call_header ch;
  264. struct READDIR3args readdir;
  265. };
  266. struct rpc_call_setattr
  267. {
  268. struct rpc_call_header ch;
  269. struct SETATTR3args setattr;
  270. };
  271. struct rpc_call_fs
  272. {
  273. struct rpc_call_header ch;
  274. struct FS3args fs;
  275. };
  276. /* Generic RPC reply headers */
  277. struct rpc_reply_header
  278. {
  279. uint32_t rp_xid; /* Request transaction id */
  280. uint32_t rp_direction; /* Call direction (1) */
  281. uint32_t type;
  282. struct rpc_auth_info rpc_verfi;
  283. uint32_t status;
  284. };
  285. struct nfs_reply_header
  286. {
  287. struct rpc_reply_header rh;
  288. uint32_t nfs_status;
  289. };
  290. struct rpc_reply_pmap
  291. {
  292. struct rpc_reply_header rh;
  293. struct call_result_pmap pmap;
  294. };
  295. struct rpc_reply_mount
  296. {
  297. struct rpc_reply_header rh;
  298. struct call_result_mount mount;
  299. };
  300. struct rpc_reply_umount
  301. {
  302. struct rpc_reply_header rh;
  303. };
  304. struct rpc_reply_create
  305. {
  306. struct nfs_reply_header rh;
  307. struct CREATE3resok create;
  308. };
  309. struct rpc_reply_lookup
  310. {
  311. struct nfs_reply_header rh;
  312. struct LOOKUP3resok lookup;
  313. };
  314. struct rpc_reply_write
  315. {
  316. struct nfs_reply_header rh;
  317. struct WRITE3resok write; /* Variable length */
  318. };
  319. struct rpc_reply_read
  320. {
  321. struct nfs_reply_header rh;
  322. struct READ3resok read; /* Variable length */
  323. };
  324. #define SIZEOF_rpc_reply_read(n) \
  325. (sizeof(struct nfs_reply_header) + SIZEOF_READ3resok(n))
  326. struct rpc_reply_remove
  327. {
  328. struct nfs_reply_header rh;
  329. struct REMOVE3resok remove;
  330. };
  331. struct rpc_reply_rename
  332. {
  333. struct nfs_reply_header rh;
  334. struct RENAME3resok rename;
  335. };
  336. struct rpc_reply_mkdir
  337. {
  338. struct nfs_reply_header rh;
  339. struct MKDIR3resok mkdir;
  340. };
  341. struct rpc_reply_rmdir
  342. {
  343. struct nfs_reply_header rh;
  344. struct RMDIR3resok rmdir;
  345. };
  346. struct rpc_reply_readdir
  347. {
  348. struct nfs_reply_header rh;
  349. struct READDIR3resok readdir;
  350. };
  351. #define SIZEOF_rpc_reply_readdir(n) \
  352. (sizeof(struct nfs_reply_header) + SIZEOF_READDIR3resok(n))
  353. struct rpc_reply_fsinfo
  354. {
  355. struct nfs_reply_header rh;
  356. struct nfsv3_fsinfo fsinfo;
  357. };
  358. struct rpc_reply_fsstat
  359. {
  360. struct nfs_reply_header rh;
  361. struct nfs_statfs fsstat;
  362. };
  363. struct rpc_reply_getattr
  364. {
  365. struct nfs_reply_header rh;
  366. struct nfs_fattr attr;
  367. };
  368. struct rpc_reply_setattr
  369. {
  370. struct nfs_reply_header rh;
  371. struct SETATTR3resok setattr;
  372. };
  373. struct rpcclnt
  374. {
  375. nfsfh_t rc_fh; /* File handle of the root directory */
  376. uint8_t rc_fhsize; /* File size of the root directory */
  377. FAR char *rc_path; /* Server's path of the mounted directory */
  378. FAR struct sockaddr_storage *rc_name;
  379. struct socket rc_so; /* RPC socket */
  380. uint8_t rc_sotype; /* Type of socket */
  381. uint8_t rc_timeo; /* Timeout value (in deciseconds) */
  382. uint8_t rc_retry; /* Max retries */
  383. uint32_t rc_xid; /* Transaction id */
  384. };
  385. /****************************************************************************
  386. * Public Function Prototypes
  387. ****************************************************************************/
  388. void rpcclnt_init(void);
  389. int rpcclnt_connect(FAR struct rpcclnt *rpc);
  390. void rpcclnt_disconnect(FAR struct rpcclnt *rpc);
  391. int rpcclnt_request(FAR struct rpcclnt *rpc, int procnum, int prog,
  392. int version, FAR void *request, size_t reqlen,
  393. FAR void *response, size_t resplen);
  394. #endif /* __FS_NFS_RPC_H */