1#include <stdio.h>2#include <stdlib.h>34#include "shell.h"5#include "xtimer.h"67#include "9p.h"8#include "9pfs.h"9#include "vfs.h"1011#include "net/af.h"12#include "net/gnrc/ipv6.h"13#include "net/gnrc/tcp.h"1415#ifndef NINEPFS_HOST16 #error "NINEPFS_HOST was not defined."17#endif1819#ifndef NINEPFS_PORT20 #error "NINEPFS_PORT was not defined."21#endif2223/**24 * GNRC transmission control block.25 */26static gnrc_tcp_tcb_t tcb;2728/**29 * 9P connection context.30 */31static _9pfs fs;3233/* import "ifconfig" shell command, used for printing addresses */34extern int _netif_config(int argc, char **argv);3536static ssize_t37recvfn(void *buf, size_t count)38{39 return gnrc_tcp_recv(&tcb, buf,40 count, GNRC_TCP_CONNECTION_TIMEOUT_DURATION);41}4243static ssize_t44sendfn(void *buf, size_t count)45{46 return gnrc_tcp_send(&tcb, buf,47 count, GNRC_TCP_CONNECTION_TIMEOUT_DURATION);48}4950int51main(void)52{53 int ret;54 ipv6_addr_t remote;55 char line_buf[SHELL_DEFAULT_BUFSIZE];56 vfs_mount_t mountp;5758 if (!ipv6_addr_from_str(&remote, NINEPFS_HOST)) {59 fprintf(stderr, "Address '%s' is malformed\n", NINEPFS_HOST);60 return EXIT_FAILURE;61 }6263 mountp.mount_point = "/9pfs";64 mountp.fs = &_9p_file_system;65 mountp.private_data = &fs;6667 puts("Waiting for address autoconfiguration...");68 xtimer_sleep(3);6970 puts("Configured network interfaces:");71 _netif_config(0, NULL);7273 gnrc_tcp_tcb_init(&tcb);74 if ((ret = gnrc_tcp_open_active(&tcb, AF_INET6,75 (uint8_t *)&remote, NINEPFS_PORT, 0))) {76 fprintf(stderr, "Couldn't open TCP connection\n");77 return EXIT_FAILURE;78 }7980 fs.uname = "glenda";81 fs.aname = NULL;8283 _9pinit(&fs.ctx, recvfn, sendfn);8485 if ((ret = vfs_mount(&mountp))) {86 fprintf(stderr, "vfs_mount failed, err code: %d\n", ret);87 return EXIT_FAILURE;88 }8990 puts("All up, running the shell now");91 shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE);9293 if ((ret = vfs_umount(&mountp))) {94 fprintf(stderr, "vfs_unmount failed, err code: %d\n", ret);95 return EXIT_FAILURE;96 }9798 gnrc_tcp_close(&tcb);99 return EXIT_SUCCESS;100}