/**************************************************************************
RPC_LOOKUP - Lookup RPC Port numbers
**************************************************************************/
-static void rpc_req(int rpc_prog, int rpc_proc, uint32_t *data, int datalen)
+static struct rpc_t *rpc_req_prep(void)
+{
+ return (struct rpc_t *)(net_tx_packet + net_eth_hdr_size() +
+ IP_UDP_HDR_SIZE);
+}
+
+static void rpc_req(int rpc_prog, int rpc_proc, struct rpc_t *rpc_pkt,
+ int datalen)
{
- struct rpc_t rpc_pkt;
unsigned long id;
- uint32_t *p;
int pktlen;
int sport;
id = ++rpc_id;
- rpc_pkt.u.call.id = htonl(id);
- rpc_pkt.u.call.type = htonl(MSG_CALL);
- rpc_pkt.u.call.rpcvers = htonl(2); /* use RPC version 2 */
- rpc_pkt.u.call.prog = htonl(rpc_prog);
+ rpc_pkt->u.call.id = htonl(id);
+ rpc_pkt->u.call.type = htonl(MSG_CALL);
+ rpc_pkt->u.call.rpcvers = htonl(2); /* use RPC version 2 */
+ rpc_pkt->u.call.prog = htonl(rpc_prog);
switch (rpc_prog) {
case PROG_NFS:
if (supported_nfs_versions & NFSV2_FLAG)
- rpc_pkt.u.call.vers = htonl(2); /* NFS v2 */
+ rpc_pkt->u.call.vers = htonl(2); /* NFS v2 */
else /* NFSV3_FLAG */
- rpc_pkt.u.call.vers = htonl(3); /* NFS v3 */
+ rpc_pkt->u.call.vers = htonl(3); /* NFS v3 */
break;
case PROG_PORTMAP:
case PROG_MOUNT:
default:
- rpc_pkt.u.call.vers = htonl(2); /* portmapper is version 2 */
+ /* portmapper is version 2 */
+ rpc_pkt->u.call.vers = htonl(2);
}
- rpc_pkt.u.call.proc = htonl(rpc_proc);
- p = (uint32_t *)&(rpc_pkt.u.call.data);
+ rpc_pkt->u.call.proc = htonl(rpc_proc);
- if (datalen)
- memcpy((char *)p, (char *)data, datalen*sizeof(uint32_t));
-
- pktlen = (char *)p + datalen * sizeof(uint32_t) - (char *)&rpc_pkt;
-
- memcpy((char *)net_tx_packet + net_eth_hdr_size() + IP_UDP_HDR_SIZE,
- &rpc_pkt.u.data[0], pktlen);
+ pktlen = ((char *)&rpc_pkt->u.call.data - (char *)&rpc_pkt) +
+ datalen * sizeof(uint32_t);
if (rpc_prog == PROG_PORTMAP)
sport = SUNRPC_PORT;
**************************************************************************/
static void rpc_lookup_req(int prog, int ver)
{
- uint32_t data[16];
+ uint32_t *data;
+ struct rpc_t *rpc_pkt = rpc_req_prep();
+ data = rpc_pkt->u.call.data;
data[0] = 0; data[1] = 0; /* auth credential */
data[2] = 0; data[3] = 0; /* auth verifier */
data[4] = htonl(prog);
data[5] = htonl(ver);
data[6] = htonl(17); /* IP_UDP */
data[7] = 0;
- rpc_req(PROG_PORTMAP, PORTMAP_GETPORT, data, 8);
+ rpc_req(PROG_PORTMAP, PORTMAP_GETPORT, rpc_pkt, 8);
}
/**************************************************************************
**************************************************************************/
static void nfs_mount_req(char *path)
{
- uint32_t data[1024];
uint32_t *p;
int len;
int pathlen;
+ struct rpc_t *rpc_pkt = rpc_req_prep();
pathlen = strlen(path);
- p = &(data[0]);
+ p = rpc_pkt->u.call.data;
p = rpc_add_credentials(p);
*p++ = htonl(pathlen);
memcpy(p, path, pathlen);
p += (pathlen + 3) / 4;
- len = (uint32_t *)p - (uint32_t *)&(data[0]);
+ len = (uint32_t *)p - (uint32_t *)&(rpc_pkt->u.call.data);
- rpc_req(PROG_MOUNT, MOUNT_ADDENTRY, data, len);
+ rpc_req(PROG_MOUNT, MOUNT_ADDENTRY, rpc_pkt, len);
}
/**************************************************************************
**************************************************************************/
static void nfs_umountall_req(void)
{
- uint32_t data[1024];
uint32_t *p;
int len;
+ struct rpc_t *rpc_pkt = rpc_req_prep();
if ((nfs_server_mount_port == -1) || (!fs_mounted))
/* Nothing mounted, nothing to umount */
return;
- p = &(data[0]);
+ p = rpc_pkt->u.call.data;
p = rpc_add_credentials(p);
- len = (uint32_t *)p - (uint32_t *)&(data[0]);
+ len = (uint32_t *)p - (uint32_t *)&(rpc_pkt->u.call.data);
- rpc_req(PROG_MOUNT, MOUNT_UMOUNTALL, data, len);
+ rpc_req(PROG_MOUNT, MOUNT_UMOUNTALL, rpc_pkt, len);
}
/***************************************************************************
**************************************************************************/
static void nfs_readlink_req(void)
{
- uint32_t data[1024];
uint32_t *p;
int len;
+ struct rpc_t *rpc_pkt = rpc_req_prep();
- p = &(data[0]);
+ p = rpc_pkt->u.call.data;
p = rpc_add_credentials(p);
if (supported_nfs_versions & NFSV2_FLAG) {
p += (filefh3_length / 4);
}
- len = (uint32_t *)p - (uint32_t *)&(data[0]);
+ len = (uint32_t *)p - (uint32_t *)&(rpc_pkt->u.call.data);
- rpc_req(PROG_NFS, NFS_READLINK, data, len);
+ rpc_req(PROG_NFS, NFS_READLINK, rpc_pkt, len);
}
/**************************************************************************
**************************************************************************/
static void nfs_lookup_req(char *fname)
{
- uint32_t data[1024];
uint32_t *p;
int len;
int fnamelen;
+ struct rpc_t *rpc_pkt = rpc_req_prep();
fnamelen = strlen(fname);
- p = &(data[0]);
+ p = rpc_pkt->u.call.data;
p = rpc_add_credentials(p);
if (supported_nfs_versions & NFSV2_FLAG) {
memcpy(p, fname, fnamelen);
p += (fnamelen + 3) / 4;
- len = (uint32_t *)p - (uint32_t *)&(data[0]);
+ len = (uint32_t *)p - (uint32_t *)&(rpc_pkt->u.call.data);
- rpc_req(PROG_NFS, NFS_LOOKUP, data, len);
+ rpc_req(PROG_NFS, NFS_LOOKUP, rpc_pkt, len);
} else { /* NFSV3_FLAG */
*p++ = htonl(NFS_FHSIZE); /* Dir handle length */
memcpy(p, dirfh, NFS_FHSIZE);
memcpy(p, fname, fnamelen);
p += (fnamelen + 3) / 4;
- len = (uint32_t *)p - (uint32_t *)&(data[0]);
+ len = (uint32_t *)p - (uint32_t *)&(rpc_pkt->u.call.data);
- rpc_req(PROG_NFS, NFS3PROC_LOOKUP, data, len);
+ rpc_req(PROG_NFS, NFS3PROC_LOOKUP, rpc_pkt, len);
}
}
**************************************************************************/
static void nfs_read_req(int offset, int readlen)
{
- uint32_t data[1024];
uint32_t *p;
int len;
+ struct rpc_t *rpc_pkt = rpc_req_prep();
- p = &(data[0]);
+ p = rpc_pkt->u.call.data;
p = rpc_add_credentials(p);
if (supported_nfs_versions & NFSV2_FLAG) {
*p++ = 0;
}
- len = (uint32_t *)p - (uint32_t *)&(data[0]);
+ len = (uint32_t *)p - (uint32_t *)&(rpc_pkt->u.call.data);
- rpc_req(PROG_NFS, NFS_READ, data, len);
+ rpc_req(PROG_NFS, NFS_READ, rpc_pkt, len);
}
/**************************************************************************
return -NFS_RPC_PROG_MISMATCH;
case 4:
default:
- printf("*** ERROR: NFS version not supported: Requested: V%d, accepted: min V%d - max V%d\n",
- (supported_nfs_versions & NFSV2_FLAG) ?
+ puts("*** ERROR: NFS version not supported");
+ debug(": Requested: V%d, accepted: min V%d - max V%d\n",
+ (supported_nfs_versions & NFSV2_FLAG) ?
2 : 3,
- ntohl(rpc_pkt.u.reply.data[0]),
- ntohl(rpc_pkt.u.reply.data[1]));
+ ntohl(rpc_pkt.u.reply.data[0]),
+ ntohl(rpc_pkt.u.reply.data[1]));
+ puts("\n");
}
break;
case NFS_RPC_PROG_UNAVAIL:
case NFS_RPC_GARBAGE_ARGS:
case NFS_RPC_SYSTEM_ERR:
default: /* Unknown error on 'accept state' flag */
- printf("*** ERROR: accept state error (%d)\n",
- ntohl(rpc_pkt.u.reply.astatus));
+ debug("*** ERROR: accept state error (%d)\n",
+ ntohl(rpc_pkt.u.reply.astatus));
break;
}
return -1;
if (reply == -NFS_RPC_DROP) {
break;
} else if (reply == -NFS_RPC_ERR) {
- puts("*** ERROR: Cannot umount\n");
+ debug("*** ERROR: Cannot umount\n");
net_set_state(NETLOOP_FAIL);
} else {
puts("\ndone\n");
if (!rlen)
nfs_download_state = NETLOOP_SUCCESS;
if (rlen < 0)
- printf("NFS READ error (%d)\n", rlen);
+ debug("NFS READ error (%d)\n", rlen);
nfs_state = STATE_UMOUNT_REQ;
nfs_send();
}
if (nfs_path == NULL) {
net_set_state(NETLOOP_FAIL);
- puts("*** ERROR: Fail allocate memory\n");
+ debug("*** ERROR: Fail allocate memory\n");
return;
}
(net_ip.s_addr >> 16) & 0xFF,
(net_ip.s_addr >> 24) & 0xFF);
- printf("*** Warning: no boot file name; using '%s'\n",
- nfs_path);
+ debug("*** Warning: no boot file name; using '%s'\n",
+ nfs_path);
} else {
char *p = net_boot_file_name;
nfs_filename = basename(nfs_path);
nfs_path = dirname(nfs_path);
- printf("Using %s device\n", eth_get_name());
+ debug("Using %s device\n", eth_get_name());
- printf("File transfer via NFS from server %pI4; our IP address is %pI4",
- &nfs_server_ip, &net_ip);
+ debug("File transfer via NFS from server %pI4; our IP address is %pI4",
+ &nfs_server_ip, &net_ip);
/* Check if we need to send across this subnet */
if (net_gateway.s_addr && net_netmask.s_addr) {
our_net.s_addr = net_ip.s_addr & net_netmask.s_addr;
server_net.s_addr = net_server_ip.s_addr & net_netmask.s_addr;
if (our_net.s_addr != server_net.s_addr)
- printf("; sending through gateway %pI4",
- &net_gateway);
+ debug("; sending through gateway %pI4",
+ &net_gateway);
}
- printf("\nFilename '%s/%s'.", nfs_path, nfs_filename);
+ debug("\nFilename '%s/%s'.", nfs_path, nfs_filename);
if (net_boot_file_expected_size_in_blocks) {
- printf(" Size is 0x%x Bytes = ",
- net_boot_file_expected_size_in_blocks << 9);
+ debug(" Size is 0x%x Bytes = ",
+ net_boot_file_expected_size_in_blocks << 9);
print_size(net_boot_file_expected_size_in_blocks << 9, "");
}
- printf("\nLoad address: 0x%lx\n"
- "Loading: *\b", load_addr);
+ debug("\nLoad address: 0x%lx\nLoading: *\b", load_addr);
net_set_timeout_handler(nfs_timeout, nfs_timeout_handler);
net_set_udp_handler(nfs_handler);