00001
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include <stdio.h>
00037 #include <string.h>
00038 #include <stdlib.h>
00039
00040 #include <l4/sys/types.h>
00041 #include <l4/env/errno.h>
00042 #include <l4/sys/syscalls.h>
00043 #include <l4/log/l4log.h>
00044 #include <l4/l4rm/l4rm.h>
00045 #include <l4/util/util.h>
00046 #include <l4/env/env.h>
00047 #include <l4/names/libnames.h>
00048 #include <l4/generic_fprov/generic_fprov-server.h>
00049
00050
00051 #include <l4/dm_mem/dm_mem.h>
00052 #include <l4/thread/thread.h>
00053
00054
00055 #include <l4/generic_io/libio.h>
00056 #include <l4/sys/kdebug.h>
00057
00058
00059 #if 0
00060 #define TIMEOUT 5
00061 int rexmtval = TIMEOUT;
00062 int maxtimeout = 5 * TIMEOUT;
00063 #endif
00064
00065 static char tftp_stack[2*L4_PAGESIZE];
00066 static struct in_addr peeraddr;
00067
00068 extern int disp_filesizebarrier;
00069 extern int disp_filesize;
00070 extern char tftp_orename[16];
00071
00072
00073
00074 long l4fprov_file_open_component (CORBA_Object _dice_corba_obj,
00075 const char* fname,
00076 const l4_threadid_t *dm,
00077 unsigned long flags,
00078 l4dm_dataspace_t *ds,
00079 l4_size_t *size,
00080 CORBA_Server_Environment *_dice_corba_env)
00081 {
00082 int read_size;
00083 int error;
00084 char *addr;
00085 char buf[L4DM_DS_NAME_MAX_LEN];
00086 const char *ptr;
00087
00088 if (!netboot_open((char*)fname)) {
00089
00090 printf("File not found: \"%s\"\n", fname);
00091 return -L4_ENOTFOUND;
00092 }
00093
00094
00095
00096 *size = netboot_filemax;
00097
00098 ptr = strrchr(fname, '/');
00099 if (!ptr)
00100 ptr=fname;
00101 else
00102 ptr++;
00103 snprintf(buf, L4DM_DS_NAME_MAX_LEN, "tftp image: %s", ptr);
00104
00105 if (!(addr = l4dm_mem_ds_allocate_named_dsm(*size, flags, buf, *dm,
00106 (l4dm_dataspace_t *)ds))) {
00107 printf("Allocating dataspace of size %d failed\n", *size);
00108 netboot_close();
00109 return -L4_ENOMEM;
00110 }
00111
00112 printf("Loading %s [%dkB]\n", fname, (*size + 1023) / 1024);
00113
00114
00115 disp_filesizebarrier = disp_filesize = 0;
00116
00117 read_size = netboot_read((char*) addr, *size);
00118
00119 netboot_close();
00120
00121
00122 if ((error = l4rm_detach((void *)addr))) {
00123 printf("Error %d detaching dataspace\n", error);
00124 l4dm_close((l4dm_dataspace_t*)ds);
00125 return -L4_ENOMEM;
00126 }
00127
00128 if (!read_size) {
00129 printf("Error reading file %s\n"
00130 "TFTP error was %d (%s)\n",
00131 fname,
00132 netboot_errnum, err_list[netboot_errnum]);
00133 l4dm_close((l4dm_dataspace_t*)ds);
00134 return -L4_EIO;
00135 }
00136
00137
00138 if ((error = l4dm_transfer((l4dm_dataspace_t *)ds,*_dice_corba_obj))) {
00139 printf("Error transfering dataspace ownership: %s (%d)\n",
00140 l4env_errstr(error), error);
00141 l4dm_close((l4dm_dataspace_t*)ds);
00142 return -L4_EINVAL;
00143 }
00144
00145 return 0;
00146 }
00147
00148
00149 void tftp_client(void *unused)
00150 {
00151 l4_addr_t netbuf, gunzipbuf;
00152
00153
00154 netbuf = (l4_addr_t)
00155 l4dm_mem_allocate_named(NETBUF_SIZE,0,"tftp netbuff");
00156 if (netbuf == 0)
00157 {
00158 printf("Allocate netbuff failed\n");
00159 exit(-1);
00160 }
00161
00162
00163 gunzipbuf = (l4_addr_t)
00164 l4dm_mem_allocate_named(GUNZIP_SIZE,0,"tftp gunzip");
00165 if (gunzipbuf == 0)
00166 {
00167 printf("Allocate gunzip buffer failed\n");
00168 exit(-1);
00169 }
00170
00171 if (!names_register("TFTP"))
00172 {
00173 printf("failed to register at name server\n");
00174 exit(-1);
00175 }
00176
00177 l4fprov_file_server_loop(NULL);
00178 }
00179
00180
00181 void tftp_init(char *host) {
00182 l4io_info_t *io_info_addr = (l4io_info_t*)-1;
00183
00184
00185 if (!inet_aton(host, &tftp_server_addr))
00186 printf("Invalid TFTP server address: %s!\n", host);
00187 else
00188 printf("Using TFTP server %s (0x%08x)\n", host,
00189 tftp_server_addr.s_addr);
00190
00191
00192 if (l4io_init(&io_info_addr, L4IO_DRV_INVALID))
00193 enter_kdebug("Couldn't connect to L4 IO server!");
00194
00195 #if 0
00196 strncpy(tftp_orename, host, sizeof(tftp_orename));
00197 tftp_orename[sizeof(tftp_orename)-1] = 0;
00198 #endif
00199
00200 if ((ret = l4thread_create_long(L4THREAD_INVALID_ID, tftp_client,
00201 ".tftp_client",
00202 (unsigned)tftp_stack
00203 + sizeof(tftp_stack),
00204 sizeof(tftp_stack),
00205 L4THREAD_DEFAULT_PRIO, 0,
00206 L4THREAD_CREATE_ASYNC)) < 0) {
00207 Panic("Error %d creating tftp_client thread", ret);
00208 }
00209 }
00210
00211
00212 void tftp_get(char *file) {
00213 int error;
00214 l4_threadid_t tftp_id;
00215 l4_threadid_t dm_id;
00216 l4dm_dataspace_t ds;
00217 void *addr;
00218 l4_size_t size;
00219 CORBA_Environment _env = dice_default_environment;
00220
00221 if (!names_waitfor_name("TFTP", &tftp_id, 10000)) {
00222 printf("TFTP not found\n");
00223 return -1;
00224 }
00225
00226 dm_id = l4env_get_default_dsm();
00227 if (l4_is_invalid_id(dm_id)) {
00228 printf("No dataspace manager found\n");
00229 return -1;
00230 }
00231
00232 if ((error = l4fprov_file_open_call(&tftp_id, file, &dm_id,
00233 0, &ds, &size, &_env))) {
00234 printf("Error opening file from tftp\n");
00235 return -1;
00236 }
00237
00238 if ((error = l4rm_attach(&ds, size, 0, L4DM_RO | L4RM_MAP, &addr))) {
00239 printf("Error %d attaching dataspace\n", error);
00240 return -L4_ENOMEM;
00241 }
00242 }
00243
00244
00245 void tftp_put(char *file) {
00247 }
00248
00249
00250 void tftp_mode(enum TFTP_mode unused) {
00251
00252 }