From c9e808d6385306f37972a4d1475bbebea51d6dd4 Mon Sep 17 00:00:00 2001 From: adamdunkels Date: Sat, 17 Jun 2006 22:41:10 +0000 Subject: [PATCH] Import of the contiki-2.x development code from the SICS internal CVS server --- Makefile.include | 128 ++ apps/about/Makefile.about | 2 + apps/about/about-dsc.c | 74 + apps/about/about-dsc.h | 42 + apps/about/about.c | 127 ++ apps/calc/Makefile.calc | 2 + apps/calc/calc-dsc.c | 74 + apps/calc/calc-dsc.h | 42 + apps/calc/calc.c | 293 +++ apps/cmdd/Makefile.cmdd | 2 + apps/cmdd/cmdd.c | 168 ++ apps/cmdd/cmdd.h | 10 + apps/dhcp/Makefile.dhcp | 2 + apps/dhcp/dhcp-dsc.c | 74 + apps/dhcp/dhcp-dsc.h | 42 + apps/dhcp/dhcp.c | 153 ++ apps/dhcp/dhcp.h | 0 apps/directory/Makefile.directory | 2 + apps/directory/directory-dsc.c | 74 + apps/directory/directory-dsc.h | 42 + apps/directory/directory.c | 308 +++ apps/editor/Makefile.editor | 2 + apps/editor/editor-dsc.c | 74 + apps/editor/editor-dsc.h | 42 + apps/editor/editor.c | 338 +++ apps/email/Makefile.email | 3 + apps/email/email-dsc.c | 74 + apps/email/email-dsc.h | 42 + apps/email/email.c | 335 +++ apps/email/email.h | 40 + apps/email/smtp-socket.c | 241 +++ apps/email/smtp-strings | 11 + apps/email/smtp-strings.c | 70 + apps/email/smtp-strings.h | 46 + apps/email/smtp.h | 68 + apps/ftp/Makefile.ftp | 2 + apps/ftp/ftp-dsc.c | 74 + apps/ftp/ftp-dsc.h | 42 + apps/ftp/ftp.c | 577 +++++ apps/ftp/ftpc.c | 506 +++++ apps/ftp/ftpc.h | 68 + apps/irc/Makefile.irc | 3 + apps/irc/irc-dsc.c | 74 + apps/irc/irc-dsc.h | 42 + apps/irc/irc.c | 293 +++ apps/irc/ircc-strings | 17 + apps/irc/ircc-strings.c | 51 + apps/irc/ircc-strings.h | 17 + apps/irc/ircc.c | 531 +++++ apps/irc/ircc.h | 79 + apps/netconf/Makefile.netconf | 2 + apps/netconf/netconf-dsc.c | 74 + apps/netconf/netconf-dsc.h | 42 + apps/netconf/netconf.c | 246 +++ apps/process-list/Makefile.process-list | 2 + apps/process-list/process-list-dsc.c | 74 + apps/process-list/process-list-dsc.h | 42 + apps/process-list/process-list.c | 194 ++ apps/program-handler/Makefile.program-handler | 2 + apps/program-handler/program-handler.c | 385 ++++ apps/program-handler/program-handler.h | 53 + apps/shell/Makefile.shell | 2 + apps/shell/shell-dsc.c | 74 + apps/shell/shell-dsc.h | 42 + apps/shell/shell-gui.c | 144 ++ apps/shell/shell.c | 284 +++ apps/shell/shell.h | 114 + apps/telnet/Makefile.telnet | 2 + apps/telnet/simpletelnet.c | 310 +++ apps/telnet/simpletelnet.h | 40 + apps/telnet/telnet-dsc.c | 74 + apps/telnet/telnet-dsc.h | 42 + apps/telnet/telnet.c | 152 ++ apps/telnet/telnet.h | 59 + apps/telnetd/Makefile.telnetd | 2 + apps/telnetd/telnetd-dsc.c | 74 + apps/telnetd/telnetd-dsc.h | 42 + apps/telnetd/telnetd-gui.c | 98 + apps/telnetd/telnetd.c | 399 ++++ apps/telnetd/telnetd.h | 49 + apps/webbrowser/Makefile.webbrowser | 3 + apps/webbrowser/html-strings | 36 + apps/webbrowser/html-strings.c | 108 + apps/webbrowser/html-strings.h | 36 + apps/webbrowser/htmlparser.c | 852 ++++++++ apps/webbrowser/htmlparser.h | 78 + apps/webbrowser/http-strings | 32 + apps/webbrowser/http-strings.c | 102 + apps/webbrowser/http-strings.h | 34 + apps/webbrowser/http-user-agent-string.c | 37 + apps/webbrowser/http-user-agent-string.h | 35 + apps/webbrowser/webclient.c | 441 ++++ apps/webbrowser/webclient.h | 66 + apps/webbrowser/www-dsc.c | 74 + apps/webbrowser/www-dsc.h | 42 + apps/webbrowser/www.c | 950 +++++++++ apps/webbrowser/www.h | 40 + apps/webserver/Makefile.webserver | 3 + apps/webserver/http-strings.c | 102 + apps/webserver/http-strings.h | 34 + apps/webserver/httpd-cfs.c | 235 ++ apps/webserver/httpd-cfs.h | 57 + apps/webserver/httpd-cgi.c | 245 +++ apps/webserver/httpd-cgi.h | 57 + apps/webserver/httpd-fs.c | 129 ++ apps/webserver/httpd-fs.h | 59 + apps/webserver/httpd-fs/404.html | 8 + apps/webserver/httpd-fs/files.shtml | 24 + apps/webserver/httpd-fs/footer.html | 2 + apps/webserver/httpd-fs/header.html | 28 + apps/webserver/httpd-fs/index.html | 41 + apps/webserver/httpd-fs/processes.shtml | 5 + apps/webserver/httpd-fs/style.css | 239 +++ apps/webserver/httpd-fs/tcp.shtml | 5 + apps/webserver/httpd-fs/upload.html | 8 + apps/webserver/httpd-fsdata.c | 875 ++++++++ apps/webserver/httpd-fsdata.h | 64 + apps/webserver/httpd-socket.c | 193 ++ apps/webserver/httpd.c | 323 +++ apps/webserver/httpd.h | 64 + apps/webserver/webserver-dsc.c | 74 + apps/webserver/webserver-dsc.h | 42 + apps/webserver/webserver-nogui.c | 70 + apps/webserver/webserver-nogui.h | 42 + apps/webserver/webserver.c | 126 ++ apps/webserver/webserver.h | 42 + core/cfs/cfs-eeprom.c | 150 ++ core/cfs/cfs-eeprom.h | 43 + core/cfs/cfs-posix.c | 172 ++ core/cfs/cfs-posix.h | 42 + core/cfs/cfs-ram.c | 165 ++ core/cfs/cfs-ram.h | 43 + core/cfs/cfs-service.h | 76 + core/cfs/cfs.c | 76 + core/cfs/cfs.h | 204 ++ core/contiki-lib.h | 44 + core/contiki-net.h | 55 + core/contiki-version.h | 42 + core/contiki.h | 55 + core/ctk/ctk-conio-service.c | 566 +++++ core/ctk/ctk-conio.c | 521 +++++ core/ctk/ctk-conio.h | 66 + core/ctk/ctk-draw-service.h | 73 + core/ctk/ctk-draw.c | 173 ++ core/ctk/ctk-draw.h | 335 +++ core/ctk/ctk-graphic-draw.h | 96 + core/ctk/ctk-graphic.c | 809 +++++++ core/ctk/ctk-mouse.c | 323 +++ core/ctk/ctk-mouse.h | 70 + core/ctk/ctk-term-ascii.h | 123 ++ core/ctk/ctk-term-in.c | 381 ++++ core/ctk/ctk-term-int.h | 99 + core/ctk/ctk-term-out.c | 350 +++ core/ctk/ctk-term-out.h | 42 + core/ctk/ctk-term.c | 1025 +++++++++ core/ctk/ctk-term.h | 46 + core/ctk/ctk-termarch.h | 58 + core/ctk/ctk-termserial.c | 110 + core/ctk/ctk-termserial.h | 38 + core/ctk/ctk-termtelnet.c | 655 ++++++ core/ctk/ctk-termtelnet.h | 38 + core/ctk/ctk-vncarch.h | 68 + core/ctk/ctk-vncfont.c | 1205 +++++++++++ core/ctk/ctk-vncfont.h | 46 + core/ctk/ctk-vncserver-service.c | 1143 ++++++++++ core/ctk/ctk-vncserver.c | 1096 ++++++++++ core/ctk/ctk-vncserver.h | 40 + core/ctk/ctk.c | 1874 ++++++++++++++++ core/ctk/ctk.h | 972 +++++++++ core/ctk/vnc-out.c | 978 +++++++++ core/ctk/vnc-out.h | 92 + core/ctk/vnc-server.c | 487 +++++ core/ctk/vnc-server.h | 296 +++ core/dev/cc2420.c | 679 ++++++ core/dev/cc2420.h | 135 ++ core/dev/cc2420_const.h | 158 ++ core/dev/cc2420_send_ip.c | 58 + core/dev/cc2420_send_uaodv.c | 80 + core/dev/cs8900a.c | 314 +++ core/dev/cs8900a.h | 44 + core/dev/ds2411.c | 229 ++ core/dev/ds2411.h | 42 + core/dev/eeprom.h | 105 + core/dev/leds.c | 135 ++ core/dev/leds.h | 94 + core/dev/radio.h | 76 + core/dev/rom.h | 41 + core/dev/serial.c | 101 + core/dev/serial.h | 77 + core/dev/slip.c | 291 +++ core/dev/slip.h | 76 + core/dev/spi.h | 213 ++ core/dev/watchdog.h | 40 + core/dev/xmem.h | 43 + core/lib/crc16.c | 67 + core/lib/crc16.h | 79 + core/lib/crtk.c | 152 ++ core/lib/crtk.h | 150 ++ core/lib/ctk-filedialog.c | 174 ++ core/lib/ctk-filedialog.h | 51 + core/lib/ctk-textedit.c | 181 ++ core/lib/ctk-textedit.h | 73 + core/lib/ctk-textentry-checkbox.c | 63 + core/lib/ctk-textentry-checkbox.h | 41 + core/lib/ctk-textentry-cmdline.c | 52 + core/lib/ctk-textentry-cmdline.h | 41 + core/lib/ctk-textentry-multiline.c | 94 + core/lib/ctk-textentry-multiline.h | 41 + core/lib/libconio.c | 190 ++ core/lib/libconio.h | 85 + core/lib/list.c | 306 +++ core/lib/list.h | 115 + core/lib/malloc.c | 439 ++++ core/lib/malloc.h | 87 + core/lib/malloc_compact.c | 133 ++ core/lib/me.c | 117 + core/lib/me.h | 76 + core/lib/me_tabs.c | 122 ++ core/lib/me_tabs.h | 41 + core/lib/memb.c | 104 + core/lib/memb.h | 149 ++ core/lib/mmem.c | 156 ++ core/lib/mmem.h | 94 + core/lib/petsciiconv.c | 116 + core/lib/petsciiconv.h | 79 + core/lib/rand.c | 59 + core/lib/rand.h | 59 + core/lib/random.c | 72 + core/lib/random.h | 51 + core/lib/realloc.c | 160 ++ core/lib/sensors.c | 194 ++ core/lib/sensors.h | 85 + core/lib/strncasecmp.c | 70 + core/loader/dlloader.c | 69 + core/loader/dlloader.h | 38 + core/loader/elfloader-arch.h | 137 ++ core/loader/elfloader-avr.c | 214 ++ core/loader/elfloader-msp430.c | 100 + core/loader/elfloader-stub.c | 62 + core/loader/elfloader-tmp.c | 493 +++++ core/loader/elfloader-tmp.h | 170 ++ core/loader/elfloader.c | 491 +++++ core/loader/elfloader.h | 55 + core/loader/symbols.h | 43 + core/loader/symtab.c | 52 + core/loader/symtab.h | 38 + core/net/adhoc-service.h | 54 + core/net/ahdlc.c | 381 ++++ core/net/ahdlc.h | 57 + core/net/dhcpc.c | 421 ++++ core/net/dhcpc.h | 63 + core/net/hc-service.c | 68 + core/net/hc-service.h | 45 + core/net/hc.c | 215 ++ core/net/hc.h | 49 + core/net/ipcp.c | 462 ++++ core/net/ipcp.h | 95 + core/net/lcp.c | 463 ++++ core/net/lcp.h | 96 + core/net/packet-service.h | 46 + core/net/pap.c | 195 ++ core/net/pap.h | 83 + core/net/ppp-service.c | 91 + core/net/ppp.c | 440 ++++ core/net/ppp.h | 132 ++ core/net/ppp_process.c | 234 ++ core/net/ppp_process.h | 3 + core/net/psock.c | 336 +++ core/net/psock.h | 388 ++++ core/net/resolv.c | 499 +++++ core/net/resolv.h | 62 + core/net/slipdev.c | 208 ++ core/net/slipdev.h | 88 + core/net/tcpdump.c | 287 +++ core/net/tcpdump.h | 40 + core/net/tcpip.c | 411 ++++ core/net/tcpip.h | 309 +++ core/net/uaodv-def.h | 127 ++ core/net/uaodv-rt.c | 132 ++ core/net/uaodv-rt.h | 60 + core/net/uaodv.c | 495 +++++ core/net/uaodv.h | 51 + core/net/uip-fw-service.c | 62 + core/net/uip-fw-service.h | 43 + core/net/uip-fw.c | 535 +++++ core/net/uip-fw.h | 176 ++ core/net/uip-neighbor.c | 158 ++ core/net/uip-neighbor.h | 61 + core/net/uip-split.c | 136 ++ core/net/uip-split.h | 96 + core/net/uip.c | 1889 +++++++++++++++++ core/net/uip.h | 1602 ++++++++++++++ core/net/uip_arch.h | 138 ++ core/net/uip_arp.c | 427 ++++ core/net/uip_arp.h | 145 ++ core/net/uipbuf.c | 134 ++ core/net/uipbuf.h | 182 ++ core/net/uiplib.c | 74 + core/net/uiplib.h | 71 + core/net/uipopt.h | 546 +++++ core/sys/arg.c | 133 ++ core/sys/arg.h | 43 + core/sys/autostart.c | 63 + core/sys/autostart.h | 62 + core/sys/cc.h | 111 + core/sys/clock.h | 97 + core/sys/dsc.h | 128 ++ core/sys/etimer.c | 260 +++ core/sys/etimer.h | 242 +++ core/sys/lc-addrlabels.h | 82 + core/sys/lc-switch.h | 76 + core/sys/lc.h | 131 ++ core/sys/loader.h | 132 ++ core/sys/log.h | 46 + core/sys/mt.c | 221 ++ core/sys/mt.h | 366 ++++ core/sys/process.c | 402 ++++ core/sys/process.h | 526 +++++ core/sys/procinit.c | 49 + core/sys/procinit.h | 45 + core/sys/pt-sem.h | 228 ++ core/sys/pt.h | 323 +++ core/sys/service.c | 111 + core/sys/service.h | 195 ++ core/sys/timer.c | 128 ++ core/sys/timer.h | 100 + cpu/6502/Makefile.cc65 | 76 + cpu/6502/Makefile.common | 27 + cpu/6502/apps/memstat-dsc.c | 74 + cpu/6502/apps/memstat-dsc.h | 42 + cpu/6502/apps/memstat.c | 127 ++ cpu/6502/lib/clock.c | 41 + cpu/6502/lib/lc-asm.S | 30 + cpu/6502/lib/lc-cc65.h | 52 + cpu/6502/lib/lc.h | 52 + cpu/6502/loader/loader-arch-dsc.c | 57 + cpu/6502/loader/loader-arch-dsc.h | 46 + cpu/6502/loader/loader-arch-module-dsc.S | 1 + cpu/6502/loader/loader-arch-module.S | 8 + cpu/6502/loader/loader-arch.c | 117 + cpu/6502/loader/loader-arch.h | 47 + cpu/6502/net/rs232dev.c | 272 +++ cpu/6502/net/rs232dev.h | 48 + cpu/6502/net/slip-drv.c | 81 + cpu/6502/net/slip-dsc.c | 72 + cpu/6502/net/slip-dump-drv.c | 120 ++ cpu/6502/net/uip_arch.c | 520 +++++ cpu/6502/net/uip_arch.h | 47 + cpu/avr/dev/clock.c | 54 + cpu/avr/dev/compiler.h | 39 + cpu/avr/dev/debug.c | 72 + cpu/avr/dev/debug.h | 20 + cpu/avr/dev/delay.c | 29 + cpu/avr/dev/delay.h | 9 + cpu/avr/dev/eeprom.c | 55 + cpu/avr/dev/flash.c | 50 + cpu/avr/dev/flash.h | 8 + cpu/avr/dev/lanc111.c | 1362 ++++++++++++ cpu/avr/dev/rs232.c | 130 ++ cpu/avr/dev/rs232.h | 100 + cpu/avr/dev/rtl8019-drv.c | 94 + cpu/avr/dev/rtl8019-drv.h | 44 + cpu/avr/dev/rtl8019.c | 936 ++++++++ cpu/avr/dev/rtl8019.h | 265 +++ cpu/avr/dev/rtl8019as-drv.c | 160 ++ cpu/avr/dev/rtl8019dev.c | 77 + cpu/avr/dev/rtl8019dev.h | 60 + cpu/avr/dev/rtlregs.h | 354 +++ cpu/msp430/Makefile.msp430 | 128 ++ cpu/msp430/button.c | 80 + cpu/msp430/cc2420_uart0.c | 57 + cpu/msp430/clock.c | 147 ++ cpu/msp430/dev/button.h | 44 + cpu/msp430/dev/flash.h | 78 + cpu/msp430/dev/hwconf.h | 57 + cpu/msp430/dev/lpm.h | 63 + cpu/msp430/flash.c | 109 + cpu/msp430/leds-arch.c | 71 + cpu/msp430/loader-arch.c | 219 ++ cpu/msp430/lpm.c | 49 + cpu/msp430/msp430.c | 211 ++ cpu/msp430/mtarch.c | 132 ++ cpu/msp430/mtarch.h | 44 + cpu/msp430/rom.c | 161 ++ cpu/msp430/slip_uart1.c | 165 ++ cpu/msp430/spi.c | 70 + cpu/msp430/watchdog.c | 54 + cpu/x86/Makefile.x86 | 33 + cpu/x86/mtarch.c | 101 + cpu/x86/mtarch.h | 43 + doc/Doxyfile | 301 +++ doc/Makefile | 11 + doc/code-style.c | 116 + doc/code-style.txt | 3 + doc/contiki-mainpage.txt | 53 + doc/dev.txt | 5 + doc/example-list.c | 27 + doc/example-packet-service.c | 141 ++ doc/example-pollhandler.c | 30 + doc/example-program.c | 89 + doc/example-psock-client.c | 57 + doc/example-psock-server.c | 165 ++ doc/example-service.c | 115 + doc/example-service.h | 33 + doc/example-use-service.c | 65 + doc/examples.txt | 8 + doc/html/.cvsignore | 1 + doc/html/img/esb/cygwin0.jpg | Bin 0 -> 24259 bytes doc/html/img/esb/cygwin1.jpg | Bin 0 -> 25351 bytes doc/html/img/esb/cygwin2.jpg | Bin 0 -> 27979 bytes doc/html/img/esb/cygwin3.jpg | Bin 0 -> 24429 bytes doc/html/img/esb/cygwin4.jpg | Bin 0 -> 25260 bytes doc/html/img/esb/cygwin5.jpg | Bin 0 -> 35045 bytes doc/html/img/esb/cygwin6.jpg | Bin 0 -> 32856 bytes doc/html/img/esb/cygwin6b.jpg | Bin 0 -> 33462 bytes doc/html/img/esb/esb.jpg | Bin 0 -> 29308 bytes doc/html/img/esb/slip01.jpg | Bin 0 -> 42351 bytes doc/html/img/esb/slip02.jpg | Bin 0 -> 33092 bytes doc/html/img/esb/slip03.jpg | Bin 0 -> 41931 bytes doc/html/img/esb/slip04.jpg | Bin 0 -> 32314 bytes doc/html/img/esb/slip05.jpg | Bin 0 -> 25802 bytes doc/html/img/esb/slip06.jpg | Bin 0 -> 26230 bytes doc/html/img/esb/slip07.jpg | Bin 0 -> 22345 bytes doc/html/img/esb/slip08.jpg | Bin 0 -> 40307 bytes doc/html/img/esb/slip09.jpg | Bin 0 -> 25427 bytes doc/html/img/esb/slip10.jpg | Bin 0 -> 25499 bytes doc/html/img/esb/slip11.jpg | Bin 0 -> 23934 bytes doc/html/img/esb/slip12.jpg | Bin 0 -> 35768 bytes doc/html/img/esb/slip13.jpg | Bin 0 -> 40949 bytes doc/html/img/esb/slip14b.jpg | Bin 0 -> 38156 bytes doc/html/img/esb/slip15.jpg | Bin 0 -> 35075 bytes doc/html/img/esb/slip16.jpg | Bin 0 -> 40506 bytes doc/lib.txt | 5 + doc/mem.txt | 5 + doc/net.txt | 5 + doc/platform.txt | 6 + doc/pt-doc.txt | 178 ++ doc/sys.txt | 5 + doc/uip-doc.txt | 1193 +++++++++++ examples/telnet-server/Makefile | 5 + examples/telnet-server/telnet-server.c | 46 + examples/test-ipv6/Makefile | 9 + examples/test-ipv6/tapdev.h | 46 + examples/test-ipv6/tapdev6.c | 203 ++ examples/test-ipv6/testv6.c | 82 + examples/webserver/Makefile | 7 + examples/webserver/webserver-example.c | 45 + platform/c64/Makefile | 77 + platform/c64/apps/blueround-dsc.c | 74 + platform/c64/apps/cgterm-dsc.c | 74 + platform/c64/apps/cgterm.c | 242 +++ platform/c64/apps/config.c | 241 +++ platform/c64/apps/configedit-dsc.c | 74 + platform/c64/apps/configedit-dsc.h | 42 + platform/c64/apps/configedit.c | 418 ++++ platform/c64/apps/default-dsc.c | 72 + platform/c64/apps/enabler-dsc.c | 74 + platform/c64/apps/http-user-agent-string.c | 37 + platform/c64/apps/http-user-agent-string.h | 35 + platform/c64/apps/memstat-dsc.c | 74 + platform/c64/apps/mtest.c | 54 + platform/c64/apps/plasma-dsc.c | 74 + platform/c64/apps/plasma.c | 224 ++ platform/c64/apps/ravenpine-dsc.c | 74 + platform/c64/apps/springlight-dsc.c | 74 + platform/c64/apps/ssfire-dsc.c | 74 + platform/c64/apps/ssfire.c | 163 ++ platform/c64/apps/themeloader.c | 52 + platform/c64/apps/vnc-draw-asm.h | 42 + platform/c64/apps/vnc-draw.c | 689 ++++++ platform/c64/apps/warmboot.c | 54 + platform/c64/apps/welcome.c | 88 + platform/c64/apps/wget-dsc.c | 74 + platform/c64/apps/wget-dsc.h | 42 + platform/c64/apps/wget.c | 528 +++++ platform/c64/c64.cfg | 30 + platform/c64/contiki-conf.h | 606 ++++++ platform/c64/ctk/ctk-80col-asm.h | 73 + platform/c64/ctk/ctk-80col-theme.h | 83 + platform/c64/ctk/ctk-80col.c | 1187 +++++++++++ platform/c64/ctk/ctk-arch.h | 55 + platform/c64/ctk/ctk-hires-asm.h | 70 + platform/c64/ctk/ctk-hires-service.c | 925 ++++++++ platform/c64/ctk/ctk-hires-theme-blueround.c | 313 +++ platform/c64/ctk/ctk-hires-theme-default.c | 303 +++ platform/c64/ctk/ctk-hires-theme-enabler.c | 303 +++ platform/c64/ctk/ctk-hires-theme-ravenpine.c | 288 +++ .../c64/ctk/ctk-hires-theme-springlight.c | 284 +++ platform/c64/ctk/ctk-hires-theme.h | 105 + platform/c64/ctk/ctk-hires.c | 871 ++++++++ platform/c64/ctk/ctk-hires.h | 48 + platform/c64/ctk/ctk-mouse-arch.c | 122 ++ platform/c64/ctk/ctk-mouse.c | 122 ++ platform/c64/lib/iconfield.c | 119 ++ platform/c64/lib/mtarch.c | 98 + platform/c64/lib/mtarch.h | 51 + platform/c64/loader/c64-dio-asm.h | 47 + platform/c64/loader/c64-dio.c | 119 ++ platform/c64/loader/c64-dio.h | 50 + platform/c64/loader/c64-fs-raw.c | 205 ++ platform/c64/loader/c64-fs-raw.h | 46 + platform/c64/loader/c64-fs-write.c | 121 ++ platform/c64/loader/c64-fs.c | 411 ++++ platform/c64/loader/c64-fs.h | 97 + platform/c64/loader/cfs-1541.c | 67 + platform/c64/loader/cfs-cbm-posix.c | 146 ++ platform/c64/loader/cfs-cbm.c | 123 ++ platform/c64/loader/cfs-cbm.h | 39 + platform/c64/loader/cfs-init.c | 93 + platform/c64/loader/cfs-init.h | 42 + platform/c64/loader/loader-arch.c | 140 ++ platform/c64/main.c | 143 ++ platform/c64/net/cs8900a.c | 297 +++ platform/c64/net/cs8900a.h | 44 + platform/c64/net/eth64-drv.c | 107 + platform/c64/net/eth64-dsc.c | 74 + platform/c64/net/eth64-dump-drv.c | 146 ++ platform/c64/net/lan91c96.c | 453 ++++ platform/c64/net/lan91c96.h | 45 + platform/c64/net/rrnet-drv.c | 117 + platform/c64/net/rrnet-dsc.c | 74 + platform/c64/net/rrnet-dump-drv.c | 146 ++ platform/c64/net/rs232dev-ss.c | 236 ++ platform/c64/net/rs232silversurfer.h | 143 ++ platform/c64/net/tfe-drv.c | 107 + platform/c64/net/tfe-dsc.c | 74 + platform/c64/net/tfe-dump-drv.c | 141 ++ platform/esb/Makefile.esb | 31 + platform/esb/contiki-conf.h | 104 + .../esb/contiki-esb-default-contiki-conf.h | 88 + platform/esb/contiki-esb-default-init-apps.c | 36 + .../esb/contiki-esb-default-init-lowlevel.c | 81 + platform/esb/contiki-esb-default-init-net.c | 61 + platform/esb/contiki-esb-main.c | 131 ++ platform/esb/contiki-esb.h | 77 + platform/esb/core.c | 45 + platform/esb/doc/contiki-esb.txt | 72 + platform/esb/doc/doc.txt | 7 + platform/esb/doc/esb.txt | 28 + platform/esb/doc/getting-started.txt | 28 + platform/esb/doc/quickref.txt | 68 + platform/esb/doc/slipintro.txt | 126 ++ platform/esb/doc/winintro.txt | 164 ++ platform/esb/node-id.h | 41 + platform/esb/symbols.c | 289 +++ platform/ethernut1/Makefile.ethernut1 | 16 + platform/ethernut1/contiki-conf.h | 156 ++ platform/ethernut1/ethernut-main.c | 101 + platform/ethernut2/Makefile.ethernut2 | 10 + platform/ethernut2/contiki-conf.h | 159 ++ platform/ethernut2/ethernut-main.c | 100 + platform/gtk/Makefile | 38 + platform/gtk/background.png | Bin 0 -> 95975 bytes platform/gtk/clock.c | 56 + platform/gtk/contiki-conf.h | 174 ++ platform/gtk/contiki-main.c | 197 ++ platform/gtk/ctk/conio.h | 47 + platform/gtk/ctk/ctk-arch.h | 45 + platform/gtk/ctk/ctk-gtksim-conio.c | 359 ++++ platform/gtk/ctk/ctk-gtksim-draw.c | 172 ++ platform/gtk/ctk/ctk-gtksim-draw.h | 37 + platform/gtk/ctk/ctk-gtksim-service.c | 869 ++++++++ platform/gtk/ctk/ctk-gtksim-service.h | 8 + platform/gtk/ctk/ctk-gtksim.c | 371 ++++ platform/gtk/ctk/ctk-gtksim.h | 73 + platform/gtk/menubar.png | Bin 0 -> 4391 bytes platform/gtk/net/tapdev-service.c | 63 + platform/gtk/net/tapdev-service.h | 8 + platform/gtk/net/tapdev.c | 178 ++ platform/gtk/net/tapdev.h | 43 + platform/gtk/windowborder.png | Bin 0 -> 24082 bytes platform/minimal-net/Makefile.minimal-net | 57 + platform/minimal-net/clock.c | 61 + platform/minimal-net/contiki-conf.h | 62 + platform/minimal-net/contiki-main.c | 94 + platform/minimal-net/net/tapdev-service.c | 104 + platform/minimal-net/net/tapdev-service.h | 40 + platform/minimal-net/net/tapdev.c | 184 ++ platform/minimal-net/net/tapdev.h | 46 + platform/minimal-ppp/Makefile | 118 + platform/minimal-ppp/Makefile.minimal-ppp | 58 + platform/minimal-ppp/README | 5 + platform/minimal-ppp/clock.c | 61 + platform/minimal-ppp/contiki-conf.h | 220 ++ platform/minimal-ppp/contiki-main.c | 99 + platform/minimal-ppp/ctk-arch.h | 41 + platform/minimal-ppp/leds-arch.c | 61 + platform/minimal-ppp/ppp-arch.c | 62 + platform/minimal-ppp/ppp_arch.h | 0 platform/native/Makefile.native | 28 + platform/native/clock.c | 61 + platform/native/contiki-conf.h | 63 + platform/native/contiki-main.c | 98 + platform/native/dev/beep.c | 88 + platform/native/dev/beep.h | 166 ++ platform/native/dev/button-sensor.c | 60 + platform/native/dev/button-sensor.h | 12 + platform/native/dev/dummy-sensors.c | 92 + platform/native/dev/eeprom.c | 67 + platform/native/dev/irq.c | 5 + platform/native/dev/leds-arch.c | 61 + platform/native/dev/pir-sensor.c | 63 + platform/native/dev/pir-sensor.h | 12 + platform/native/dev/temperature-sensor.h | 51 + platform/native/dev/vib-sensor.c | 104 + platform/native/dev/vib-sensor.h | 53 + platform/netsim/Makefile.netsim | 52 + platform/netsim/contiki-conf.h | 296 +++ platform/netsim/contiki-esb.h | 63 + platform/netsim/contiki-main.c | 181 ++ platform/netsim/contiki-main.h | 40 + platform/netsim/dev/beep.c | 88 + platform/netsim/dev/beep.h | 166 ++ platform/netsim/dev/button-sensor.c | 60 + platform/netsim/dev/button-sensor.h | 12 + platform/netsim/dev/dummy-sensors.c | 96 + platform/netsim/dev/eeprom.c | 67 + platform/netsim/dev/esb-sensors.c | 55 + platform/netsim/dev/esb-sensors.h | 47 + platform/netsim/dev/flash.c | 61 + platform/netsim/dev/flash.h | 78 + platform/netsim/dev/irq.c | 5 + platform/netsim/dev/leds-arch.c | 60 + platform/netsim/dev/lpm.c | 55 + platform/netsim/dev/lpm.h | 40 + platform/netsim/dev/pir-sensor.c | 63 + platform/netsim/dev/pir-sensor.h | 12 + platform/netsim/dev/radio-sensor.h | 44 + platform/netsim/dev/radio.c | 52 + platform/netsim/dev/radio.h | 47 + platform/netsim/dev/rs232.c | 49 + platform/netsim/dev/rs232.h | 46 + platform/netsim/dev/temperature-sensor.h | 51 + platform/netsim/dev/tr1001-drv.c | 86 + platform/netsim/dev/tr1001-drv.h | 44 + platform/netsim/dev/tr1001.c | 101 + platform/netsim/dev/tr1001.h | 65 + platform/netsim/dev/vib-sensor.c | 104 + platform/netsim/dev/vib-sensor.h | 53 + platform/netsim/display.c | 619 ++++++ platform/netsim/display.h | 47 + platform/netsim/ether.c | 476 +++++ platform/netsim/ether.h | 79 + platform/netsim/init.c | 70 + platform/netsim/init.h | 41 + platform/netsim/loader-arch.h | 48 + platform/netsim/main.c | 267 +++ platform/netsim/net/ethernode-drv.c | 90 + platform/netsim/net/ethernode-drv.h | 45 + platform/netsim/net/ethernode.c | 190 ++ platform/netsim/net/ethernode.h | 46 + platform/netsim/net/tapdev-drv.c | 58 + platform/netsim/net/tapdev-drv.h | 8 + platform/netsim/net/tapdev-service.c | 63 + platform/netsim/net/tapdev-service.h | 8 + platform/netsim/net/tapdev.c | 192 ++ platform/netsim/net/tapdev.h | 47 + platform/netsim/node-id.h | 43 + platform/netsim/node.c | 138 ++ platform/netsim/node.h | 63 + platform/netsim/nodes.c | 115 + platform/netsim/nodes.h | 60 + platform/netsim/random.c | 59 + platform/netsim/random.h | 53 + platform/netsim/sensor.c | 82 + platform/netsim/sensor.h | 55 + platform/netsim/symbols.c | 35 + tools/avr-make-symbols | 8 + tools/cc65-make-labels | 6 + tools/makefsdata | 78 + tools/msp430-make-symbols | 13 + 671 files changed, 95332 insertions(+) create mode 100644 Makefile.include create mode 100644 apps/about/Makefile.about create mode 100644 apps/about/about-dsc.c create mode 100644 apps/about/about-dsc.h create mode 100644 apps/about/about.c create mode 100644 apps/calc/Makefile.calc create mode 100644 apps/calc/calc-dsc.c create mode 100644 apps/calc/calc-dsc.h create mode 100644 apps/calc/calc.c create mode 100644 apps/cmdd/Makefile.cmdd create mode 100644 apps/cmdd/cmdd.c create mode 100644 apps/cmdd/cmdd.h create mode 100644 apps/dhcp/Makefile.dhcp create mode 100644 apps/dhcp/dhcp-dsc.c create mode 100644 apps/dhcp/dhcp-dsc.h create mode 100644 apps/dhcp/dhcp.c create mode 100644 apps/dhcp/dhcp.h create mode 100644 apps/directory/Makefile.directory create mode 100644 apps/directory/directory-dsc.c create mode 100644 apps/directory/directory-dsc.h create mode 100644 apps/directory/directory.c create mode 100644 apps/editor/Makefile.editor create mode 100644 apps/editor/editor-dsc.c create mode 100644 apps/editor/editor-dsc.h create mode 100644 apps/editor/editor.c create mode 100644 apps/email/Makefile.email create mode 100644 apps/email/email-dsc.c create mode 100644 apps/email/email-dsc.h create mode 100644 apps/email/email.c create mode 100644 apps/email/email.h create mode 100644 apps/email/smtp-socket.c create mode 100644 apps/email/smtp-strings create mode 100644 apps/email/smtp-strings.c create mode 100644 apps/email/smtp-strings.h create mode 100644 apps/email/smtp.h create mode 100644 apps/ftp/Makefile.ftp create mode 100644 apps/ftp/ftp-dsc.c create mode 100644 apps/ftp/ftp-dsc.h create mode 100644 apps/ftp/ftp.c create mode 100644 apps/ftp/ftpc.c create mode 100644 apps/ftp/ftpc.h create mode 100644 apps/irc/Makefile.irc create mode 100644 apps/irc/irc-dsc.c create mode 100644 apps/irc/irc-dsc.h create mode 100644 apps/irc/irc.c create mode 100644 apps/irc/ircc-strings create mode 100644 apps/irc/ircc-strings.c create mode 100644 apps/irc/ircc-strings.h create mode 100644 apps/irc/ircc.c create mode 100644 apps/irc/ircc.h create mode 100644 apps/netconf/Makefile.netconf create mode 100644 apps/netconf/netconf-dsc.c create mode 100644 apps/netconf/netconf-dsc.h create mode 100644 apps/netconf/netconf.c create mode 100644 apps/process-list/Makefile.process-list create mode 100644 apps/process-list/process-list-dsc.c create mode 100644 apps/process-list/process-list-dsc.h create mode 100644 apps/process-list/process-list.c create mode 100644 apps/program-handler/Makefile.program-handler create mode 100644 apps/program-handler/program-handler.c create mode 100644 apps/program-handler/program-handler.h create mode 100644 apps/shell/Makefile.shell create mode 100644 apps/shell/shell-dsc.c create mode 100644 apps/shell/shell-dsc.h create mode 100644 apps/shell/shell-gui.c create mode 100644 apps/shell/shell.c create mode 100644 apps/shell/shell.h create mode 100644 apps/telnet/Makefile.telnet create mode 100644 apps/telnet/simpletelnet.c create mode 100644 apps/telnet/simpletelnet.h create mode 100644 apps/telnet/telnet-dsc.c create mode 100644 apps/telnet/telnet-dsc.h create mode 100644 apps/telnet/telnet.c create mode 100644 apps/telnet/telnet.h create mode 100644 apps/telnetd/Makefile.telnetd create mode 100644 apps/telnetd/telnetd-dsc.c create mode 100644 apps/telnetd/telnetd-dsc.h create mode 100644 apps/telnetd/telnetd-gui.c create mode 100644 apps/telnetd/telnetd.c create mode 100644 apps/telnetd/telnetd.h create mode 100644 apps/webbrowser/Makefile.webbrowser create mode 100644 apps/webbrowser/html-strings create mode 100644 apps/webbrowser/html-strings.c create mode 100644 apps/webbrowser/html-strings.h create mode 100644 apps/webbrowser/htmlparser.c create mode 100644 apps/webbrowser/htmlparser.h create mode 100644 apps/webbrowser/http-strings create mode 100644 apps/webbrowser/http-strings.c create mode 100644 apps/webbrowser/http-strings.h create mode 100644 apps/webbrowser/http-user-agent-string.c create mode 100644 apps/webbrowser/http-user-agent-string.h create mode 100644 apps/webbrowser/webclient.c create mode 100644 apps/webbrowser/webclient.h create mode 100644 apps/webbrowser/www-dsc.c create mode 100644 apps/webbrowser/www-dsc.h create mode 100644 apps/webbrowser/www.c create mode 100644 apps/webbrowser/www.h create mode 100644 apps/webserver/Makefile.webserver create mode 100644 apps/webserver/http-strings.c create mode 100644 apps/webserver/http-strings.h create mode 100644 apps/webserver/httpd-cfs.c create mode 100644 apps/webserver/httpd-cfs.h create mode 100644 apps/webserver/httpd-cgi.c create mode 100644 apps/webserver/httpd-cgi.h create mode 100644 apps/webserver/httpd-fs.c create mode 100644 apps/webserver/httpd-fs.h create mode 100644 apps/webserver/httpd-fs/404.html create mode 100644 apps/webserver/httpd-fs/files.shtml create mode 100644 apps/webserver/httpd-fs/footer.html create mode 100644 apps/webserver/httpd-fs/header.html create mode 100644 apps/webserver/httpd-fs/index.html create mode 100644 apps/webserver/httpd-fs/processes.shtml create mode 100644 apps/webserver/httpd-fs/style.css create mode 100644 apps/webserver/httpd-fs/tcp.shtml create mode 100644 apps/webserver/httpd-fs/upload.html create mode 100644 apps/webserver/httpd-fsdata.c create mode 100644 apps/webserver/httpd-fsdata.h create mode 100644 apps/webserver/httpd-socket.c create mode 100644 apps/webserver/httpd.c create mode 100644 apps/webserver/httpd.h create mode 100644 apps/webserver/webserver-dsc.c create mode 100644 apps/webserver/webserver-dsc.h create mode 100644 apps/webserver/webserver-nogui.c create mode 100644 apps/webserver/webserver-nogui.h create mode 100644 apps/webserver/webserver.c create mode 100644 apps/webserver/webserver.h create mode 100644 core/cfs/cfs-eeprom.c create mode 100644 core/cfs/cfs-eeprom.h create mode 100644 core/cfs/cfs-posix.c create mode 100644 core/cfs/cfs-posix.h create mode 100644 core/cfs/cfs-ram.c create mode 100644 core/cfs/cfs-ram.h create mode 100644 core/cfs/cfs-service.h create mode 100644 core/cfs/cfs.c create mode 100644 core/cfs/cfs.h create mode 100644 core/contiki-lib.h create mode 100644 core/contiki-net.h create mode 100644 core/contiki-version.h create mode 100644 core/contiki.h create mode 100644 core/ctk/ctk-conio-service.c create mode 100644 core/ctk/ctk-conio.c create mode 100644 core/ctk/ctk-conio.h create mode 100644 core/ctk/ctk-draw-service.h create mode 100644 core/ctk/ctk-draw.c create mode 100644 core/ctk/ctk-draw.h create mode 100644 core/ctk/ctk-graphic-draw.h create mode 100644 core/ctk/ctk-graphic.c create mode 100644 core/ctk/ctk-mouse.c create mode 100644 core/ctk/ctk-mouse.h create mode 100644 core/ctk/ctk-term-ascii.h create mode 100644 core/ctk/ctk-term-in.c create mode 100644 core/ctk/ctk-term-int.h create mode 100644 core/ctk/ctk-term-out.c create mode 100644 core/ctk/ctk-term-out.h create mode 100644 core/ctk/ctk-term.c create mode 100644 core/ctk/ctk-term.h create mode 100644 core/ctk/ctk-termarch.h create mode 100644 core/ctk/ctk-termserial.c create mode 100644 core/ctk/ctk-termserial.h create mode 100644 core/ctk/ctk-termtelnet.c create mode 100644 core/ctk/ctk-termtelnet.h create mode 100644 core/ctk/ctk-vncarch.h create mode 100644 core/ctk/ctk-vncfont.c create mode 100644 core/ctk/ctk-vncfont.h create mode 100644 core/ctk/ctk-vncserver-service.c create mode 100644 core/ctk/ctk-vncserver.c create mode 100644 core/ctk/ctk-vncserver.h create mode 100644 core/ctk/ctk.c create mode 100644 core/ctk/ctk.h create mode 100644 core/ctk/vnc-out.c create mode 100644 core/ctk/vnc-out.h create mode 100644 core/ctk/vnc-server.c create mode 100644 core/ctk/vnc-server.h create mode 100644 core/dev/cc2420.c create mode 100644 core/dev/cc2420.h create mode 100644 core/dev/cc2420_const.h create mode 100644 core/dev/cc2420_send_ip.c create mode 100644 core/dev/cc2420_send_uaodv.c create mode 100644 core/dev/cs8900a.c create mode 100644 core/dev/cs8900a.h create mode 100644 core/dev/ds2411.c create mode 100644 core/dev/ds2411.h create mode 100644 core/dev/eeprom.h create mode 100644 core/dev/leds.c create mode 100644 core/dev/leds.h create mode 100644 core/dev/radio.h create mode 100644 core/dev/rom.h create mode 100644 core/dev/serial.c create mode 100644 core/dev/serial.h create mode 100644 core/dev/slip.c create mode 100644 core/dev/slip.h create mode 100644 core/dev/spi.h create mode 100644 core/dev/watchdog.h create mode 100644 core/dev/xmem.h create mode 100644 core/lib/crc16.c create mode 100644 core/lib/crc16.h create mode 100644 core/lib/crtk.c create mode 100644 core/lib/crtk.h create mode 100644 core/lib/ctk-filedialog.c create mode 100644 core/lib/ctk-filedialog.h create mode 100644 core/lib/ctk-textedit.c create mode 100644 core/lib/ctk-textedit.h create mode 100644 core/lib/ctk-textentry-checkbox.c create mode 100644 core/lib/ctk-textentry-checkbox.h create mode 100644 core/lib/ctk-textentry-cmdline.c create mode 100644 core/lib/ctk-textentry-cmdline.h create mode 100644 core/lib/ctk-textentry-multiline.c create mode 100644 core/lib/ctk-textentry-multiline.h create mode 100644 core/lib/libconio.c create mode 100644 core/lib/libconio.h create mode 100644 core/lib/list.c create mode 100644 core/lib/list.h create mode 100644 core/lib/malloc.c create mode 100644 core/lib/malloc.h create mode 100644 core/lib/malloc_compact.c create mode 100644 core/lib/me.c create mode 100644 core/lib/me.h create mode 100644 core/lib/me_tabs.c create mode 100644 core/lib/me_tabs.h create mode 100644 core/lib/memb.c create mode 100644 core/lib/memb.h create mode 100644 core/lib/mmem.c create mode 100644 core/lib/mmem.h create mode 100644 core/lib/petsciiconv.c create mode 100644 core/lib/petsciiconv.h create mode 100644 core/lib/rand.c create mode 100644 core/lib/rand.h create mode 100644 core/lib/random.c create mode 100644 core/lib/random.h create mode 100644 core/lib/realloc.c create mode 100644 core/lib/sensors.c create mode 100644 core/lib/sensors.h create mode 100644 core/lib/strncasecmp.c create mode 100644 core/loader/dlloader.c create mode 100644 core/loader/dlloader.h create mode 100644 core/loader/elfloader-arch.h create mode 100644 core/loader/elfloader-avr.c create mode 100644 core/loader/elfloader-msp430.c create mode 100644 core/loader/elfloader-stub.c create mode 100644 core/loader/elfloader-tmp.c create mode 100644 core/loader/elfloader-tmp.h create mode 100644 core/loader/elfloader.c create mode 100644 core/loader/elfloader.h create mode 100644 core/loader/symbols.h create mode 100644 core/loader/symtab.c create mode 100644 core/loader/symtab.h create mode 100644 core/net/adhoc-service.h create mode 100644 core/net/ahdlc.c create mode 100644 core/net/ahdlc.h create mode 100644 core/net/dhcpc.c create mode 100644 core/net/dhcpc.h create mode 100644 core/net/hc-service.c create mode 100644 core/net/hc-service.h create mode 100644 core/net/hc.c create mode 100644 core/net/hc.h create mode 100644 core/net/ipcp.c create mode 100644 core/net/ipcp.h create mode 100644 core/net/lcp.c create mode 100644 core/net/lcp.h create mode 100644 core/net/packet-service.h create mode 100644 core/net/pap.c create mode 100644 core/net/pap.h create mode 100644 core/net/ppp-service.c create mode 100644 core/net/ppp.c create mode 100644 core/net/ppp.h create mode 100644 core/net/ppp_process.c create mode 100644 core/net/ppp_process.h create mode 100644 core/net/psock.c create mode 100644 core/net/psock.h create mode 100644 core/net/resolv.c create mode 100644 core/net/resolv.h create mode 100644 core/net/slipdev.c create mode 100644 core/net/slipdev.h create mode 100644 core/net/tcpdump.c create mode 100644 core/net/tcpdump.h create mode 100644 core/net/tcpip.c create mode 100644 core/net/tcpip.h create mode 100644 core/net/uaodv-def.h create mode 100644 core/net/uaodv-rt.c create mode 100644 core/net/uaodv-rt.h create mode 100644 core/net/uaodv.c create mode 100644 core/net/uaodv.h create mode 100644 core/net/uip-fw-service.c create mode 100644 core/net/uip-fw-service.h create mode 100644 core/net/uip-fw.c create mode 100644 core/net/uip-fw.h create mode 100644 core/net/uip-neighbor.c create mode 100644 core/net/uip-neighbor.h create mode 100644 core/net/uip-split.c create mode 100644 core/net/uip-split.h create mode 100644 core/net/uip.c create mode 100644 core/net/uip.h create mode 100644 core/net/uip_arch.h create mode 100644 core/net/uip_arp.c create mode 100644 core/net/uip_arp.h create mode 100644 core/net/uipbuf.c create mode 100644 core/net/uipbuf.h create mode 100644 core/net/uiplib.c create mode 100644 core/net/uiplib.h create mode 100644 core/net/uipopt.h create mode 100644 core/sys/arg.c create mode 100644 core/sys/arg.h create mode 100644 core/sys/autostart.c create mode 100644 core/sys/autostart.h create mode 100644 core/sys/cc.h create mode 100644 core/sys/clock.h create mode 100644 core/sys/dsc.h create mode 100644 core/sys/etimer.c create mode 100644 core/sys/etimer.h create mode 100644 core/sys/lc-addrlabels.h create mode 100644 core/sys/lc-switch.h create mode 100644 core/sys/lc.h create mode 100644 core/sys/loader.h create mode 100644 core/sys/log.h create mode 100644 core/sys/mt.c create mode 100644 core/sys/mt.h create mode 100644 core/sys/process.c create mode 100644 core/sys/process.h create mode 100644 core/sys/procinit.c create mode 100644 core/sys/procinit.h create mode 100644 core/sys/pt-sem.h create mode 100644 core/sys/pt.h create mode 100644 core/sys/service.c create mode 100644 core/sys/service.h create mode 100644 core/sys/timer.c create mode 100644 core/sys/timer.h create mode 100644 cpu/6502/Makefile.cc65 create mode 100644 cpu/6502/Makefile.common create mode 100644 cpu/6502/apps/memstat-dsc.c create mode 100644 cpu/6502/apps/memstat-dsc.h create mode 100644 cpu/6502/apps/memstat.c create mode 100644 cpu/6502/lib/clock.c create mode 100644 cpu/6502/lib/lc-asm.S create mode 100644 cpu/6502/lib/lc-cc65.h create mode 100644 cpu/6502/lib/lc.h create mode 100644 cpu/6502/loader/loader-arch-dsc.c create mode 100644 cpu/6502/loader/loader-arch-dsc.h create mode 100644 cpu/6502/loader/loader-arch-module-dsc.S create mode 100644 cpu/6502/loader/loader-arch-module.S create mode 100644 cpu/6502/loader/loader-arch.c create mode 100644 cpu/6502/loader/loader-arch.h create mode 100644 cpu/6502/net/rs232dev.c create mode 100644 cpu/6502/net/rs232dev.h create mode 100644 cpu/6502/net/slip-drv.c create mode 100644 cpu/6502/net/slip-dsc.c create mode 100644 cpu/6502/net/slip-dump-drv.c create mode 100644 cpu/6502/net/uip_arch.c create mode 100644 cpu/6502/net/uip_arch.h create mode 100644 cpu/avr/dev/clock.c create mode 100644 cpu/avr/dev/compiler.h create mode 100644 cpu/avr/dev/debug.c create mode 100644 cpu/avr/dev/debug.h create mode 100644 cpu/avr/dev/delay.c create mode 100644 cpu/avr/dev/delay.h create mode 100644 cpu/avr/dev/eeprom.c create mode 100644 cpu/avr/dev/flash.c create mode 100644 cpu/avr/dev/flash.h create mode 100644 cpu/avr/dev/lanc111.c create mode 100644 cpu/avr/dev/rs232.c create mode 100644 cpu/avr/dev/rs232.h create mode 100644 cpu/avr/dev/rtl8019-drv.c create mode 100644 cpu/avr/dev/rtl8019-drv.h create mode 100644 cpu/avr/dev/rtl8019.c create mode 100644 cpu/avr/dev/rtl8019.h create mode 100644 cpu/avr/dev/rtl8019as-drv.c create mode 100644 cpu/avr/dev/rtl8019dev.c create mode 100644 cpu/avr/dev/rtl8019dev.h create mode 100644 cpu/avr/dev/rtlregs.h create mode 100644 cpu/msp430/Makefile.msp430 create mode 100644 cpu/msp430/button.c create mode 100644 cpu/msp430/cc2420_uart0.c create mode 100644 cpu/msp430/clock.c create mode 100644 cpu/msp430/dev/button.h create mode 100644 cpu/msp430/dev/flash.h create mode 100644 cpu/msp430/dev/hwconf.h create mode 100644 cpu/msp430/dev/lpm.h create mode 100644 cpu/msp430/flash.c create mode 100644 cpu/msp430/leds-arch.c create mode 100644 cpu/msp430/loader-arch.c create mode 100644 cpu/msp430/lpm.c create mode 100644 cpu/msp430/msp430.c create mode 100644 cpu/msp430/mtarch.c create mode 100644 cpu/msp430/mtarch.h create mode 100644 cpu/msp430/rom.c create mode 100644 cpu/msp430/slip_uart1.c create mode 100644 cpu/msp430/spi.c create mode 100644 cpu/msp430/watchdog.c create mode 100644 cpu/x86/Makefile.x86 create mode 100644 cpu/x86/mtarch.c create mode 100644 cpu/x86/mtarch.h create mode 100644 doc/Doxyfile create mode 100644 doc/Makefile create mode 100644 doc/code-style.c create mode 100644 doc/code-style.txt create mode 100644 doc/contiki-mainpage.txt create mode 100644 doc/dev.txt create mode 100644 doc/example-list.c create mode 100644 doc/example-packet-service.c create mode 100644 doc/example-pollhandler.c create mode 100644 doc/example-program.c create mode 100644 doc/example-psock-client.c create mode 100644 doc/example-psock-server.c create mode 100644 doc/example-service.c create mode 100644 doc/example-service.h create mode 100644 doc/example-use-service.c create mode 100644 doc/examples.txt create mode 100644 doc/html/.cvsignore create mode 100644 doc/html/img/esb/cygwin0.jpg create mode 100644 doc/html/img/esb/cygwin1.jpg create mode 100644 doc/html/img/esb/cygwin2.jpg create mode 100644 doc/html/img/esb/cygwin3.jpg create mode 100644 doc/html/img/esb/cygwin4.jpg create mode 100644 doc/html/img/esb/cygwin5.jpg create mode 100644 doc/html/img/esb/cygwin6.jpg create mode 100644 doc/html/img/esb/cygwin6b.jpg create mode 100644 doc/html/img/esb/esb.jpg create mode 100644 doc/html/img/esb/slip01.jpg create mode 100644 doc/html/img/esb/slip02.jpg create mode 100644 doc/html/img/esb/slip03.jpg create mode 100644 doc/html/img/esb/slip04.jpg create mode 100644 doc/html/img/esb/slip05.jpg create mode 100644 doc/html/img/esb/slip06.jpg create mode 100644 doc/html/img/esb/slip07.jpg create mode 100644 doc/html/img/esb/slip08.jpg create mode 100644 doc/html/img/esb/slip09.jpg create mode 100644 doc/html/img/esb/slip10.jpg create mode 100644 doc/html/img/esb/slip11.jpg create mode 100644 doc/html/img/esb/slip12.jpg create mode 100644 doc/html/img/esb/slip13.jpg create mode 100644 doc/html/img/esb/slip14b.jpg create mode 100644 doc/html/img/esb/slip15.jpg create mode 100644 doc/html/img/esb/slip16.jpg create mode 100644 doc/lib.txt create mode 100644 doc/mem.txt create mode 100644 doc/net.txt create mode 100644 doc/platform.txt create mode 100644 doc/pt-doc.txt create mode 100644 doc/sys.txt create mode 100644 doc/uip-doc.txt create mode 100644 examples/telnet-server/Makefile create mode 100644 examples/telnet-server/telnet-server.c create mode 100644 examples/test-ipv6/Makefile create mode 100644 examples/test-ipv6/tapdev.h create mode 100644 examples/test-ipv6/tapdev6.c create mode 100644 examples/test-ipv6/testv6.c create mode 100644 examples/webserver/Makefile create mode 100644 examples/webserver/webserver-example.c create mode 100644 platform/c64/Makefile create mode 100644 platform/c64/apps/blueround-dsc.c create mode 100644 platform/c64/apps/cgterm-dsc.c create mode 100644 platform/c64/apps/cgterm.c create mode 100644 platform/c64/apps/config.c create mode 100644 platform/c64/apps/configedit-dsc.c create mode 100644 platform/c64/apps/configedit-dsc.h create mode 100644 platform/c64/apps/configedit.c create mode 100644 platform/c64/apps/default-dsc.c create mode 100644 platform/c64/apps/enabler-dsc.c create mode 100644 platform/c64/apps/http-user-agent-string.c create mode 100644 platform/c64/apps/http-user-agent-string.h create mode 100644 platform/c64/apps/memstat-dsc.c create mode 100644 platform/c64/apps/mtest.c create mode 100644 platform/c64/apps/plasma-dsc.c create mode 100644 platform/c64/apps/plasma.c create mode 100644 platform/c64/apps/ravenpine-dsc.c create mode 100644 platform/c64/apps/springlight-dsc.c create mode 100644 platform/c64/apps/ssfire-dsc.c create mode 100644 platform/c64/apps/ssfire.c create mode 100644 platform/c64/apps/themeloader.c create mode 100644 platform/c64/apps/vnc-draw-asm.h create mode 100644 platform/c64/apps/vnc-draw.c create mode 100644 platform/c64/apps/warmboot.c create mode 100644 platform/c64/apps/welcome.c create mode 100644 platform/c64/apps/wget-dsc.c create mode 100644 platform/c64/apps/wget-dsc.h create mode 100644 platform/c64/apps/wget.c create mode 100644 platform/c64/c64.cfg create mode 100644 platform/c64/contiki-conf.h create mode 100644 platform/c64/ctk/ctk-80col-asm.h create mode 100644 platform/c64/ctk/ctk-80col-theme.h create mode 100644 platform/c64/ctk/ctk-80col.c create mode 100644 platform/c64/ctk/ctk-arch.h create mode 100644 platform/c64/ctk/ctk-hires-asm.h create mode 100644 platform/c64/ctk/ctk-hires-service.c create mode 100644 platform/c64/ctk/ctk-hires-theme-blueround.c create mode 100644 platform/c64/ctk/ctk-hires-theme-default.c create mode 100644 platform/c64/ctk/ctk-hires-theme-enabler.c create mode 100644 platform/c64/ctk/ctk-hires-theme-ravenpine.c create mode 100644 platform/c64/ctk/ctk-hires-theme-springlight.c create mode 100644 platform/c64/ctk/ctk-hires-theme.h create mode 100644 platform/c64/ctk/ctk-hires.c create mode 100644 platform/c64/ctk/ctk-hires.h create mode 100644 platform/c64/ctk/ctk-mouse-arch.c create mode 100644 platform/c64/ctk/ctk-mouse.c create mode 100644 platform/c64/lib/iconfield.c create mode 100644 platform/c64/lib/mtarch.c create mode 100644 platform/c64/lib/mtarch.h create mode 100644 platform/c64/loader/c64-dio-asm.h create mode 100644 platform/c64/loader/c64-dio.c create mode 100644 platform/c64/loader/c64-dio.h create mode 100644 platform/c64/loader/c64-fs-raw.c create mode 100644 platform/c64/loader/c64-fs-raw.h create mode 100644 platform/c64/loader/c64-fs-write.c create mode 100644 platform/c64/loader/c64-fs.c create mode 100644 platform/c64/loader/c64-fs.h create mode 100644 platform/c64/loader/cfs-1541.c create mode 100644 platform/c64/loader/cfs-cbm-posix.c create mode 100644 platform/c64/loader/cfs-cbm.c create mode 100644 platform/c64/loader/cfs-cbm.h create mode 100644 platform/c64/loader/cfs-init.c create mode 100644 platform/c64/loader/cfs-init.h create mode 100644 platform/c64/loader/loader-arch.c create mode 100644 platform/c64/main.c create mode 100644 platform/c64/net/cs8900a.c create mode 100644 platform/c64/net/cs8900a.h create mode 100644 platform/c64/net/eth64-drv.c create mode 100644 platform/c64/net/eth64-dsc.c create mode 100644 platform/c64/net/eth64-dump-drv.c create mode 100644 platform/c64/net/lan91c96.c create mode 100644 platform/c64/net/lan91c96.h create mode 100644 platform/c64/net/rrnet-drv.c create mode 100644 platform/c64/net/rrnet-dsc.c create mode 100644 platform/c64/net/rrnet-dump-drv.c create mode 100644 platform/c64/net/rs232dev-ss.c create mode 100644 platform/c64/net/rs232silversurfer.h create mode 100644 platform/c64/net/tfe-drv.c create mode 100644 platform/c64/net/tfe-dsc.c create mode 100644 platform/c64/net/tfe-dump-drv.c create mode 100644 platform/esb/Makefile.esb create mode 100644 platform/esb/contiki-conf.h create mode 100644 platform/esb/contiki-esb-default-contiki-conf.h create mode 100644 platform/esb/contiki-esb-default-init-apps.c create mode 100644 platform/esb/contiki-esb-default-init-lowlevel.c create mode 100644 platform/esb/contiki-esb-default-init-net.c create mode 100644 platform/esb/contiki-esb-main.c create mode 100644 platform/esb/contiki-esb.h create mode 100644 platform/esb/core.c create mode 100644 platform/esb/doc/contiki-esb.txt create mode 100644 platform/esb/doc/doc.txt create mode 100644 platform/esb/doc/esb.txt create mode 100644 platform/esb/doc/getting-started.txt create mode 100644 platform/esb/doc/quickref.txt create mode 100644 platform/esb/doc/slipintro.txt create mode 100644 platform/esb/doc/winintro.txt create mode 100644 platform/esb/node-id.h create mode 100644 platform/esb/symbols.c create mode 100644 platform/ethernut1/Makefile.ethernut1 create mode 100644 platform/ethernut1/contiki-conf.h create mode 100644 platform/ethernut1/ethernut-main.c create mode 100644 platform/ethernut2/Makefile.ethernut2 create mode 100644 platform/ethernut2/contiki-conf.h create mode 100644 platform/ethernut2/ethernut-main.c create mode 100644 platform/gtk/Makefile create mode 100644 platform/gtk/background.png create mode 100644 platform/gtk/clock.c create mode 100644 platform/gtk/contiki-conf.h create mode 100644 platform/gtk/contiki-main.c create mode 100644 platform/gtk/ctk/conio.h create mode 100644 platform/gtk/ctk/ctk-arch.h create mode 100644 platform/gtk/ctk/ctk-gtksim-conio.c create mode 100644 platform/gtk/ctk/ctk-gtksim-draw.c create mode 100644 platform/gtk/ctk/ctk-gtksim-draw.h create mode 100644 platform/gtk/ctk/ctk-gtksim-service.c create mode 100644 platform/gtk/ctk/ctk-gtksim-service.h create mode 100644 platform/gtk/ctk/ctk-gtksim.c create mode 100644 platform/gtk/ctk/ctk-gtksim.h create mode 100644 platform/gtk/menubar.png create mode 100644 platform/gtk/net/tapdev-service.c create mode 100644 platform/gtk/net/tapdev-service.h create mode 100644 platform/gtk/net/tapdev.c create mode 100644 platform/gtk/net/tapdev.h create mode 100644 platform/gtk/windowborder.png create mode 100644 platform/minimal-net/Makefile.minimal-net create mode 100644 platform/minimal-net/clock.c create mode 100644 platform/minimal-net/contiki-conf.h create mode 100644 platform/minimal-net/contiki-main.c create mode 100644 platform/minimal-net/net/tapdev-service.c create mode 100644 platform/minimal-net/net/tapdev-service.h create mode 100644 platform/minimal-net/net/tapdev.c create mode 100644 platform/minimal-net/net/tapdev.h create mode 100644 platform/minimal-ppp/Makefile create mode 100644 platform/minimal-ppp/Makefile.minimal-ppp create mode 100644 platform/minimal-ppp/README create mode 100644 platform/minimal-ppp/clock.c create mode 100644 platform/minimal-ppp/contiki-conf.h create mode 100644 platform/minimal-ppp/contiki-main.c create mode 100644 platform/minimal-ppp/ctk-arch.h create mode 100644 platform/minimal-ppp/leds-arch.c create mode 100644 platform/minimal-ppp/ppp-arch.c create mode 100644 platform/minimal-ppp/ppp_arch.h create mode 100644 platform/native/Makefile.native create mode 100644 platform/native/clock.c create mode 100644 platform/native/contiki-conf.h create mode 100644 platform/native/contiki-main.c create mode 100644 platform/native/dev/beep.c create mode 100644 platform/native/dev/beep.h create mode 100644 platform/native/dev/button-sensor.c create mode 100644 platform/native/dev/button-sensor.h create mode 100644 platform/native/dev/dummy-sensors.c create mode 100644 platform/native/dev/eeprom.c create mode 100644 platform/native/dev/irq.c create mode 100644 platform/native/dev/leds-arch.c create mode 100644 platform/native/dev/pir-sensor.c create mode 100644 platform/native/dev/pir-sensor.h create mode 100644 platform/native/dev/temperature-sensor.h create mode 100644 platform/native/dev/vib-sensor.c create mode 100644 platform/native/dev/vib-sensor.h create mode 100644 platform/netsim/Makefile.netsim create mode 100644 platform/netsim/contiki-conf.h create mode 100644 platform/netsim/contiki-esb.h create mode 100644 platform/netsim/contiki-main.c create mode 100644 platform/netsim/contiki-main.h create mode 100644 platform/netsim/dev/beep.c create mode 100644 platform/netsim/dev/beep.h create mode 100644 platform/netsim/dev/button-sensor.c create mode 100644 platform/netsim/dev/button-sensor.h create mode 100644 platform/netsim/dev/dummy-sensors.c create mode 100644 platform/netsim/dev/eeprom.c create mode 100644 platform/netsim/dev/esb-sensors.c create mode 100644 platform/netsim/dev/esb-sensors.h create mode 100644 platform/netsim/dev/flash.c create mode 100644 platform/netsim/dev/flash.h create mode 100644 platform/netsim/dev/irq.c create mode 100644 platform/netsim/dev/leds-arch.c create mode 100644 platform/netsim/dev/lpm.c create mode 100644 platform/netsim/dev/lpm.h create mode 100644 platform/netsim/dev/pir-sensor.c create mode 100644 platform/netsim/dev/pir-sensor.h create mode 100644 platform/netsim/dev/radio-sensor.h create mode 100644 platform/netsim/dev/radio.c create mode 100644 platform/netsim/dev/radio.h create mode 100644 platform/netsim/dev/rs232.c create mode 100644 platform/netsim/dev/rs232.h create mode 100644 platform/netsim/dev/temperature-sensor.h create mode 100644 platform/netsim/dev/tr1001-drv.c create mode 100644 platform/netsim/dev/tr1001-drv.h create mode 100644 platform/netsim/dev/tr1001.c create mode 100644 platform/netsim/dev/tr1001.h create mode 100644 platform/netsim/dev/vib-sensor.c create mode 100644 platform/netsim/dev/vib-sensor.h create mode 100644 platform/netsim/display.c create mode 100644 platform/netsim/display.h create mode 100644 platform/netsim/ether.c create mode 100644 platform/netsim/ether.h create mode 100644 platform/netsim/init.c create mode 100644 platform/netsim/init.h create mode 100644 platform/netsim/loader-arch.h create mode 100644 platform/netsim/main.c create mode 100644 platform/netsim/net/ethernode-drv.c create mode 100644 platform/netsim/net/ethernode-drv.h create mode 100644 platform/netsim/net/ethernode.c create mode 100644 platform/netsim/net/ethernode.h create mode 100644 platform/netsim/net/tapdev-drv.c create mode 100644 platform/netsim/net/tapdev-drv.h create mode 100644 platform/netsim/net/tapdev-service.c create mode 100644 platform/netsim/net/tapdev-service.h create mode 100644 platform/netsim/net/tapdev.c create mode 100644 platform/netsim/net/tapdev.h create mode 100644 platform/netsim/node-id.h create mode 100644 platform/netsim/node.c create mode 100644 platform/netsim/node.h create mode 100644 platform/netsim/nodes.c create mode 100644 platform/netsim/nodes.h create mode 100644 platform/netsim/random.c create mode 100644 platform/netsim/random.h create mode 100644 platform/netsim/sensor.c create mode 100644 platform/netsim/sensor.h create mode 100644 platform/netsim/symbols.c create mode 100755 tools/avr-make-symbols create mode 100755 tools/cc65-make-labels create mode 100755 tools/makefsdata create mode 100755 tools/msp430-make-symbols diff --git a/Makefile.include b/Makefile.include new file mode 100644 index 000000000..1d4896043 --- /dev/null +++ b/Makefile.include @@ -0,0 +1,128 @@ +ifndef CONTIKI + $(error CONTIKI not defined! You must specify where CONTIKI resides!) +endif + +OBJECTDIR = obj_$(TARGET) + + +ifeq ($(TARGET),) + -include Makefile.target + ifeq ($(TARGET),) + $(warning TARGET not defined, using netsim target) + TARGET=netsim + else + $(warning using saved target '$(TARGET)') + endif +endif + +usage: + @echo "make MAKETARGETS... [TARGET=(TARGET)] [savetarget]" + +savetarget: + -@rm -f Makefile.target + @echo >Makefile.target "TARGET = $(TARGET)" + +ifeq (${wildcard $(OBJECTDIR)},) +DUMMY := ${shell mkdir $(OBJECTDIR)} +endif + +SYSTEM = process.c procinit.c service.c autostart.c +THREADS = mt.c +LIBS = memb.c timer.c list.c etimer.c +CFS = cfs.c cfs-ram.c +CTK = ctk.c +UIP = uip.c uiplib.c resolv.c tcpip.c psock.c hc.c uip-split.c \ + uip-fw.c uip-fw-service.c uipbuf.c uip_arp.c uiplib.c tcpdump.c \ + uip-neighbor.c +NET = $(UIP) uaodv.c uaodv-rt.c + +CTKVNC = $(CTK) ctk-vncserver.c libconio.c vnc-server.c vnc-out.c \ + ctk-vncfont.c +CTKTERM = $(CTK) libconio.c ctk-term.c ctk-term-in.c ctk-term-out.c \ + ctk-termtelnet.c + +CONTIKIFILES = $(SYSTEM) $(THREADS) $(CFS) $(LIBS) $(NET) $(DHCP) + +CONTIKI_SOURCEFILES += $(CONTIKIFILES) + +# contiki.a: ${addprefix $(OBJECTDIR)/, $(CONTIKIFILES:.c=.o)} +# @$(AR) rcf $@ $^ + +# contikiapps.a: ${addprefix $(OBJECTDIR)/, $(APPSFILES:.c=.o)} +# @$(AR) rcf $@ $^ + +CONTIKIDIRS = ${addprefix $(CONTIKI)/core/,dev lib net sys \ + cfs ctk lib/ctk loader . } +#APPDIRS += ${filter-out $(CONTIKI)/apps/CVS,${wildcard ${addprefix $(CONTIKI)/,apps/*}}} + +PROJECT_OBJECTFILES = ${addprefix $(OBJECTDIR)/,$(PROJECT_SOURCEFILES:.c=.o)} + +### Include application makefiles + +ifdef APPS + APPDIRS += $(addprefix $(CONTIKI)/apps/, $(APPS)) + APPINCLUDES = $(foreach APP, $(APPS), $(CONTIKI)/apps/$(APP)/Makefile.$(APP)) + -include $(APPINCLUDES) + CONTIKI_SOURCEFILES += $(APP_SOURCES) $(DSC_SOURCES) +endif + +### Include target makefile (TODO Unsafe?) +include $(CONTIKI)/platform/$(TARGET)/Makefile.$(TARGET) + +### Automatic dependency generation + +ifneq ($(MAKECMDGOALS),clean) +-include $(addprefix $(OBJECTDIR)/,$(CONTIKI_SOURCEFILES:.c=.d) \ + $(PROJECT_SOURCEFILES:.c=.d)) +endif + + +clean: + rm -f *~ *core core *.srec node-id.c \ + *.lst *.map \ + *.cprg *.bin *.data contiki*.a *.firmware core-labels.S *.ihex *.ini \ + *.ce *.co + -rm -rf $(OBJECTDIR) + +%.ce: %.c + $(CC) $(CFLAGS) -DAUTOSTART_ENABLE -c $< -o $@ + $(STRIP) --strip-unneeded -g -x $@ + +$(OBJECTDIR)/%.o: %.c + $(CC) $(CFLAGS) -c $< -o $@ + +%.o: %.c + $(CC) $(CFLAGS) -c $< -o $@ + +%.co: %.c + $(CC) $(CFLAGS) -DAUTOSTART_ENABLE -c $< -o $@ + +contiki-$(TARGET).a: ${addprefix $(OBJECTDIR)/, $(CONTIKI_SOURCEFILES:.c=.o)} + $(AR) rcf $@ $^ + + +ifndef CCDEP + CCDEP = $(CC) +endif +ifndef CDEPFLAGS + CDEPFLAGS = $(CFLAGS) +endif + +$(OBJECTDIR)/%.d: %.c + @set -e; rm -f $@; \ + $(CCDEP) -MM $(CDEPFLAGS) $< > $@.$$$$; \ + sed 's,\($*\)\.o[ :]*,$(OBJECTDIR)/\1.o $@ : ,g' < $@.$$$$ > $@; \ + rm -f $@.$$$$ + + +# The line below is needed so that GNU make does not remove the +# generated file. +.PRECIOUS: %.$(TARGET) + +%.$(TARGET): %.co $(PROJECT_OBJECTFILES) contiki-$(TARGET).a + $(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(filter-out %.a,$^) $(filter %.a,$^) + +# The target below looks weird, but I had to add the @ to avoid complaints +# from GNU make about "*** No rule to make target `XXX'. Stop." +%: %.$(TARGET) + @ diff --git a/apps/about/Makefile.about b/apps/about/Makefile.about new file mode 100644 index 000000000..dc13c3834 --- /dev/null +++ b/apps/about/Makefile.about @@ -0,0 +1,2 @@ +APP_SOURCES += about.c +DSC_SOURCES += about-dsc.c \ No newline at end of file diff --git a/apps/about/about-dsc.c b/apps/about/about-dsc.c new file mode 100644 index 000000000..132a28e37 --- /dev/null +++ b/apps/about/about-dsc.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2003, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the Contiki desktop environment + * + * $Id: about-dsc.c,v 1.1 2006/06/17 22:41:10 adamdunkels Exp $ + * + */ + +#include "sys/dsc.h" + +extern struct ctk_icon about_icon; +/*-----------------------------------------------------------------------------------*/ +DSC(about_dsc, + "About Contiki", + "about.prg", + about_process, + &about_icon); +/*-----------------------------------------------------------------------------------*/ +#if CTK_CONF_ICON_BITMAPS +static unsigned char abouticon_bitmap[3*3*8] = { + 0x00, 0x7f, 0x43, 0x4c, 0x58, 0x53, 0x60, 0x6f, + 0x00, 0xff, 0x00, 0x7e, 0x00, 0xff, 0x00, 0xff, + 0x00, 0xfe, 0xc2, 0x32, 0x1a, 0xca, 0x06, 0xf6, + + 0x40, 0x5f, 0x40, 0x5f, 0x40, 0x5f, 0x40, 0x4f, + 0x00, 0xff, 0x00, 0xff, 0x00, 0xfc, 0x01, 0xf3, + 0x02, 0xfa, 0x02, 0x82, 0x3e, 0xfe, 0xfe, 0xfe, + + 0x60, 0x67, 0x50, 0x59, 0x4c, 0x43, 0x7f, 0x00, + 0x07, 0xe7, 0x0f, 0xef, 0x0f, 0x0f, 0xff, 0x00, + 0x8e, 0x06, 0x06, 0x06, 0x8e, 0xfe, 0xfe, 0x00 +}; +#endif /* CTK_CONF_ICON_BITMAPS */ + +#if CTK_CONF_ICON_TEXTMAPS +static char abouticon_textmap[9] = { + ' ', ' ', 'c', + ' ', '?', ' ', + '.', ' ', ' ' +}; +#endif /* CTK_CONF_ICON_TEXTMAPS */ + +#if CTK_CONF_ICONS +static struct ctk_icon about_icon = + {CTK_ICON("About Contiki", abouticon_bitmap, abouticon_textmap)}; +#endif /* CTK_CONF_ICONS */ +/*-----------------------------------------------------------------------------------*/ diff --git a/apps/about/about-dsc.h b/apps/about/about-dsc.h new file mode 100644 index 000000000..f592a69d2 --- /dev/null +++ b/apps/about/about-dsc.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2003, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the Contiki desktop environment + * + * $Id: about-dsc.h,v 1.1 2006/06/17 22:41:10 adamdunkels Exp $ + * + */ +#ifndef __ABOUT_DSC_H__ +#define __ABOUT_DSC_H__ + +#include "sys/dsc.h" + +DSC_HEADER(about_dsc); + +#endif /* __ABOUT_DSC_H__ */ diff --git a/apps/about/about.c b/apps/about/about.c new file mode 100644 index 000000000..d23da30f8 --- /dev/null +++ b/apps/about/about.c @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2002, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the Contiki desktop environment + * + * $Id: about.c,v 1.1 2006/06/17 22:41:10 adamdunkels Exp $ + * + */ + +#include + +#include "contiki.h" +#include "ctk/ctk.h" + +static struct ctk_window aboutdialog; +static struct ctk_label aboutlabel1 = + {CTK_LABEL(2, 0, 28, 1, "The Contiki Operating System")}; +static struct ctk_label aboutlabel2 = + {CTK_LABEL(3, 2, 28, 1, "A modern, Internet-enabled")}; +static struct ctk_label aboutlabel3 = + {CTK_LABEL(6, 3, 20, 1, "operating system and")}; +static struct ctk_label aboutlabel4 = + {CTK_LABEL(6, 4, 20, 1, "desktop environment.")}; + +static char abouturl_petscii[] = "http://www.sics.se/~adam/contiki/"; +static char abouturl_ascii[40]; +static struct ctk_hyperlink abouturl = + {CTK_HYPERLINK(0, 6, 32, "http://www.sics.se/~adam/contiki/", + abouturl_ascii)}; +static struct ctk_button aboutclose = + {CTK_BUTTON(12, 8, 5, "Close")}; + + +PROCESS(about_process, "About Contiki"); + +/*-----------------------------------------------------------------------------------*/ +static void +about_quit(void) +{ + ctk_dialog_close(); + process_exit(&about_process); + LOADER_UNLOAD(); +} +/*-----------------------------------------------------------------------------------*/ +PROCESS_THREAD(about_process, ev, data) +{ + unsigned char width; + + PROCESS_BEGIN(); + + width = ctk_desktop_width(NULL); + + strcpy(abouturl_ascii, abouturl_petscii); + petsciiconv_toascii(abouturl_ascii, sizeof(abouturl_ascii)); + + if(width > 34) { + ctk_dialog_new(&aboutdialog, 32, 9); + } else { + ctk_dialog_new(&aboutdialog, width - 2, 9); + } + CTK_WIDGET_ADD(&aboutdialog, &aboutlabel1); + CTK_WIDGET_ADD(&aboutdialog, &aboutlabel2); + CTK_WIDGET_ADD(&aboutdialog, &aboutlabel3); + CTK_WIDGET_ADD(&aboutdialog, &aboutlabel4); + if(width > 34) { + CTK_WIDGET_ADD(&aboutdialog, &abouturl); + CTK_WIDGET_SET_FLAG(&abouturl, CTK_WIDGET_FLAG_MONOSPACE); + } else { + CTK_WIDGET_SET_XPOS(&aboutlabel1, 0); + CTK_WIDGET_SET_XPOS(&aboutlabel2, 0); + CTK_WIDGET_SET_XPOS(&aboutlabel3, 0); + CTK_WIDGET_SET_XPOS(&aboutlabel4, 0); + + CTK_WIDGET_SET_XPOS(&aboutclose, 0); + } + CTK_WIDGET_ADD(&aboutdialog, &aboutclose); + CTK_WIDGET_FOCUS(&aboutdialog, &aboutclose); + + ctk_dialog_open(&aboutdialog); + + while(1) { + PROCESS_WAIT_EVENT(); + if(ev == PROCESS_EVENT_EXIT) { + about_quit(); + PROCESS_EXIT(); + } else if(ev == ctk_signal_button_activate) { + if(data == (process_data_t)&aboutclose) { + about_quit(); + PROCESS_EXIT(); + } + } else if(ev == ctk_signal_hyperlink_activate) { + if((struct ctk_widget *)data == (struct ctk_widget *)&abouturl) { + about_quit(); + PROCESS_EXIT(); + } + } + } + + PROCESS_END(); +} +/*-----------------------------------------------------------------------------------*/ diff --git a/apps/calc/Makefile.calc b/apps/calc/Makefile.calc new file mode 100644 index 000000000..a0f343611 --- /dev/null +++ b/apps/calc/Makefile.calc @@ -0,0 +1,2 @@ +APP_SOURCES += calc.c +DSC_SOURCES += calc-dsc.c \ No newline at end of file diff --git a/apps/calc/calc-dsc.c b/apps/calc/calc-dsc.c new file mode 100644 index 000000000..c233a066c --- /dev/null +++ b/apps/calc/calc-dsc.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2003, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the Contiki desktop environment + * + * $Id: calc-dsc.c,v 1.1 2006/06/17 22:41:10 adamdunkels Exp $ + * + */ + +#include "sys/dsc.h" + +extern struct ctk_icon calc_icon; +/*-----------------------------------------------------------------------------------*/ +DSC(calc_dsc, + "Simple calculator", + "calc.prg", + calc_process, + &calc_icon); +/*-----------------------------------------------------------------------------------*/ +#if CTK_CONF_ICON_BITMAPS +static unsigned char calcicon_bitmap[3*3*8] = { + 0x00, 0x7f, 0x43, 0x4c, 0x58, 0x53, 0x60, 0x6f, + 0x00, 0xff, 0x00, 0x7e, 0x00, 0xff, 0x00, 0xff, + 0x00, 0xfe, 0xc2, 0x32, 0x1a, 0xca, 0x06, 0xf6, + + 0x40, 0x5f, 0x40, 0x5f, 0x40, 0x5f, 0x40, 0x4f, + 0x00, 0xff, 0x00, 0xff, 0x00, 0xfc, 0x01, 0xf3, + 0x02, 0xfa, 0x02, 0x82, 0x3e, 0xfe, 0xfe, 0xfe, + + 0x60, 0x67, 0x50, 0x59, 0x4c, 0x43, 0x7f, 0x00, + 0x07, 0xe7, 0x0f, 0xef, 0x0f, 0x0f, 0xff, 0x00, + 0x8e, 0x06, 0x06, 0x06, 0x8e, 0xfe, 0xfe, 0x00 +}; +#endif /* CTK_CONF_ICON_BITMAPS */ + +#if CTK_CONF_ICON_TEXTMAPS +static char calcicon_textmap[9] = { + '+', ' ', '-', + ' ', '*', ' ', + '=', ' ', '/' +}; +#endif /* CTK_CONF_ICON_TEXTMAPS */ + +#if CTK_CONF_ICONS +static struct ctk_icon calc_icon = + {CTK_ICON("Calculator", calcicon_bitmap, calcicon_textmap)}; +#endif /* CTK_CONF_ICONS */ +/*-----------------------------------------------------------------------------------*/ diff --git a/apps/calc/calc-dsc.h b/apps/calc/calc-dsc.h new file mode 100644 index 000000000..98f414737 --- /dev/null +++ b/apps/calc/calc-dsc.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2003, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the Contiki desktop environment + * + * $Id: calc-dsc.h,v 1.1 2006/06/17 22:41:10 adamdunkels Exp $ + * + */ +#ifndef __CALC_DSC_H__ +#define __CALC_DSC_H__ + +#include "sys/dsc.h" + +DSC_HEADER(calc_dsc); + +#endif /* __CALC_DSC_H__ */ diff --git a/apps/calc/calc.c b/apps/calc/calc.c new file mode 100644 index 000000000..8f8fa50f1 --- /dev/null +++ b/apps/calc/calc.c @@ -0,0 +1,293 @@ +/* + * Copyright (c) 2003, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This an example program for the Contiki desktop OS + * + * $Id: calc.c,v 1.1 2006/06/17 22:41:10 adamdunkels Exp $ + * + */ + +#include "contiki.h" +#include "ctk/ctk.h" + +static struct ctk_window window; + +static char input[16]; +static struct ctk_label inputlabel = + {CTK_LABEL(0, 0, 12, 1, input)}; + +static struct ctk_button button7 = + {CTK_BUTTON(0, 3, 1, "7")}; +static struct ctk_button button8 = + {CTK_BUTTON(3, 3, 1, "8")}; +static struct ctk_button button9 = + {CTK_BUTTON(6, 3, 1, "9")}; +static struct ctk_button button4 = + {CTK_BUTTON(0, 4, 1, "4")}; +static struct ctk_button button5 = + {CTK_BUTTON(3, 4, 1, "5")}; +static struct ctk_button button6 = + {CTK_BUTTON(6, 4, 1, "6")}; +static struct ctk_button button1 = + {CTK_BUTTON(0, 5, 1, "1")}; +static struct ctk_button button2 = + {CTK_BUTTON(3, 5, 1, "2")}; +static struct ctk_button button3 = + {CTK_BUTTON(6, 5, 1, "3")}; +static struct ctk_button button0 = + {CTK_BUTTON(0, 6, 3, " 0 ")}; + +static struct ctk_button cbutton = + {CTK_BUTTON(0, 2, 1, "C")}; + +static struct ctk_button divbutton = + {CTK_BUTTON(9, 2, 1, "/")}; +static struct ctk_button mulbutton = + {CTK_BUTTON(9, 3, 1, "*")}; + +static struct ctk_button subbutton = + {CTK_BUTTON(9, 4, 1, "-")}; +static struct ctk_button addbutton = + {CTK_BUTTON(9, 5, 1, "+")}; +static struct ctk_button calcbutton = + {CTK_BUTTON(9, 6, 1, "=")}; + +PROCESS(calc_process, "Calculator"); + +static unsigned long operand1, operand2; +static unsigned char op; +#define OP_ADD 1 +#define OP_SUB 2 +#define OP_MUL 3 +#define OP_DIV 4 + +/*-----------------------------------------------------------------------------------*/ +static void +calc_quit(void) +{ + process_exit(&calc_process); + LOADER_UNLOAD(); +} +/*-----------------------------------------------------------------------------------*/ +static void +add_to_input(char c) +{ + unsigned char i; + + for(i = 0; i < 11; ++i) { + input[i] = input[i + 1]; + } + input[11] = c; +} +/*-----------------------------------------------------------------------------------*/ +static void +clear_input(void) +{ + unsigned char i; + + for(i = 0; i < sizeof(input); ++i) { + input[i] = ' '; + } +} +/*-----------------------------------------------------------------------------------*/ +static void +input_to_operand1(void) +{ + unsigned int m; + unsigned char i; + + operand1 = 0; + for(m = 1, i = 11; + i > 7; --i, m *= 10) { + if(input[i] >= '0' && + input[i] <= '9') { + operand1 += (input[i] - '0') * m; + } + } + clear_input(); +} +/*-----------------------------------------------------------------------------------*/ +static void +operand2_to_input(void) +{ + unsigned char i; + + input[7] = (operand2/10000) % 10 + '0'; + input[8] = (operand2/1000) % 10 + '0'; + input[9] = (operand2/100) % 10 + '0'; + input[10] = (operand2/10) % 10 + '0'; + input[11] = operand2 % 10 + '0'; + + for(i = 0; i < 4; ++i) { + if(input[7 + i] == '0') { + input[7 + i] = ' '; + } else { + break; + } + } +} +/*-----------------------------------------------------------------------------------*/ +static void +calculate(void) +{ + operand2 = operand1; + input_to_operand1(); + switch(op) { + case OP_ADD: + operand2 = operand2 + operand1; + break; + case OP_SUB: + operand2 = operand2 - operand1; + break; + case OP_MUL: + operand2 = operand2 * operand1; + break; + case OP_DIV: + operand2 = operand2 / operand1; + break; + } + operand2_to_input(); +} +/*-----------------------------------------------------------------------------------*/ +PROCESS_THREAD(calc_process, ev, data) +{ + PROCESS_BEGIN(); + + ctk_window_new(&window, 12, 7, "Calc"); + + CTK_WIDGET_ADD(&window, &inputlabel); + CTK_WIDGET_SET_FLAG(&inputlabel, CTK_WIDGET_FLAG_MONOSPACE); + + CTK_WIDGET_ADD(&window, &cbutton); + + CTK_WIDGET_ADD(&window, &divbutton); + + CTK_WIDGET_ADD(&window, &button7); + CTK_WIDGET_ADD(&window, &button8); + CTK_WIDGET_ADD(&window, &button9); + + CTK_WIDGET_ADD(&window, &mulbutton); + + + + CTK_WIDGET_ADD(&window, &button4); + CTK_WIDGET_ADD(&window, &button5); + CTK_WIDGET_ADD(&window, &button6); + + CTK_WIDGET_ADD(&window, &subbutton); + + CTK_WIDGET_ADD(&window, &button1); + CTK_WIDGET_ADD(&window, &button2); + CTK_WIDGET_ADD(&window, &button3); + + CTK_WIDGET_ADD(&window, &addbutton); + + CTK_WIDGET_ADD(&window, &button0); + + CTK_WIDGET_ADD(&window, &calcbutton); + + clear_input(); + + ctk_window_open(&window); + + while(1) { + + PROCESS_WAIT_EVENT(); + + if(ev == ctk_signal_keypress) { + if((char)data >= '0' && + (char)data <= '9') { + add_to_input((char)data); + } else if((char)data == ' ') { + clear_input(); + } else if((char)data == '+') { + input_to_operand1(); + op = OP_ADD; + } else if((char)data == '-') { + input_to_operand1(); + op = OP_SUB; + } else if((char)data == '*') { + input_to_operand1(); + op = OP_MUL; + } else if((char)data == '/') { + input_to_operand1(); + op = OP_DIV; + } else if((char)data == '=' || + (char)data == CH_ENTER) { + calculate(); + } + + CTK_WIDGET_REDRAW(&inputlabel); + } else if(ev == ctk_signal_button_activate) { + if(data == (process_data_t)&button0) { + add_to_input('0'); + } else if(data == (process_data_t)&button1) { + add_to_input('1'); + } else if(data == (process_data_t)&button2) { + add_to_input('2'); + } else if(data == (process_data_t)&button3) { + add_to_input('3'); + } else if(data == (process_data_t)&button4) { + add_to_input('4'); + } else if(data == (process_data_t)&button5) { + add_to_input('5'); + } else if(data == (process_data_t)&button6) { + add_to_input('6'); + } else if(data == (process_data_t)&button7) { + add_to_input('7'); + } else if(data == (process_data_t)&button8) { + add_to_input('8'); + } else if(data == (process_data_t)&button9) { + add_to_input('9'); + } else if(data == (process_data_t)&cbutton) { + clear_input(); + } else if(data == (process_data_t)&calcbutton) { + calculate(); + } else if(data == (process_data_t)&addbutton) { + input_to_operand1(); + op = OP_ADD; + } else if(data == (process_data_t)&subbutton) { + input_to_operand1(); + op = OP_SUB; + } else if(data == (process_data_t)&mulbutton) { + input_to_operand1(); + op = OP_MUL; + } else if(data == (process_data_t)&divbutton) { + input_to_operand1(); + op = OP_DIV; + } + CTK_WIDGET_REDRAW(&inputlabel); + } else if(ev == ctk_signal_window_close && + data == (process_data_t)&window) { + calc_quit(); + } + } + PROCESS_END(); +} +/*-----------------------------------------------------------------------------------*/ diff --git a/apps/cmdd/Makefile.cmdd b/apps/cmdd/Makefile.cmdd new file mode 100644 index 000000000..8b36f8e65 --- /dev/null +++ b/apps/cmdd/Makefile.cmdd @@ -0,0 +1,2 @@ +APP_SOURCES += cmdd.c +DSC_SOURCES += \ No newline at end of file diff --git a/apps/cmdd/cmdd.c b/apps/cmdd/cmdd.c new file mode 100644 index 000000000..8c0fb9c40 --- /dev/null +++ b/apps/cmdd/cmdd.c @@ -0,0 +1,168 @@ +#include "contiki.h" +#include "psock.h" +#include "memb.h" + +#include + +struct cmdd_state { + struct psock s; + char inputbuf[8]; + struct timer timer; + int i; + char command; +}; + +#define COMMAND_NONE 0 +#define COMMAND_PS 1 + +MEMB(conns, struct cmdd_state, 1); + +PROCESS(cmdd_process, "Command server"); + +static struct uip_udp_conn *udpconn; +static char send_udp = 0; +static const char *prompt = "contiki> "; + +/*---------------------------------------------------------------------------*/ +static char * CC_FASTCALL +n(u16_t num, char *ptr) +{ + u16_t d; + u8_t a, f; + + if(num == 0) { + *ptr = '0'; + return ptr + 1; + } else { + f = 0; + for(d = 10000; d >= 1; d /= 10) { + a = (num / d) % 10; + if(f == 1 || a > 0) { + *ptr = a + '0'; + ++ptr; + f = 1; + } + } + } + return ptr; +} +/*---------------------------------------------------------------------------*/ +static unsigned short +ps_generate(void *state) +{ + struct ek_proc *p = (struct ek_proc *)state; + char *ptr = (char *)uip_appdata; + + ptr = n(EK_PROC_ID(p), ptr); + + *ptr++ = ' '; + strncpy(ptr, p->name, 40); + ptr += strlen(p->name); + *ptr++ = '\n'; + + return ptr - (char *)uip_appdata; +} +/*---------------------------------------------------------------------------*/ +static +PT_THREAD(handle_connection(struct cmdd_state *s)) +{ + PSOCK_BEGIN(&s->s); + + while(1) { + PSOCK_SEND(&s->s, prompt, strlen(prompt)); + PSOCK_WAIT_UNTIL(&s->s, PSOCK_NEWDATA(&s->s) || + s->command != COMMAND_NONE); + + if(PSOCK_NEWDATA(&s->s)) { + PSOCK_READTO(&s->s, '\n'); + if(strncmp(s->inputbuf, "quit", 4) == 0) { + PSOCK_CLOSE_EXIT(&s->s); + memb_free(&conns, s); + tcp_markconn(uip_conn, NULL); + } else if(strncmp(s->inputbuf, "ps", 2) == 0) { + PSOCK_GENERATOR_SEND(&s->s, ps_generate, ek_procs); + + for(s->i = 0; s->i < 40; s->i++) { + if(ek_process(s->i) != NULL) { + PSOCK_GENERATOR_SEND(&s->s, ps_generate, ek_process(s->i)); + } + } + } else if(strncmp(s->inputbuf, "send", 4) == 0) { + send_udp = 1; + PSOCK_WAIT_UNTIL(&s->s, send_udp == 0); + } else { + PSOCK_SEND(&s->s, "?\n", 2); + } + } else { + switch(s->command) { + } + } + + } + PSOCK_END(&s->s); +} +/*---------------------------------------------------------------------------*/ +static void +appcall(void *state) +{ + struct cmdd_state *s = (struct cmdd_state *)state; + + if(uip_udpconnection()) { + if(send_udp) { + uip_udp_send(8); + send_udp = 0; + } + } else { + if(uip_closed() || uip_timedout() || uip_aborted()) { + if(state != NULL) { + memb_free(&conns, state); + } + } else if(uip_connected()) { + s = (struct cmdd_state *)memb_alloc(&conns); + if(s == NULL) { + uip_abort(); + } else { + tcp_markconn(uip_conn, s); + PSOCK_INIT(&s->s, s->inputbuf, sizeof(s->inputbuf) - 1); + timer_set(&s->timer, CLOCK_SECOND * 60); + handle_connection(s); + } + } else if(s != NULL) { + if(uip_poll()) { + if(timer_expired(&s->timer)) { + memb_free(&conns, state); + uip_abort(); + return; + } + } + timer_reset(&s->timer); + handle_connection(s); + } else { + uip_abort(); + } + } +} +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(cmdd_process, ev, data) +{ + u16_t ipaddr[2]; + + PROCESS_BEGIN(); + + tcp_listen(HTONS(6581)); + memb_init(&conns); + uip_ipaddr(ipaddr, 255,255,255,255); + udpconn = udp_new(ipaddr, HTONS(6712), NULL); + + while(1) { + PROCESS_WAIT_EVENT(); + if(ev == tcpip_event) { + appcall(data); + } else if(ev == PROCESS_EVENT_EXIT) { + process_exit(&cmdd_process); + LOADER_UNLOAD(); + } + } + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/ diff --git a/apps/cmdd/cmdd.h b/apps/cmdd/cmdd.h new file mode 100644 index 000000000..7543c9140 --- /dev/null +++ b/apps/cmdd/cmdd.h @@ -0,0 +1,10 @@ +#ifndef __CMDD_H__ +#define __CMDD_H__ + +#include "contiki.h" + +/*EK_PROCESS_INIT(cmdd_init, arg);*/ + +PROCESS_NAME(cmdd_process); + +#endif /* __CMDD_H__ */ diff --git a/apps/dhcp/Makefile.dhcp b/apps/dhcp/Makefile.dhcp new file mode 100644 index 000000000..b205fb160 --- /dev/null +++ b/apps/dhcp/Makefile.dhcp @@ -0,0 +1,2 @@ +APP_SOURCES += dhcp.c dhcpc.c +DSC_SOURCES += dhcp-dsc.c \ No newline at end of file diff --git a/apps/dhcp/dhcp-dsc.c b/apps/dhcp/dhcp-dsc.c new file mode 100644 index 000000000..9c18bb5fa --- /dev/null +++ b/apps/dhcp/dhcp-dsc.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2003, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the Contiki desktop environment + * + * $Id: dhcp-dsc.c,v 1.1 2006/06/17 22:41:10 adamdunkels Exp $ + * + */ + +#include "sys/dsc.h" + +extern struct ctk_icon dhcp_icon; +/*-----------------------------------------------------------------------------------*/ +DSC(dhcp_dsc, + "Obtain IP address automatically", + "dhcp.prg", + dhcp_process, + &dhcp_icon); +/*-----------------------------------------------------------------------------------*/ +#if CTK_CONF_ICON_BITMAPS +static unsigned char tcpipconficon_bitmap[3*3*8] = { + 0x00, 0x79, 0x43, 0x73, 0x47, 0x77, 0x47, 0x6f, + 0x00, 0xfe, 0xfe, 0xfc, 0xfc, 0xfc, 0xf8, 0xfb, + 0x00, 0x16, 0x02, 0x00, 0x02, 0x00, 0x00, 0xc2, + + 0x48, 0x4c, 0x5f, 0x5f, 0x1f, 0x3f, 0x3f, 0x03, + 0x79, 0xf0, 0xf0, 0xf0, 0xe0, 0xe0, 0xfe, 0xfc, + 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + + 0x77, 0x47, 0x70, 0x43, 0x79, 0x41, 0x7c, 0x00, + 0xfc, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xf7, 0x00, + 0x00, 0x80, 0x00, 0x00, 0x00, 0x84, 0xf0, 0x00 +}; +#endif /* CTK_CONF_ICON_BITMAPS */ + +#if CTK_CONF_ICON_TEXTMAPS +static char tcpipconficon_textmap[9] = { + 'T', 'C', 'P', + '/', 'I', 'P', + 'C', 'f', 'g' +}; +#endif /* CTK_CONF_ICON_TEXTMAPS */ + +#if CTK_CONF_ICONS +static struct ctk_icon dhcp_icon = + {CTK_ICON("DHCP client", tcpipconficon_bitmap, tcpipconficon_textmap)}; +#endif /* CTK_CONF_ICONS */ +/*-----------------------------------------------------------------------------------*/ diff --git a/apps/dhcp/dhcp-dsc.h b/apps/dhcp/dhcp-dsc.h new file mode 100644 index 000000000..e52d30758 --- /dev/null +++ b/apps/dhcp/dhcp-dsc.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2003, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the Contiki desktop environment + * + * $Id: dhcp-dsc.h,v 1.1 2006/06/17 22:41:10 adamdunkels Exp $ + * + */ +#ifndef __DHCP_DSC_H__ +#define __DHCP_DSC_H__ + +#include "sys/dsc.h" + +DSC_HEADER(dhcp_dsc); + +#endif /* __DHCP_DSC_H__ */ diff --git a/apps/dhcp/dhcp.c b/apps/dhcp/dhcp.c new file mode 100644 index 000000000..c026a5760 --- /dev/null +++ b/apps/dhcp/dhcp.c @@ -0,0 +1,153 @@ +#include "contiki-net.h" +#include "ctk/ctk.h" +#include "net/dhcpc.h" + + + +PROCESS(dhcp_process, "DHCP"); + +static struct ctk_window window; +static struct ctk_button getbutton = + {CTK_BUTTON(0, 0, 16, "Request address")}; +static struct ctk_label statuslabel = + {CTK_LABEL(0, 1, 16, 1, "")}; + + +static struct ctk_label ipaddrlabel = + {CTK_LABEL(0, 3, 10, 1, "IP address")}; +static char ipaddr[17]; +static struct ctk_textentry ipaddrentry = + {CTK_LABEL(11, 3, 16, 1, ipaddr)}; +static struct ctk_label netmasklabel = + {CTK_LABEL(0, 4, 10, 1, "Netmask")}; +static char netmask[17]; +static struct ctk_textentry netmaskentry = + {CTK_LABEL(11, 4, 16, 1, netmask)}; +static struct ctk_label gatewaylabel = + {CTK_LABEL(0, 5, 10, 1, "Gateway")}; +static char gateway[17]; +static struct ctk_textentry gatewayentry = + {CTK_LABEL(11, 5, 16, 1, gateway)}; +static struct ctk_label dnsserverlabel = + {CTK_LABEL(0, 6, 10, 1, "DNS server")}; +static char dnsserver[17]; +static struct ctk_textentry dnsserverentry = + {CTK_LABEL(11, 6, 16, 1, dnsserver)}; + +enum { + SHOWCONFIG +}; +/*---------------------------------------------------------------------------*/ +static void +set_statustext(char *text) +{ + ctk_label_set_text(&statuslabel, text); + CTK_WIDGET_REDRAW(&statuslabel); +} +/*---------------------------------------------------------------------------*/ +static char * +makebyte(u8_t byte, char *str) +{ + if(byte >= 100) { + *str++ = (byte / 100 ) % 10 + '0'; + } + if(byte >= 10) { + *str++ = (byte / 10) % 10 + '0'; + } + *str++ = (byte % 10) + '0'; + + return str; +} +/*---------------------------------------------------------------------------*/ +static void +makeaddr(u16_t *addr, char *str) +{ + str = makebyte(HTONS(addr[0]) >> 8, str); + *str++ = '.'; + str = makebyte(HTONS(addr[0]) & 0xff, str); + *str++ = '.'; + str = makebyte(HTONS(addr[1]) >> 8, str); + *str++ = '.'; + str = makebyte(HTONS(addr[1]) & 0xff, str); + *str++ = 0; +} +/*---------------------------------------------------------------------------*/ +static void +makestrings(void) +{ + u16_t addr[2], *addrptr; + + uip_gethostaddr(addr); + makeaddr(addr, ipaddr); + + uip_getnetmask(addr); + makeaddr(addr, netmask); + + uip_getdraddr(addr); + makeaddr(addr, gateway); + + addrptr = resolv_getserver(); + if(addrptr != NULL) { + makeaddr(addrptr, dnsserver); + } + +} +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(dhcp_process, ev, data) +{ + PROCESS_BEGIN(); + + ctk_window_new(&window, 28, 7, "DHCP"); + + CTK_WIDGET_ADD(&window, &getbutton); + CTK_WIDGET_ADD(&window, &statuslabel); + CTK_WIDGET_ADD(&window, &ipaddrlabel); + CTK_WIDGET_ADD(&window, &ipaddrentry); + CTK_WIDGET_ADD(&window, &netmasklabel); + CTK_WIDGET_ADD(&window, &netmaskentry); + CTK_WIDGET_ADD(&window, &gatewaylabel); + CTK_WIDGET_ADD(&window, &gatewayentry); + CTK_WIDGET_ADD(&window, &dnsserverlabel); + CTK_WIDGET_ADD(&window, &dnsserverentry); + + CTK_WIDGET_FOCUS(&window, &getbutton); + + ctk_window_open(&window); + dhcpc_init(uip_ethaddr.addr, sizeof(uip_ethaddr.addr)); + + + while(1) { + PROCESS_WAIT_EVENT(); + + if(ev == ctk_signal_widget_activate) { + if(data == (process_data_t)&getbutton) { + dhcpc_request(); + set_statustext("Requesting..."); + } + } else if(ev == tcpip_event) { + dhcpc_appcall(ev, data); + } else if(ev == PROCESS_EVENT_EXIT || + ev == ctk_signal_window_close) { + ctk_window_close(&window); + process_exit(&dhcp_process); + LOADER_UNLOAD(); + } else if(ev == SHOWCONFIG) { + makestrings(); + ctk_window_redraw(&window); + } + } + + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/ +void +dhcpc_configured(const struct dhcpc_state *s) +{ + uip_sethostaddr(s->ipaddr); + uip_setnetmask(s->netmask); + uip_setdraddr(s->default_router); + resolv_conf(s->dnsaddr); + set_statustext("Configured."); + process_post(PROCESS_CURRENT(), SHOWCONFIG, NULL); +} +/*---------------------------------------------------------------------------*/ diff --git a/apps/dhcp/dhcp.h b/apps/dhcp/dhcp.h new file mode 100644 index 000000000..e69de29bb diff --git a/apps/directory/Makefile.directory b/apps/directory/Makefile.directory new file mode 100644 index 000000000..e74993f3f --- /dev/null +++ b/apps/directory/Makefile.directory @@ -0,0 +1,2 @@ +APP_SOURCES += directory.c +DSC_SOURCES += directory-dsc.c \ No newline at end of file diff --git a/apps/directory/directory-dsc.c b/apps/directory/directory-dsc.c new file mode 100644 index 000000000..ccc8da794 --- /dev/null +++ b/apps/directory/directory-dsc.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2003, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the Contiki desktop environment + * + * $Id: directory-dsc.c,v 1.1 2006/06/17 22:41:10 adamdunkels Exp $ + * + */ + +#include "sys/dsc.h" + +extern struct ctk_icon directory_icon; +/*-----------------------------------------------------------------------------------*/ +DSC(directory_dsc, + "Directory reader", + "directory.prg", + directory_process, + &directory_icon); +/*-----------------------------------------------------------------------------------*/ +#if CTK_CONF_ICON_BITMAPS +static unsigned char directoryicon_bitmap[3*3*8] = { + 0x00, 0x7f, 0x43, 0x4c, 0x58, 0x53, 0x60, 0x6f, + 0x00, 0xff, 0x00, 0x7e, 0x00, 0xff, 0x00, 0xff, + 0x00, 0xfe, 0xc2, 0x32, 0x1a, 0xca, 0x06, 0xf6, + + 0x40, 0x5f, 0x40, 0x5f, 0x40, 0x5f, 0x40, 0x4f, + 0x00, 0xff, 0x00, 0xff, 0x00, 0xfc, 0x01, 0xf3, + 0x02, 0xfa, 0x02, 0x82, 0x3e, 0xfe, 0xfe, 0xfe, + + 0x60, 0x67, 0x50, 0x59, 0x4c, 0x43, 0x7f, 0x00, + 0x07, 0xe7, 0x0f, 0xef, 0x0f, 0x0f, 0xff, 0x00, + 0x8e, 0x06, 0x06, 0x06, 0x8e, 0xfe, 0xfe, 0x00 +}; +#endif /* CTK_CONF_ICON_BITMAPS */ + +#if CTK_CONF_ICON_TEXTMAPS +static char directoryicon_textmap[9] = { + '+', '-', '+', + '|', 'o', '|', + '+', '-', '+' +}; +#endif /* CTK_CONF_ICON_TEXTMAPS */ + +#if CTK_CONF_ICONS +static struct ctk_icon directory_icon = + {CTK_ICON("Directory", directoryicon_bitmap, directoryicon_textmap)}; +#endif /* CTK_CONF_ICONS */ +/*-----------------------------------------------------------------------------------*/ diff --git a/apps/directory/directory-dsc.h b/apps/directory/directory-dsc.h new file mode 100644 index 000000000..60110d618 --- /dev/null +++ b/apps/directory/directory-dsc.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2003, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the Contiki desktop environment + * + * $Id: directory-dsc.h,v 1.1 2006/06/17 22:41:10 adamdunkels Exp $ + * + */ +#ifndef __DIRECTORY_DSC_H__ +#define __DIRECTORY_DSC_H__ + +#include "sys/dsc.h" + +DSC_HEADER(directory_dsc); + +#endif /* __DIRECTORY_DSC_H__ */ diff --git a/apps/directory/directory.c b/apps/directory/directory.c new file mode 100644 index 000000000..be1ce86b5 --- /dev/null +++ b/apps/directory/directory.c @@ -0,0 +1,308 @@ +/* + * Copyright (c) 2003, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the Contiki desktop environment + * + * $Id: directory.c,v 1.1 2006/06/17 22:41:10 adamdunkels Exp $ + * + */ + +#include +#include + +#include "contiki.h" +#include "cfs/cfs.h" +#include "ctk/ctk.h" + +#include "program-handler.h" + +#define FILENAMELEN 24 +#define MAX_NUMFILES 40 +#define WIDTH 36 +#define HEIGHT 22 + +static char (filenames[FILENAMELEN + 1])[MAX_NUMFILES]; +static struct dsc *dscs[MAX_NUMFILES]; +static unsigned char numfiles, morestart, filenameptr; + +static struct ctk_window window; + +static struct ctk_label description = + {CTK_LABEL(0, HEIGHT - 1, WIDTH, 1, "")}; + +static char autoexit = 1; +static struct ctk_button autoexitbutton = + {CTK_BUTTON(WIDTH/2 - 9, 20, 9, "Auto-exit")}; +static char autoexiton[] = "is On "; +static char autoexitoff[] = "is Off"; +static struct ctk_label autoexitlabel = + {CTK_LABEL(WIDTH/2 - 9 + 12, 20, 6, 1, autoexiton)}; + +static struct ctk_button morebutton = + {CTK_BUTTON(0, 20, 4, "More")}; + +static struct ctk_button backbutton = + {CTK_BUTTON(0, 20, 4, "Back")}; + +static struct ctk_button reloadbutton = + {CTK_BUTTON(30, 20, 6, "Reload")}; + +PROCESS(directory_process, "Directory browser"); + +static unsigned char width, height; + +#define LOADING_DIR 1 +#define LOADING_DSC 2 +static char loading = 0; +static struct cfs_dir dir; +/*-----------------------------------------------------------------------------------*/ +static void +show_statustext(char *text) +{ + ctk_label_set_text(&description, text); + CTK_WIDGET_REDRAW(&description); +} +/*-----------------------------------------------------------------------------------*/ +static void +startloading(void) +{ + if(cfs_opendir(&dir, "/") != 0) { + show_statustext("Cannot open directory"); + loading = 0; + } else { + loading = 1; + process_post(&directory_process, PROCESS_EVENT_CONTINUE, NULL); + numfiles = 0; + } +} +/*-----------------------------------------------------------------------------------*/ +static void +makewindow(unsigned char i) +{ + unsigned char x, y; + + ctk_window_clear(&window); + CTK_WIDGET_SET_YPOS(&description, height - 3); + CTK_WIDGET_SET_WIDTH(&description, width); + CTK_WIDGET_ADD(&window, &description); + + morestart = i; + + x = 0; y = 1; + for(; dscs[i] != NULL; ++i) { + + if(x + strlen(dscs[i]->icon->title) >= width) { + y += 5; + x = 0; + if(y >= height - 2 - 4) { + morestart = i; + break; + } + } + CTK_WIDGET_SET_XPOS(dscs[i]->icon, x); + CTK_WIDGET_SET_YPOS(dscs[i]->icon, y); + CTK_WIDGET_ADD(&window, dscs[i]->icon); + + x += strlen(dscs[i]->icon->title) + 2; + } + CTK_WIDGET_SET_YPOS(&autoexitbutton, height - 2); + CTK_WIDGET_ADD(&window, &autoexitbutton); + CTK_WIDGET_SET_YPOS(&autoexitlabel, height - 2); + CTK_WIDGET_ADD(&window, &autoexitlabel); + CTK_WIDGET_FOCUS(&window, &autoexitbutton); + + if(i != morestart) { + CTK_WIDGET_SET_YPOS(&backbutton, height - 1); + CTK_WIDGET_ADD(&window, &backbutton); + } else { + CTK_WIDGET_SET_YPOS(&morebutton, height - 1); + CTK_WIDGET_ADD(&window, &morebutton); + } + CTK_WIDGET_SET_XPOS(&reloadbutton, width - 8); + CTK_WIDGET_SET_YPOS(&reloadbutton, height - 1); + CTK_WIDGET_ADD(&window, &reloadbutton); +} +/*-----------------------------------------------------------------------------------*/ +static void +quit(void) +{ + unsigned char i; + + cfs_closedir(&dir); + ctk_window_close(&window); + for(i = 0; dscs[i] != NULL; ++i) { + LOADER_UNLOAD_DSC(dscs[i]); + } + process_exit(&directory_process); + LOADER_UNLOAD(); +} +/*-----------------------------------------------------------------------------------*/ +static void +read_dirent(void) +{ + static struct cfs_dirent dirent; + static char message[40]; + + if(loading == LOADING_DIR) { + if(cfs_readdir(&dir, &dirent)) { + cfs_closedir(&dir); + loading = LOADING_DSC; + filenameptr = 0; + } else if(strcasecmp(&dirent.name[strlen(dirent.name) - 4], ".dsc") == 0) { + strncpy(filenames[numfiles], dirent.name, FILENAMELEN); + ++numfiles; + if(numfiles == MAX_NUMFILES) { + cfs_closedir(&dir); + loading = LOADING_DSC; + filenameptr = 0; + return; + } + strcpy(message, "Found \""); + strcpy(message + 7, dirent.name); + strcpy(message + 7 + strlen(dirent.name), "\"..."); + show_statustext(message); + } + } +} +/*-----------------------------------------------------------------------------------*/ +static void +load_dirent(void) +{ + static char message[40]; + char *name; + + if(loading == LOADING_DSC) { + + name = filenames[filenameptr]; + dscs[filenameptr] = LOADER_LOAD_DSC(name); + if(dscs[filenameptr] == NULL || filenameptr + 1 >= numfiles) { + loading = 0; + makewindow(0); + show_statustext("Directory loaded"); + ctk_window_redraw(&window); + return; + } + ++filenameptr; + strcpy(message, "Loading \""); + strcpy(message + 9, name); + strcpy(message + 9 + strlen(name), "\"..."); + show_statustext(message); + } +} +/*-----------------------------------------------------------------------------------*/ +PROCESS_THREAD(directory_process, ev, data) +{ + unsigned char i; + + PROCESS_BEGIN(); + + width = ctk_draw_width() - 2; + height = ctk_draw_height() - 3; + + ctk_window_new(&window, width, height, "Directory"); + + /* loaddirectory();*/ + makewindow(0); + show_statustext("Loading directory..."); + startloading(); + + ctk_window_open(&window); + + while(1) { + PROCESS_WAIT_EVENT(); + if(ev == PROCESS_EVENT_CONTINUE) { + read_dirent(); + load_dirent(); + if(loading != 0) { + process_post(&directory_process, PROCESS_EVENT_CONTINUE, NULL); + } + } else if(ev == ctk_signal_widget_activate) { + if(data == (process_data_t)&reloadbutton) { + for(i = 0; dscs[i] != NULL; ++i) { + LOADER_UNLOAD_DSC(dscs[i]); + dscs[i] = NULL; + } + /* loaddirectory();*/ + startloading(); + makewindow(0); + ctk_window_open(&window); + } else if(data == (process_data_t)&morebutton) { + makewindow(morestart); + ctk_window_open(&window); + } else if(data == (process_data_t)&backbutton) { + makewindow(0); + ctk_window_open(&window); + } else if(data == (process_data_t)&autoexitbutton) { + autoexit = 1 - autoexit; + if(autoexit == 1) { + ctk_label_set_text(&autoexitlabel, autoexiton); + } else { + ctk_label_set_text(&autoexitlabel, autoexitoff); + } + CTK_WIDGET_REDRAW(&autoexitlabel); + } else { + for(i = 0; dscs[i] != NULL; ++i) { + if(data == (process_data_t)(dscs[i]->icon)) { + /* program_handler_load(dscs[i]->prgname, NULL);*/ + if(autoexit) { + ctk_window_close(&window); + quit(); + } + break; + } + } + } + } else if(ev == ctk_signal_widget_select) { + if(data == (process_data_t)&reloadbutton) { + show_statustext("Reload directory"); + } else if(data == (process_data_t)&morebutton) { + show_statustext("Show more files"); + } else if(data == (process_data_t)&backbutton) { + show_statustext("Show first files"); + } else if(data == (process_data_t)&autoexitbutton) { + show_statustext("Exit when loading program"); + } else { + for(i = 0; dscs[i] != NULL; ++i) { + if(data == (process_data_t)(dscs[i]->icon)) { + show_statustext(dscs[i]->description); + break; + } + } + } + } else if(ev == ctk_signal_window_close && + data == (process_data_t)&window) { + quit(); + } else if(ev == PROCESS_EVENT_EXIT) { + ctk_window_close(&window); + quit(); + } + } + PROCESS_END(); +} +/*-----------------------------------------------------------------------------------*/ diff --git a/apps/editor/Makefile.editor b/apps/editor/Makefile.editor new file mode 100644 index 000000000..9a514acc4 --- /dev/null +++ b/apps/editor/Makefile.editor @@ -0,0 +1,2 @@ +APP_SOURCES += editor.c memb.c ctk-filedialog.c +DSC_SOURCES += editor-dsc.c \ No newline at end of file diff --git a/apps/editor/editor-dsc.c b/apps/editor/editor-dsc.c new file mode 100644 index 000000000..057ada02a --- /dev/null +++ b/apps/editor/editor-dsc.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2004, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the Contiki desktop environment + * + * $Id: editor-dsc.c,v 1.1 2006/06/17 22:41:11 adamdunkels Exp $ + * + */ + +#include "sys/dsc.h" + +extern struct ctk_icon editor_icon; +/*-----------------------------------------------------------------------------------*/ +DSC(editor_dsc, + "A simple text editor", + "editor.prg", + editor_process, + &editor_icon); +/*-----------------------------------------------------------------------------------*/ +#if CTK_CONF_ICON_BITMAPS +static unsigned char editoricon_bitmap[3*3*8] = { + 0x00, 0x7e, 0x40, 0x73, 0x46, 0x4c, 0x18, 0x13, + 0x00, 0x00, 0xff, 0x81, 0x34, 0xc9, 0x00, 0xb6, + 0x00, 0x7e, 0x02, 0xce, 0x72, 0x32, 0x18, 0x48, + + 0x30, 0x27, 0x24, 0x20, 0x37, 0x24, 0x20, 0x33, + 0x00, 0x7b, 0x42, 0x00, 0x7b, 0x42, 0x00, 0x3b, + 0x0c, 0x24, 0x24, 0x04, 0xa4, 0x24, 0x04, 0x4c, + + 0x12, 0x19, 0x4c, 0x46, 0x63, 0x40, 0x7c, 0x00, + 0x22, 0x91, 0x00, 0xc4, 0x81, 0xff, 0x00, 0x00, + 0x08, 0x18, 0x32, 0x62, 0xc6, 0x02, 0x3e, 0x00 +}; +#endif /* CTK_CONF_ICON_BITMAPS */ + +#if CTK_CONF_ICON_TEXTMAPS +static char editoricon_textmap[9] = { + 't', 'x', 't', + 'e', 'd', 'i', + 't', 'o', 'r' +}; +#endif /* CTK_CONF_ICON_TEXTMAPS */ + +#if CTK_CONF_ICONS +static struct ctk_icon editor_icon = + {CTK_ICON("Editor", editoricon_bitmap, editoricon_textmap)}; +#endif /* CTK_CONF_ICONS */ +/*-----------------------------------------------------------------------------------*/ diff --git a/apps/editor/editor-dsc.h b/apps/editor/editor-dsc.h new file mode 100644 index 000000000..6716128e0 --- /dev/null +++ b/apps/editor/editor-dsc.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2004, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the Contiki desktop environment + * + * $Id: editor-dsc.h,v 1.1 2006/06/17 22:41:11 adamdunkels Exp $ + * + */ +#ifndef __EDITOR_DSC_H__ +#define __EDITOR_DSC_H__ + +#include "sys/dsc.h" + +DSC_HEADER(editor_dsc); + +#endif /* __EDITOR_DSC_H__ */ diff --git a/apps/editor/editor.c b/apps/editor/editor.c new file mode 100644 index 000000000..645b84d08 --- /dev/null +++ b/apps/editor/editor.c @@ -0,0 +1,338 @@ +/* + * Copyright (c) 2004, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the Contiki operating system. + * + * Author: Adam Dunkels + * + * $Id: editor.c,v 1.1 2006/06/17 22:41:11 adamdunkels Exp $ + */ +#define EDITOR_CONF_WIDTH 32 +#define EDITOR_CONF_HEIGHT 16 +#define EDITOR_CONF_MAX_FILENAME_LEN 16 + +#include "contiki.h" +#include "contiki-lib.h" +#include "ctk/ctk.h" +#include "cfs/cfs.h" + +#include "lib/ctk-filedialog.h" + +#define ISO_nl 0x0a + +PROCESS(editor_process, "Editor"); + +static struct ctk_window window; + +#define LINE_LEN 60 +#define NUM_LINES EDITOR_CONF_HEIGHT + +struct line { + struct line *next, *prev; + char text[LINE_LEN]; +}; +MEMB(linesmem, struct line, NUM_LINES); + +static struct line *lines; + +static struct { + unsigned char x, y; + struct ctk_label labels[NUM_LINES]; + +} editor_state; + +static struct ctk_button openbutton = + {CTK_BUTTON(0, 0, 4, "Open")}; +static char statustext[EDITOR_CONF_WIDTH + 1]; +static struct ctk_label statuslabel = + {CTK_LABEL(0, EDITOR_CONF_HEIGHT + 2, EDITOR_CONF_WIDTH, 1, statustext)}; + +static struct ctk_menu menu; +static unsigned char menuitem_new, menuitem_open, menuitem_save; + +static char filename[EDITOR_CONF_MAX_FILENAME_LEN]; + + +static struct ctk_filedialog_state filedialog; + +enum { + OPEN_EVENT +}; + +/*---------------------------------------------------------------------------*/ +static void +show_statustext(char *text1, char *text2) +{ + int len; + + len = strlen(text1); + if(len < sizeof(statustext)) { + strncpy(statustext, text1, sizeof(statustext)); + strncpy(statustext + len, text2, sizeof(statustext) - len); + CTK_WIDGET_REDRAW(&statuslabel); + } + +} +/*---------------------------------------------------------------------------*/ +static void +editor_start(void) +{ + unsigned char i; + register struct ctk_label *label; + struct line *l, *m; + + m = NULL; + + for(i = 0; i < NUM_LINES; ++i) { + label = &editor_state.labels[i]; + l = (struct line *)memb_alloc(&linesmem); + + if(l != NULL) { + l->next = NULL; + l->prev = m; + if(m == NULL) { + /* First line */ + lines = l; + } else { + m->next = l; + } + CTK_LABEL_NEW(label, 0, i + 1, EDITOR_CONF_WIDTH, 1, l->text); + CTK_WIDGET_SET_FLAG(label, CTK_WIDGET_FLAG_MONOSPACE); + CTK_WIDGET_ADD(&window, label); + } + m = l; + } +} +/*---------------------------------------------------------------------------*/ +static void +editor_eventhandler(process_event_t ev, process_data_t data) +{ + char *textptr, *textptr2; + unsigned char len; + + if(ev == ctk_signal_keypress) { + /* CTK_WIDGET_FOCUS(t->label.window, &t->label);*/ + textptr = &(editor_state.labels[editor_state.y].text[editor_state.x]); + *textptr &= 0x7f; + CTK_WIDGET_REDRAW(&(editor_state.labels[editor_state.y])); + + switch((ctk_arch_key_t)data) { + case CH_CURS_DOWN: + ++editor_state.y; + if(editor_state.y >= EDITOR_CONF_HEIGHT) { + editor_state.y = EDITOR_CONF_HEIGHT - 1; + } + break; + case CH_CURS_UP: + if(editor_state.y > 0) { + --editor_state.y; + } + break; + case CH_CURS_RIGHT: + if(editor_state.x < strlen(editor_state.labels[editor_state.y].text)) { + ++editor_state.x; + } + break; + case CH_CURS_LEFT: + if(editor_state.x > 0) { + --editor_state.x; + } else { + if(editor_state.y > 0) { + --editor_state.y; + editor_state.x = strlen(editor_state.labels[editor_state.y].text); + } + } + break; + case CH_ENTER: + editor_state.x = 0; + ++editor_state.y; + if(editor_state.y >= EDITOR_CONF_HEIGHT) { + editor_state.y = EDITOR_CONF_HEIGHT - 1; + } + break; + case CH_DEL: + /* len = t->label.w - t->xpos; + if(t->xpos > 0 && len > 0) { + strncpy(textptr - 1, textptr, + len); + *(textptr + len - 1) = 0; + --t->xpos; + }*/ + break; + default: + len = EDITOR_CONF_WIDTH - editor_state.x; + if(len > 0) { + textptr2 = textptr + len - 1; + while(textptr2 + 1 > textptr) { + *(textptr2 + 1) = *textptr2; + --textptr2; + } + + *textptr = (char)data; + ++editor_state.x; + if(editor_state.x == EDITOR_CONF_WIDTH) { + editor_state.x = 0; + if(editor_state.y < EDITOR_CONF_HEIGHT - 1) { + ++editor_state.y; + } + } + } + break; + } + textptr = &(editor_state.labels[editor_state.y].text[editor_state.x]); + *textptr |= 0x80; + CTK_WIDGET_REDRAW(&(editor_state.labels[editor_state.y])); + /* } else if(s == ctk_signal_widget_activate && + data == (process_data_t)t) { + textptr = &(t->label.text[t->ypos * t->label.w + t->xpos]); + *textptr &= 0x7f; + t->xpos = 0; + if(t->ypos < t->label.h - 1) { + ++t->ypos; + } + textptr = &(t->label.text[t->ypos * t->label.w + t->xpos]); + *textptr |= 0x80; + CTK_WIDGET_REDRAW(&t->label);*/ + + + } +} +/*---------------------------------------------------------------------------*/ +static void +open_file(char *name) +{ + int fd; + struct line *l; + char line[LINE_LEN]; + char *cptr; + int i, len, clen; + + fd = cfs_open(name, 0); + if(fd < 0) { + show_statustext("Could not open file ", name); + return; + } + + l = lines; + cptr = l->text; + clen = LINE_LEN; + + do { + /* Read a portion of the input file */ + len = cfs_read(fd, line, LINE_LEN); + + /* Split the input into lines. */ + for(i = 0; i < len; ++i) { + if(line[i] == ISO_nl || + clen == 0) { + *cptr = 0; + l = l->next; + if(l != NULL) { + cptr = l->text; + clen = LINE_LEN; + } else { + len = -1; + break; + } + } else { + *cptr++ = line[i]; + --clen; + } + } + } while(len > 0); + + + cfs_close(fd); +} +/*---------------------------------------------------------------------------*/ +static void +quit(void) +{ + ctk_window_close(&window); + process_exit(&editor_process); + LOADER_UNLOAD(); +} +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(editor_process, ev, data) +{ + + PROCESS_BEGIN(); + + memb_init(&linesmem); + + ctk_window_new(&window, + EDITOR_CONF_WIDTH + 2, + EDITOR_CONF_HEIGHT + 3, + "Editor"); + + CTK_WIDGET_ADD(&window, &openbutton); + CTK_WIDGET_ADD(&window, &statuslabel); + + CTK_WIDGET_FOCUS(&window, &openbutton); + + editor_start(); + + ctk_window_open(&window); + + while(1) { + PROCESS_WAIT_EVENT(); + + if(ctk_filedialog_eventhandler(&filedialog, ev, data)) { + + } else { + if(ev == PROCESS_EVENT_EXIT) { + quit(); + } else if(ev == OPEN_EVENT) { + /* printf("Open file '%s'\n", (char *)data);*/ + open_file((char *)data); + ctk_window_redraw(&window); + } else { + + if(ev == ctk_signal_window_close && + data == (process_data_t)&window) { + quit(); + } else if(ev == ctk_signal_widget_activate) { + if(data == (process_data_t)&openbutton) { + ctk_filedialog_open(&filedialog, "Open", OPEN_EVENT); + } + } else { + editor_eventhandler(ev, data); + } + } + } + } + + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/ +/*LOADER_INIT_FUNC(editor_init, arg) +{ + arg_free(arg); + id = ek_start(&p); +}*/ +/*---------------------------------------------------------------------------*/ diff --git a/apps/email/Makefile.email b/apps/email/Makefile.email new file mode 100644 index 000000000..4a0917e62 --- /dev/null +++ b/apps/email/Makefile.email @@ -0,0 +1,3 @@ +APP_SOURCES += email.c smtp-socket.c smtp-strings.c ctk-textentry-multiline.c \ + psock.c uipbuf.c memb.c +DSC_SOURCES += email-dsc.c \ No newline at end of file diff --git a/apps/email/email-dsc.c b/apps/email/email-dsc.c new file mode 100644 index 000000000..f7832519b --- /dev/null +++ b/apps/email/email-dsc.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2003, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the Contiki desktop environment + * + * $Id: email-dsc.c,v 1.1 2006/06/17 22:41:11 adamdunkels Exp $ + * + */ + +#include "sys/dsc.h" + +extern struct ctk_icon email_icon; +/*-----------------------------------------------------------------------------------*/ +DSC(email_dsc, + "Unfinished e-mail client", + "email.prg", + email_process, + &email_icon); +/*-----------------------------------------------------------------------------------*/ +#if CTK_CONF_ICON_BITMAPS +static unsigned char tcpipconficon_bitmap[3*3*8] = { + 0x00, 0x79, 0x43, 0x73, 0x47, 0x77, 0x47, 0x6f, + 0x00, 0xfe, 0xfe, 0xfc, 0xfc, 0xfc, 0xf8, 0xfb, + 0x00, 0x16, 0x02, 0x00, 0x02, 0x00, 0x00, 0xc2, + + 0x48, 0x4c, 0x5f, 0x5f, 0x1f, 0x3f, 0x3f, 0x03, + 0x79, 0xf0, 0xf0, 0xf0, 0xe0, 0xe0, 0xfe, 0xfc, + 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + + 0x77, 0x47, 0x70, 0x43, 0x79, 0x41, 0x7c, 0x00, + 0xfc, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xf7, 0x00, + 0x00, 0x80, 0x00, 0x00, 0x00, 0x84, 0xf0, 0x00 +}; +#endif /* CTK_CONF_ICON_BITMAPS */ + +#if CTK_CONF_ICON_TEXTMAPS +static char tcpipconficon_textmap[9] = { + '+', '-', '+', + '|', 'v', '|', + '+', '-', '+' +}; +#endif /* CTK_CONF_ICON_TEXTMAPS */ + +#if CTK_CONF_ICONS +static struct ctk_icon email_icon = + {CTK_ICON("E-mail", tcpipconficon_bitmap, tcpipconficon_textmap)}; +#endif /* CTK_CONF_ICONS */ +/*-----------------------------------------------------------------------------------*/ diff --git a/apps/email/email-dsc.h b/apps/email/email-dsc.h new file mode 100644 index 000000000..65de9ff57 --- /dev/null +++ b/apps/email/email-dsc.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2003, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the Contiki desktop environment + * + * $Id: email-dsc.h,v 1.1 2006/06/17 22:41:11 adamdunkels Exp $ + * + */ +#ifndef __EMAIL_DSC_H__ +#define __EMAIL_DSC_H__ + +#include "sys/dsc.h" + +DSC_HEADER(email_dsc); + +#endif /* __EMAIL_DSC_H__ */ diff --git a/apps/email/email.c b/apps/email/email.c new file mode 100644 index 000000000..6563a7e0a --- /dev/null +++ b/apps/email/email.c @@ -0,0 +1,335 @@ +/* + * Copyright (c) 2002, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the Contiki desktop environment for the C64. + * + * $Id: email.c,v 1.1 2006/06/17 22:41:11 adamdunkels Exp $ + * + */ + + +#include "contiki.h" +#include "ctk/ctk.h" +#include "smtp.h" +#include "lib/petsciiconv.h" + +#include "lib/ctk-textentry-multiline.h" + + +#include + +#ifdef EMAIL_CONF_WIDTH +#define MAIL_WIDTH EMAIL_CONF_WIDTH +#else +#define MAIL_WIDTH 37 +#endif + +#ifdef EMAIL_CONF_HEIGHT +#define MAIL_HEIGHT EMAIL_CONF_HEIGHT +#else +#define MAIL_HEIGHT 17 +#endif + +#if (MAIL_WIDTH - 9) < 39 +#define TEXTENTRY_WIDTH (MAIL_WIDTH - 9) +#else +#define TEXTENTRY_WIDTH 39 +#endif + +static struct ctk_menu menu; +unsigned char menuitem_compose, menuitem_setup, menuitem_quit; + +/* The main window. */ +static struct ctk_window composewindow; + +static struct ctk_separator sep1 = + {CTK_SEPARATOR(0, MAIL_HEIGHT + 3, MAIL_WIDTH + 1)}; +static struct ctk_label statuslabel = + {CTK_LABEL(7, MAIL_HEIGHT + 4, MAIL_WIDTH - 14, 1, "")}; + + +static struct ctk_label tolabel = + {CTK_LABEL(0, 0, 3, 1, "To:")}; +static char to[40]; +static struct ctk_textentry totextentry = + {CTK_TEXTENTRY(8, 0, TEXTENTRY_WIDTH, 1, to, 39)}; + +static struct ctk_label cclabel = + {CTK_LABEL(0, 1, 3, 1, "Cc:")}; +static char cc[40]; +static struct ctk_textentry cctextentry = + {CTK_TEXTENTRY(8, 1, TEXTENTRY_WIDTH, 1, cc, 39)}; + +static struct ctk_label subjectlabel = + {CTK_LABEL(0, 2, 8, 1, "Subject:")}; +static char subject[40]; +static struct ctk_textentry subjecttextentry = + {CTK_TEXTENTRY(8, 2, TEXTENTRY_WIDTH, 1, subject, 39)}; + +static char mail[MAIL_WIDTH * MAIL_HEIGHT]; +struct ctk_textentry mailtextentry = + {CTK_TEXTENTRY_INPUT(0, 3, MAIL_WIDTH - 1, MAIL_HEIGHT, mail, MAIL_WIDTH - 1, \ + ctk_textentry_multiline_input)}; + + +static struct ctk_button sendbutton = + {CTK_BUTTON(0, MAIL_HEIGHT + 4, 4, "Send")}; +static struct ctk_button erasebutton = + {CTK_BUTTON(MAIL_WIDTH - 6, MAIL_HEIGHT + 4, 5, "Erase")}; + +/* The "Really erase message?" dialog. */ +static struct ctk_window erasedialog; +static struct ctk_label erasedialoglabel1 = + {CTK_LABEL(2, 1, 22, 1, "Really erase message?")}; +static struct ctk_label erasedialoglabel2 = + {CTK_LABEL(0, 2, 26, 1, "All contents will be lost.")}; +static struct ctk_button eraseyesbutton = + {CTK_BUTTON(4, 4, 3, "Yes")}; +static struct ctk_button erasenobutton = + {CTK_BUTTON(18, 4, 2, "No")}; + +/* The setup window. */ +static struct ctk_window setupwindow; +static struct ctk_label fromaddresslabel = + {CTK_LABEL(0, 0, 25, 1, "Name and e-mail address")}; +static char fromaddress[40]; +static struct ctk_textentry fromaddresstextentry = + {CTK_TEXTENTRY(0, 1, 26, 1, fromaddress, 39)}; + +static struct ctk_label smtpserverlabel = + {CTK_LABEL(0, 3, 20, 1, "Outgoing mailserver")}; +static char smtpserver[40]; +static struct ctk_textentry smtpservertextentry = + {CTK_TEXTENTRY(0, 4, 26, 1, smtpserver, 39)}; + +static struct ctk_label pop3serverlabel = + {CTK_LABEL(0, 6, 20, 1, "Incoming mailserver")}; +static char pop3server[40]; +static struct ctk_textentry pop3servertextentry = + {CTK_TEXTENTRY(0, 7, 26, 1, pop3server, 39)}; + +static struct ctk_label pop3userlabel = + {CTK_LABEL(0, 9, 20, 1, "Mailserver username")}; +static char pop3user[40]; +static struct ctk_textentry pop3usertextentry = + {CTK_TEXTENTRY(0, 10, 26, 1, pop3user, 39)}; + +static struct ctk_label pop3passwordlabel = + {CTK_LABEL(0, 12, 20, 1, "Mailserver password")}; +static char pop3password[40]; +static struct ctk_textentry pop3passwordtextentry = + {CTK_TEXTENTRY(0, 13, 26, 1, pop3password, 39)}; + + +static struct ctk_button setupokbutton = + {CTK_BUTTON(24, 15, 2, "Ok")}; + +PROCESS(email_process, "E-mail client"); + +/*-----------------------------------------------------------------------------------*/ +static void +email_quit(void) +{ + ctk_window_close(&setupwindow); + ctk_window_close(&composewindow); + ctk_menu_remove(&menu); + process_exit(&email_process); + LOADER_UNLOAD(); +} +/*-----------------------------------------------------------------------------------*/ +static void +applyconfig(void) +{ + u16_t addr[2], *addrptr; + char *cptr; + + for(cptr = smtpserver; *cptr != ' ' && *cptr != 0; ++cptr); + *cptr = 0; + + addrptr = &addr[0]; + if(uiplib_ipaddrconv(smtpserver, (unsigned char *)addr) == 0) { + addrptr = resolv_lookup(smtpserver); + if(addrptr == NULL) { + resolv_query(smtpserver); + ctk_label_set_text(&statuslabel, "Resolving host..."); + return; + } + } + smtp_configure("contiki", addrptr); +} +/*-----------------------------------------------------------------------------------*/ +static void +prepare_message(void) +{ + /* Convert fields to ASCII. */ + petsciiconv_toascii(to, sizeof(to)); + petsciiconv_toascii(cc, sizeof(cc)); + petsciiconv_toascii(subject, sizeof(subject)); + petsciiconv_toascii(mail, sizeof(mail)); +} +/*-----------------------------------------------------------------------------------*/ +static void +erase_message(void) +{ + CTK_TEXTENTRY_CLEAR(&totextentry); + CTK_TEXTENTRY_CLEAR(&cctextentry); + CTK_TEXTENTRY_CLEAR(&subjecttextentry); + CTK_TEXTENTRY_CLEAR(&mailtextentry); +} +/*-----------------------------------------------------------------------------------*/ +PROCESS_THREAD(email_process, ev, data) +{ + struct ctk_widget *w; + + PROCESS_BEGIN(); + + /* Create the "Really erase message?" dialog. */ + ctk_dialog_new(&erasedialog, 26, 6); + CTK_WIDGET_ADD(&erasedialog, &erasedialoglabel1); + CTK_WIDGET_ADD(&erasedialog, &erasedialoglabel2); + CTK_WIDGET_ADD(&erasedialog, &eraseyesbutton); + CTK_WIDGET_ADD(&erasedialog, &erasenobutton); + CTK_WIDGET_FOCUS(&erasedialog, &erasenobutton); + + /* Create setup window. */ + ctk_window_new(&setupwindow, 28, 16, "E-mail setup"); + + CTK_WIDGET_ADD(&setupwindow, &fromaddresslabel); + CTK_WIDGET_ADD(&setupwindow, &fromaddresstextentry); + CTK_WIDGET_ADD(&setupwindow, &smtpserverlabel); + CTK_WIDGET_ADD(&setupwindow, &smtpservertextentry); + /* CTK_WIDGET_ADD(&setupwindow, &pop3serverlabel);*/ + /* CTK_WIDGET_ADD(&setupwindow, &pop3servertextentry);*/ + /* CTK_WIDGET_ADD(&setupwindow, &pop3userlabel);*/ + /* CTK_WIDGET_ADD(&setupwindow, &pop3usertextentry);*/ + /* CTK_WIDGET_ADD(&setupwindow, &pop3passwordlabel);*/ + /* CTK_WIDGET_ADD(&setupwindow, &pop3passwordtextentry);*/ + CTK_WIDGET_ADD(&setupwindow, &setupokbutton); + + CTK_WIDGET_FOCUS(&setupwindow, &fromaddresstextentry); + + + /* Create compose window. */ + + ctk_window_new(&composewindow, MAIL_WIDTH + 1, MAIL_HEIGHT + 5, "Compose e-mail"); + + CTK_WIDGET_ADD(&composewindow, &tolabel); + CTK_WIDGET_ADD(&composewindow, &cclabel); + CTK_WIDGET_ADD(&composewindow, &subjectlabel); + + CTK_WIDGET_ADD(&composewindow, &totextentry); + CTK_WIDGET_FOCUS(&composewindow, &totextentry); + CTK_WIDGET_ADD(&composewindow, &cctextentry); + CTK_WIDGET_ADD(&composewindow, &subjecttextentry); + + CTK_WIDGET_ADD(&composewindow, &mailtextentry); + + CTK_WIDGET_ADD(&composewindow, &sep1); + CTK_WIDGET_ADD(&composewindow, &statuslabel); + + CTK_WIDGET_ADD(&composewindow, &sendbutton); + CTK_WIDGET_ADD(&composewindow, &erasebutton); + + erase_message(); + + /* Create and add the menu */ + ctk_menu_new(&menu, "E-mail"); + menuitem_setup = ctk_menuitem_add(&menu, "Setup"); + menuitem_compose = ctk_menuitem_add(&menu, "Compose"); + menuitem_quit = ctk_menuitem_add(&menu, "Quit"); + ctk_menu_add(&menu); + + /* Open setup window */ + ctk_window_open(&setupwindow); + + while(1) { + + PROCESS_WAIT_EVENT(); + + if(ev == tcpip_event) { + smtp_appcall(data); + } else if(ev == ctk_signal_widget_activate) { + w = (struct ctk_widget *)data; + if(w == (struct ctk_widget *)&sendbutton) { + prepare_message(); + smtp_send(to, cc, fromaddress, subject, mail, MAIL_WIDTH, MAIL_HEIGHT); + ctk_label_set_text(&statuslabel, "Sending message..."); + CTK_WIDGET_REDRAW(&statuslabel); + } else if(w == (struct ctk_widget *)&erasebutton) { + ctk_dialog_open(&erasedialog); + } else if(w == (struct ctk_widget *)&eraseyesbutton) { + erase_message(); + ctk_dialog_close(); + } else if(w == (struct ctk_widget *)&erasenobutton) { + ctk_dialog_close(); + } else if(w == (struct ctk_widget *)&setupokbutton) { + applyconfig(); + ctk_window_close(&setupwindow); + ctk_window_open(&composewindow); + } + } else if(ev == ctk_signal_menu_activate) { + if((struct ctk_menu *)data == &menu) { + if(menu.active == menuitem_compose) { + ctk_window_open(&composewindow); + } else if(menu.active == menuitem_setup) { + ctk_window_open(&setupwindow); + } else if(menu.active == menuitem_quit) { + email_quit(); + } + } + } else if(ev == resolv_event_found) { + if(strcmp(data, smtpserver) == 0) { + if(resolv_lookup(smtpserver) != NULL) { + applyconfig(); + ctk_label_set_text(&statuslabel, ""); + } else { + ctk_label_set_text(&statuslabel, "Host not found"); + } + CTK_WIDGET_REDRAW(&statuslabel); + } + } else if(ev == PROCESS_EVENT_EXIT) { + email_quit(); + } + } + PROCESS_END(); +} +/*-----------------------------------------------------------------------------------*/ +void +smtp_done(unsigned char error) +{ + if(error == SMTP_ERR_OK) { + ctk_label_set_text(&statuslabel, "Mail sent"); + erase_message(); + ctk_window_open(&composewindow); + } else { + ctk_label_set_text(&statuslabel, "Mail error"); + } + CTK_WIDGET_REDRAW(&statuslabel); +} +/*-----------------------------------------------------------------------------------*/ diff --git a/apps/email/email.h b/apps/email/email.h new file mode 100644 index 000000000..3bdf78252 --- /dev/null +++ b/apps/email/email.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2002, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the Contiki desktop environment for the C64. + * + * $Id: email.h,v 1.1 2006/06/17 22:41:11 adamdunkels Exp $ + * + */ +#ifndef __EMAIL_H__ +#define __EMAIL_H__ + +void email_init(void); + +#endif /* __EMAIL_H__ */ diff --git a/apps/email/smtp-socket.c b/apps/email/smtp-socket.c new file mode 100644 index 000000000..20c7e4aa0 --- /dev/null +++ b/apps/email/smtp-socket.c @@ -0,0 +1,241 @@ +/* + * Copyright (c) 2004, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the Contiki operating system. + * + * Author: Adam Dunkels + * + * $Id: smtp-socket.c,v 1.1 2006/06/17 22:41:11 adamdunkels Exp $ + */ +#include "smtp.h" + +#include "smtp-strings.h" +#include "contiki-net.h" + +#include + +struct smtp_state { + + char connected; + + struct psock psock; + + char inputbuffer[4]; + + char *to; + char *cc; + char *from; + char *subject; + char *msg; + u8_t msgwidth; + u8_t msgheight; + u8_t line; +}; + +static struct smtp_state s; + +static char *localhostname; +static u16_t smtpserver[2]; + +#define ISO_nl 0x0a +#define ISO_cr 0x0d + +#define ISO_period 0x2e + +#define ISO_2 0x32 +#define ISO_3 0x33 +#define ISO_4 0x34 +#define ISO_5 0x35 + + +#define SEND_STRING(s, str) PSOCK_SEND(s, str, strlen(str)) +/*---------------------------------------------------------------------------*/ +static +PT_THREAD(smtp_thread(void)) +{ + PSOCK_BEGIN(&s.psock); + + PSOCK_READTO(&s.psock, ISO_nl); + + if(strncmp(s.inputbuffer, smtp_220, 3) != 0) { + PSOCK_CLOSE(&s.psock); + smtp_done(2); + PSOCK_EXIT(&s.psock); + } + + SEND_STRING(&s.psock, (char *)smtp_helo); + SEND_STRING(&s.psock, localhostname); + SEND_STRING(&s.psock, (char *)smtp_crnl); + + PSOCK_READTO(&s.psock, ISO_nl); + + if(s.inputbuffer[0] != ISO_2) { + PSOCK_CLOSE(&s.psock); + smtp_done(3); + PSOCK_EXIT(&s.psock); + } + + SEND_STRING(&s.psock, (char *)smtp_mail_from); + SEND_STRING(&s.psock, s.from); + SEND_STRING(&s.psock, (char *)smtp_crnl); + + PSOCK_READTO(&s.psock, ISO_nl); + + if(s.inputbuffer[0] != ISO_2) { + PSOCK_CLOSE(&s.psock); + smtp_done(4); + PSOCK_EXIT(&s.psock); + } + + SEND_STRING(&s.psock, (char *)smtp_rcpt_to); + SEND_STRING(&s.psock, s.to); + SEND_STRING(&s.psock, (char *)smtp_crnl); + + PSOCK_READTO(&s.psock, ISO_nl); + + if(s.inputbuffer[0] != ISO_2) { + PSOCK_CLOSE(&s.psock); + smtp_done(5); + PSOCK_EXIT(&s.psock); + } + + if(*s.cc != 0) { + SEND_STRING(&s.psock, (char *)smtp_rcpt_to); + SEND_STRING(&s.psock, s.cc); + SEND_STRING(&s.psock, (char *)smtp_crnl); + + PSOCK_READTO(&s.psock, ISO_nl); + + if(s.inputbuffer[0] != ISO_2) { + PSOCK_CLOSE(&s.psock); + smtp_done(6); + PSOCK_EXIT(&s.psock); + } + } + + SEND_STRING(&s.psock, (char *)smtp_data); + + PSOCK_READTO(&s.psock, ISO_nl); + + if(s.inputbuffer[0] != ISO_3) { + PSOCK_CLOSE(&s.psock); + smtp_done(7); + PSOCK_EXIT(&s.psock); + } + + SEND_STRING(&s.psock, (char *)smtp_to); + SEND_STRING(&s.psock, s.to); + SEND_STRING(&s.psock, (char *)smtp_crnl); + + if(*s.cc != 0) { + SEND_STRING(&s.psock, (char *)smtp_cc); + SEND_STRING(&s.psock, s.cc); + SEND_STRING(&s.psock, (char *)smtp_crnl); + } + + SEND_STRING(&s.psock, (char *)smtp_from); + SEND_STRING(&s.psock, s.from); + SEND_STRING(&s.psock, (char *)smtp_crnl); + + SEND_STRING(&s.psock, (char *)smtp_subject); + SEND_STRING(&s.psock, s.subject); + SEND_STRING(&s.psock, (char *)smtp_crnl); + + for(s.line = 0; s.line < s.msgheight; ++s.line) { + SEND_STRING(&s.psock, (char *)smtp_crnl); + SEND_STRING(&s.psock, &s.msg[s.line * s.msgwidth]); + } + + SEND_STRING(&s.psock, (char *)smtp_crnlperiodcrnl); + + PSOCK_READTO(&s.psock, ISO_nl); + if(s.inputbuffer[0] != ISO_2) { + PSOCK_CLOSE(&s.psock); + smtp_done(8); + PSOCK_EXIT(&s.psock); + } + + SEND_STRING(&s.psock, (char *)smtp_quit); + smtp_done(SMTP_ERR_OK); + PSOCK_END(&s.psock); +} +/*---------------------------------------------------------------------------*/ +void +smtp_appcall(void *state) +{ + if(uip_closed()) { + s.connected = 0; + return; + } + if(uip_aborted() || uip_timedout()) { + s.connected = 0; + smtp_done(1); + return; + } + smtp_thread(); +} +/*---------------------------------------------------------------------------*/ +void +smtp_configure(char *lhostname, u16_t *server) +{ + localhostname = lhostname; + smtpserver[0] = server[0]; + smtpserver[1] = server[1]; +} +/*---------------------------------------------------------------------------*/ +unsigned char +smtp_send(char *to, char *cc, char *from, char *subject, + char *msg, u8_t msgwidth, u8_t msgheight) +{ + struct uip_conn *conn; + + conn = tcp_connect(smtpserver, HTONS(25), NULL); + if(conn == NULL) { + return 0; + } + s.connected = 1; + s.to = to; + s.cc = cc; + s.from = from; + s.subject = subject; + s.msg = msg; + s.msgwidth = msgwidth; + s.msgheight = msgheight; + + PSOCK_INIT(&s.psock, s.inputbuffer, sizeof(s.inputbuffer)); + + return 1; +} +/*---------------------------------------------------------------------------*/ +void +smtp_init(void) +{ + s.connected = 0; +} +/*---------------------------------------------------------------------------*/ + diff --git a/apps/email/smtp-strings b/apps/email/smtp-strings new file mode 100644 index 000000000..27f639c2e --- /dev/null +++ b/apps/email/smtp-strings @@ -0,0 +1,11 @@ +smtp_220 "220" +smtp_helo "HELO " +smtp_mail_from "MAIL FROM: " +smtp_rcpt_to "RCPT TO: " +smtp_data "DATA\r\n" +smtp_to "To: " +smtp_from "From: " +smtp_subject "Subject: " +smtp_quit "QUIT\r\n" +smtp_crnl "\r\n" +smtp_crnlperiodcrnl "\r\n.\r\n" \ No newline at end of file diff --git a/apps/email/smtp-strings.c b/apps/email/smtp-strings.c new file mode 100644 index 000000000..67295392e --- /dev/null +++ b/apps/email/smtp-strings.c @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2004, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the Contiki operating system. + * + * Author: Adam Dunkels + * + * $Id: smtp-strings.c,v 1.1 2006/06/17 22:41:11 adamdunkels Exp $ + */ +const char smtp_220[4] = +/* "220" */ +{0x32, 0x32, 0x30, }; +const char smtp_helo[6] = +/* "HELO " */ +{0x48, 0x45, 0x4c, 0x4f, 0x20, }; +const char smtp_mail_from[12] = +/* "MAIL FROM: " */ +{0x4d, 0x41, 0x49, 0x4c, 0x20, 0x46, 0x52, 0x4f, 0x4d, 0x3a, 0x20, }; +const char smtp_rcpt_to[10] = +/* "RCPT TO: " */ +{0x52, 0x43, 0x50, 0x54, 0x20, 0x54, 0x4f, 0x3a, 0x20, }; +const char smtp_data[7] = +/* "DATA\r\n" */ +{0x44, 0x41, 0x54, 0x41, 0xd, 0xa, }; +const char smtp_to[5] = +/* "To: " */ +{0x54, 0x6f, 0x3a, 0x20, }; +const char smtp_cc[5] = +/* "Cc: " */ +{0x43, 0x63, 0x3a, 0x20, }; +const char smtp_from[7] = +/* "From: " */ +{0x46, 0x72, 0x6f, 0x6d, 0x3a, 0x20, }; +const char smtp_subject[10] = +/* "Subject: " */ +{0x53, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x3a, 0x20, }; +const char smtp_quit[7] = +/* "QUIT\r\n" */ +{0x51, 0x55, 0x49, 0x54, 0xd, 0xa, }; +const char smtp_crnl[3] = +/* "\r\n" */ +{0xd, 0xa, }; +const char smtp_crnlperiodcrnl[6] = +/* "\r\n.\r\n" */ +{0xd, 0xa, 0x2e, 0xd, 0xa, }; diff --git a/apps/email/smtp-strings.h b/apps/email/smtp-strings.h new file mode 100644 index 000000000..74cb5da46 --- /dev/null +++ b/apps/email/smtp-strings.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2004, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the Contiki operating system. + * + * Author: Adam Dunkels + * + * $Id: smtp-strings.h,v 1.1 2006/06/17 22:41:11 adamdunkels Exp $ + */ +extern const char smtp_220[4]; +extern const char smtp_helo[6]; +extern const char smtp_mail_from[12]; +extern const char smtp_rcpt_to[10]; +extern const char smtp_data[7]; +extern const char smtp_to[5]; +extern const char smtp_cc[5]; +extern const char smtp_from[7]; +extern const char smtp_subject[10]; +extern const char smtp_quit[7]; +extern const char smtp_crnl[3]; +extern const char smtp_crnlperiodcrnl[6]; diff --git a/apps/email/smtp.h b/apps/email/smtp.h new file mode 100644 index 000000000..11c3b6890 --- /dev/null +++ b/apps/email/smtp.h @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2002, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the uIP TCP/IP stack. + * + * $Id: smtp.h,v 1.1 2006/06/17 22:41:11 adamdunkels Exp $ + * + */ +#ifndef __SMTP_H__ +#define __SMTP_H__ + +#include "contiki-net.h" + +/* Callbacks. */ +#define SMTP_ERR_OK 0 +void smtp_done(unsigned char error); + +/* Functions. */ +void smtp_configure(char *localhostname, u16_t *smtpserver); +/* +unsigned char smtp_send(char *to, char *cc, char *from, + char *subject, char *msg, + u8_t msgwidth, u8_t msgheight); +*/ +unsigned char smtp_send(char *to, char *from, + char *subject, char *msg, + u16_t msglen); + +void smtp_appcall(void *state); + + +#ifndef UIP_APPCALL +#define UIP_APPCALL smtp_appcall +#endif + +#ifndef UIP_APPSTATE_SIZE +#define UIP_APPSTATE_SIZE (sizeof(struct smtp_state)) +#endif + + +void smtp_init(void); + +#endif /* __SMTP_H__ */ diff --git a/apps/ftp/Makefile.ftp b/apps/ftp/Makefile.ftp new file mode 100644 index 000000000..df796d7e7 --- /dev/null +++ b/apps/ftp/Makefile.ftp @@ -0,0 +1,2 @@ +APP_SOURCES += ftp.c ftpc.c memb.c +DSC_SOURCES += ftp-dsc.c \ No newline at end of file diff --git a/apps/ftp/ftp-dsc.c b/apps/ftp/ftp-dsc.c new file mode 100644 index 000000000..80fb6b0e3 --- /dev/null +++ b/apps/ftp/ftp-dsc.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2004, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the Contiki desktop environment + * + * $Id: ftp-dsc.c,v 1.1 2006/06/17 22:41:11 adamdunkels Exp $ + * + */ + +#include "sys/dsc.h" + +extern struct ctk_icon ftp_icon; +/*-----------------------------------------------------------------------------------*/ +DSC(ftp_dsc, + "FTP client", + "ftp.prg", + ftp_process, + &ftp_icon); +/*-----------------------------------------------------------------------------------*/ +#if CTK_CONF_ICON_BITMAPS +static unsigned char ftpicon_bitmap[3*3*8] = { + 0x00, 0x7e, 0x40, 0x73, 0x46, 0x4c, 0x18, 0x13, + 0x00, 0x00, 0xff, 0x81, 0x34, 0xc9, 0x00, 0xb6, + 0x00, 0x7e, 0x02, 0xce, 0x72, 0x32, 0x18, 0x48, + + 0x30, 0x27, 0x24, 0x20, 0x37, 0x24, 0x20, 0x33, + 0x00, 0x7b, 0x42, 0x00, 0x7b, 0x42, 0x00, 0x3b, + 0x0c, 0x24, 0x24, 0x04, 0xa4, 0x24, 0x04, 0x4c, + + 0x12, 0x19, 0x4c, 0x46, 0x63, 0x40, 0x7c, 0x00, + 0x22, 0x91, 0x00, 0xc4, 0x81, 0xff, 0x00, 0x00, + 0x08, 0x18, 0x32, 0x62, 0xc6, 0x02, 0x3e, 0x00 +}; +#endif /* CTK_CONF_ICON_BITMAPS */ + +#if CTK_CONF_ICON_TEXTMAPS +static char ftpicon_textmap[9] = { + 'F', 'T', 'P', + ' ', ' ', ' ', + 'F', 'T', 'P' +}; +#endif /* CTK_CONF_ICON_TEXTMAPS */ + +#if CTK_CONF_ICONS +static struct ctk_icon ftp_icon = + {CTK_ICON("FTP client", ftpicon_bitmap, ftpicon_textmap)}; +#endif /* CTK_CONF_ICONS */ +/*-----------------------------------------------------------------------------------*/ diff --git a/apps/ftp/ftp-dsc.h b/apps/ftp/ftp-dsc.h new file mode 100644 index 000000000..52418c360 --- /dev/null +++ b/apps/ftp/ftp-dsc.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2004, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the Contiki desktop environment + * + * $Id: ftp-dsc.h,v 1.1 2006/06/17 22:41:11 adamdunkels Exp $ + * + */ +#ifndef __FTP_DSC_H__ +#define __FTP_DSC_H__ + +#include "sys/dsc.h" + +DSC_HEADER(ftp_dsc); + +#endif /* __FTP_DSC_H__ */ diff --git a/apps/ftp/ftp.c b/apps/ftp/ftp.c new file mode 100644 index 000000000..f8a55114b --- /dev/null +++ b/apps/ftp/ftp.c @@ -0,0 +1,577 @@ +/* + * Copyright (c) 2004, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the Contiki operating system. + * + * Author: Adam Dunkels + * + * $Id: ftp.c,v 1.1 2006/06/17 22:41:11 adamdunkels Exp $ + */ +/* Note to self: It would be nice to have a "View" option in the download dialog. */ + +#include "ftpc.h" +#include "contiki.h" +#include "ctk/ctk.h" +#include "cfs/cfs.h" +#include "net/resolv.h" + +#include + +#define MAX_USERNAMELEN 16 +#define MAX_PASSWORDLEN 16 +#define MAX_HOSTNAMELEN 32 +#define MAX_FILENAMELEN 16 +#define FILES_WIDTH 17 +#define FILES_HEIGHT 18 + +PROCESS(ftp_process, "FTP client"); + +static void *connection; + +/* --- The main window --- */ + +static struct ctk_window window; + +static struct ctk_label localtextlabel = + {CTK_LABEL(1, 0, FILES_WIDTH, 1, "Local files")}; +static struct ctk_label remotetextlabel = + {CTK_LABEL(1 + FILES_WIDTH + 1, 0, + FILES_WIDTH, 1, "Remote files")}; + +static char leftptr[FILES_HEIGHT]; +static struct ctk_label leftptrlabel = + {CTK_LABEL(0, 1, 1, FILES_HEIGHT, leftptr)}; +static char midptr[FILES_HEIGHT]; +static struct ctk_label midptrlabel = + {CTK_LABEL(1 + FILES_WIDTH, 1, 1, FILES_HEIGHT, midptr)}; +static char rightptr[FILES_HEIGHT]; +static struct ctk_label rightptrlabel = + {CTK_LABEL(1 + FILES_WIDTH + 1 + FILES_WIDTH, 1, + 1, FILES_HEIGHT, rightptr)}; + +static char localfiles[FILES_WIDTH * FILES_HEIGHT]; +static struct ctk_label localfileslabel = + {CTK_LABEL(1, 1, + FILES_WIDTH, FILES_HEIGHT, localfiles)}; +static char remotefiles[FILES_WIDTH * FILES_HEIGHT]; +static struct ctk_label remotefileslabel = + {CTK_LABEL(FILES_WIDTH + 1 + 1, 1, + FILES_WIDTH, FILES_HEIGHT, remotefiles)}; + +static struct ctk_button reloadbutton = + {CTK_BUTTON(0, 1 + FILES_HEIGHT, 6, "Reload")}; + +static struct ctk_button connectionbutton = + {CTK_BUTTON(8, 1 + FILES_HEIGHT, 13, "Connection...")}; +static struct ctk_button quitbutton = + {CTK_BUTTON(1 + FILES_WIDTH + 1 + FILES_WIDTH - 5, + 1 + FILES_HEIGHT, 4, "Quit")}; + +static char statustext[3 + FILES_WIDTH * 2 + 1]; +static struct ctk_label statuslabel = + {CTK_LABEL(0, FILES_HEIGHT + 2, 3 + FILES_WIDTH * 2, 1, statustext)}; + + + +/* --- The download/upload dialogs --- */ +static char remotefilename[MAX_FILENAMELEN + 1]; +static char localfilename[MAX_FILENAMELEN + 1]; + +static struct ctk_window dialog; +static struct ctk_label downloadlabel = + {CTK_LABEL(6, 1, 13, 1, "Download file")}; +static struct ctk_label uploadlabel = + {CTK_LABEL(7, 1, 11, 1, "Upload file")}; +static struct ctk_label localfilenametextlabel = + {CTK_LABEL(2, 3, 15, 1, "Local filename")}; +static struct ctk_label localfilenamelabel = + {CTK_LABEL(3, 5, 16, 1, localfilename)}; +static struct ctk_textentry localfilenameentry = + {CTK_TEXTENTRY(2, 5, 16, 1, localfilename, sizeof(localfilename) - 1)}; +static struct ctk_label remotefilenametextlabel = + {CTK_LABEL(2, 7, 15, 1, "Remote filename")}; +static struct ctk_label remotefilenamelabel = + {CTK_LABEL(3, 9, 16, 1, remotefilename)}; +static struct ctk_textentry remotefilenameentry = + {CTK_TEXTENTRY(2, 9, 16, 1, remotefilename, sizeof(remotefilename) - 1)}; +static struct ctk_button downloadbutton = + {CTK_BUTTON(0, 11, 13, "Download file")}; +static struct ctk_button uploadbutton = + {CTK_BUTTON(0, 11, 11, "Upload file")}; +static struct ctk_button cancelbutton = + {CTK_BUTTON(16, 11, 6, "Cancel")}; + +/* --- The connection window --- */ +static char hostname[MAX_HOSTNAMELEN + 1]; +static char username[MAX_USERNAMELEN + 1]; +static char password[MAX_PASSWORDLEN + 1]; + +static struct ctk_window connectionwindow; +static struct ctk_label serverlabel = + {CTK_LABEL(0, 1, 10, 1, "FTP server")}; +static struct ctk_textentry serverentry = + {CTK_TEXTENTRY(0, 2, 16, 1, hostname, MAX_HOSTNAMELEN)}; + +static struct ctk_button anonymousbutton = + {CTK_BUTTON(10, 4, 9, "Anonymous")}; +static struct ctk_label userlabel = + {CTK_LABEL(0, 4, 8, 1, "Username")}; +static struct ctk_textentry userentry = + {CTK_TEXTENTRY(0, 5, 16, 1, username, sizeof(username) - 1)}; +static struct ctk_label passwordlabel = + {CTK_LABEL(0, 7, 8, 1, "Password")}; +static struct ctk_textentry passwordentry = + {CTK_TEXTENTRY(0, 8, 16, 1, password, sizeof(password) - 1)}; + +static struct ctk_button connectbutton = + {CTK_BUTTON(0, 10, 7, "Connect")}; +static struct ctk_button closeconnectionbutton = + {CTK_BUTTON(0, 10, 16, "Close connection")}; + +static struct ctk_button closebutton = + {CTK_BUTTON(18, 10, 5, "Close")}; + +static struct cfs_dir dir; +static struct cfs_dirent dirent; +static unsigned char localfileptr = 0; + +static unsigned char remotefileptr = 0; + +static unsigned char ptrstate; +#define PTRSTATE_LOCALFILES 0 +#define PTRSTATE_REMOTEFILES 1 +static unsigned char localptr, remoteptr; + +static int fd = -1; + +/*---------------------------------------------------------------------------*/ +static void +make_uploaddialog(void) +{ + ctk_dialog_new(&dialog, 24, 13); + + CTK_WIDGET_ADD(&dialog, &uploadlabel); + CTK_WIDGET_ADD(&dialog, &localfilenametextlabel); + CTK_WIDGET_ADD(&dialog, &localfilenamelabel); + CTK_WIDGET_ADD(&dialog, &remotefilenametextlabel); + CTK_WIDGET_ADD(&dialog, &remotefilenameentry); + CTK_WIDGET_ADD(&dialog, &uploadbutton); + CTK_WIDGET_ADD(&dialog, &cancelbutton); + + CTK_WIDGET_FOCUS(&dialog, &uploadbutton); +} +/*---------------------------------------------------------------------------*/ +static void +make_downloaddialog(void) +{ + ctk_dialog_new(&dialog, 24, 13); + + CTK_WIDGET_ADD(&dialog, &downloadlabel); + CTK_WIDGET_ADD(&dialog, &localfilenametextlabel); + CTK_WIDGET_ADD(&dialog, &localfilenameentry); + CTK_WIDGET_ADD(&dialog, &remotefilenametextlabel); + CTK_WIDGET_ADD(&dialog, &remotefilenamelabel); + CTK_WIDGET_ADD(&dialog, &downloadbutton); + CTK_WIDGET_ADD(&dialog, &cancelbutton); + + CTK_WIDGET_FOCUS(&dialog, &downloadbutton); +} +/*---------------------------------------------------------------------------*/ +static void +show_statustext(char *text1, char *text2) +{ + int len; + + len = strlen(text1); + if(len < sizeof(statustext)) { + strncpy(statustext, text1, sizeof(statustext)); + strncpy(statustext + len, text2, sizeof(statustext) - len); + CTK_WIDGET_REDRAW(&statuslabel); + } + +} +/*---------------------------------------------------------------------------*/ +static void +close_file(void) +{ + if(fd != -1) { + cfs_close(fd); + fd = -1; + } +} +/*---------------------------------------------------------------------------*/ +static void +quit(void) +{ + close_file(); + ctk_window_close(&window); + process_exit(&ftp_process); + LOADER_UNLOAD(); +} +/*---------------------------------------------------------------------------*/ +static void +clearptr(void) +{ + rightptr[remoteptr] = ' '; + midptr[remoteptr] = ' '; + leftptr[localptr] = ' '; + midptr[localptr] = ' '; +} +/*---------------------------------------------------------------------------*/ +static void +showptr(void) +{ + if(ptrstate == PTRSTATE_LOCALFILES) { + rightptr[remoteptr] = ' '; + midptr[remoteptr] = ' '; + leftptr[localptr] = '>'; + midptr[localptr] = '<'; + } else { + leftptr[localptr] = ' '; + midptr[localptr] = ' '; + rightptr[remoteptr] = '<'; + midptr[remoteptr] = '>'; + } + + CTK_WIDGET_REDRAW(&leftptrlabel); + CTK_WIDGET_REDRAW(&midptrlabel); + CTK_WIDGET_REDRAW(&rightptrlabel); +} +/*---------------------------------------------------------------------------*/ +static void +start_loaddir(void) +{ + memset(localfiles, 0, sizeof(localfiles)); + localfileptr = 0; + cfs_opendir(&dir, "."); + process_post(&ftp_process, PROCESS_EVENT_CONTINUE, NULL); +} +/*---------------------------------------------------------------------------*/ +static void +start_loadremote(void) +{ + memset(remotefiles, 0, sizeof(remotefiles)); + remotefileptr = 0; + clearptr(); + remoteptr = 0; + showptr(); + ftpc_list(connection); +} +/*---------------------------------------------------------------------------*/ +static void +make_connectionwindow(void) +{ + ctk_dialog_new(&connectionwindow, 25, 11); + + CTK_WIDGET_ADD(&connectionwindow, &serverlabel); + CTK_WIDGET_ADD(&connectionwindow, &serverentry); + + CTK_WIDGET_ADD(&connectionwindow, &userlabel); + CTK_WIDGET_ADD(&connectionwindow, &anonymousbutton); + CTK_WIDGET_ADD(&connectionwindow, &userentry); + CTK_WIDGET_ADD(&connectionwindow, &passwordlabel); + CTK_WIDGET_ADD(&connectionwindow, &passwordentry); + + if(connection == NULL) { + CTK_WIDGET_ADD(&connectionwindow, &connectbutton); + } else { + CTK_WIDGET_ADD(&connectionwindow, &closeconnectionbutton); + } + CTK_WIDGET_ADD(&connectionwindow, &closebutton); + + CTK_WIDGET_FOCUS(&connectionwindow, &serverentry); +} +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(ftp_process, ev, data) +{ + u16_t ipaddr[2], *ipaddrptr; + + PROCESS_BEGIN(); + + ftpc_init(); + + memset(statustext, 0, sizeof(statustext)); + memset(remotefiles, 0, sizeof(remotefiles)); + memset(localfiles, 0, sizeof(localfiles)); + memset(leftptr, 0, sizeof(leftptr)); + memset(midptr, 0, sizeof(midptr)); + memset(rightptr, 0, sizeof(rightptr)); + + ptrstate = PTRSTATE_REMOTEFILES; + localptr = remoteptr = 0; + + connection = NULL; + + ctk_window_new(&window, + 3 + FILES_WIDTH * 2, 3 + FILES_HEIGHT, + "FTP Client"); + + CTK_WIDGET_ADD(&window, &localtextlabel); + CTK_WIDGET_ADD(&window, &remotetextlabel); + + CTK_WIDGET_ADD(&window, &leftptrlabel); + CTK_WIDGET_ADD(&window, &localfileslabel); + CTK_WIDGET_ADD(&window, &midptrlabel); + CTK_WIDGET_ADD(&window, &remotefileslabel); + CTK_WIDGET_ADD(&window, &rightptrlabel); + + CTK_WIDGET_ADD(&window, &reloadbutton); + CTK_WIDGET_ADD(&window, &connectionbutton); + CTK_WIDGET_ADD(&window, &quitbutton); + + CTK_WIDGET_ADD(&window, &statuslabel); + + CTK_WIDGET_FOCUS(&window, &connectionbutton); + ctk_window_open(&window); + + showptr(); + + start_loaddir(); + + while(1) { + + PROCESS_WAIT_EVENT(); + + if(ev == PROCESS_EVENT_CONTINUE) { + if(cfs_readdir(&dir, &dirent) == 0 && + localfileptr < FILES_HEIGHT) { + strncpy(&localfiles[localfileptr * FILES_WIDTH], + dirent.name, FILES_WIDTH); + CTK_WIDGET_REDRAW(&localfileslabel); + ++localfileptr; + process_post(&ftp_process, PROCESS_EVENT_CONTINUE, NULL); + } else{ + cfs_closedir(&dir); + } + } else if(ev == PROCESS_EVENT_EXIT) { + quit(); + } else if(ev == tcpip_event) { + ftpc_appcall(data); + } else if(ev == resolv_event_found) { + /* Either found a hostname, or not. */ + if((char *)data != NULL && + (ipaddrptr = resolv_lookup((char *)data)) != NULL) { + connection = ftpc_connect(ipaddrptr, HTONS(21)); + show_statustext("Connecting to ", hostname); + } else { + show_statustext("Host not found: ", hostname); + } + + } else if(ev == ctk_signal_window_close && + data == (process_data_t)&window) { + quit(); + } else if(ev == ctk_signal_widget_activate) { + if((struct ctk_button *)data == &quitbutton) { + quit(); + } else if((struct ctk_button *)data == &cancelbutton) { + ctk_dialog_close(); + } else if((struct ctk_button *)data == &downloadbutton) { + ctk_dialog_close(); + close_file(); + fd = cfs_open(localfilename, CFS_WRITE); + if(fd != -1) { + show_statustext("Downloading ", remotefilename); + ftpc_get(connection, remotefilename); + } else { + show_statustext("Could not create ", localfilename); + } + } else if((struct ctk_button *)data == &reloadbutton) { + start_loaddir(); + } else if((struct ctk_button *)data == &connectionbutton) { + make_connectionwindow(); + ctk_dialog_open(&connectionwindow); + } else if((struct ctk_button *)data == &closebutton) { + ctk_dialog_close(); + } else if((struct ctk_button *)data == &anonymousbutton) { + strcpy(username, "ftp"); + strcpy(password, "contiki@ftp"); + CTK_WIDGET_REDRAW(&userentry); + CTK_WIDGET_REDRAW(&passwordentry); + } else if((struct ctk_button *)data == &closeconnectionbutton) { + ctk_dialog_close(); + ftpc_close(connection); + } else if((struct ctk_button *)data == &connectbutton) { + ctk_dialog_close(); + if(uiplib_ipaddrconv(hostname, (unsigned char *)ipaddr) == 0) { + ipaddrptr = resolv_lookup(hostname); + if(ipaddrptr == NULL) { + resolv_query(hostname); + show_statustext("Resolving host ", hostname); + break; + } + connection = ftpc_connect(ipaddrptr, HTONS(21)); + show_statustext("Connecting to ", hostname); + } else { + connection = ftpc_connect(ipaddr, HTONS(21)); + show_statustext("Connecting to ", hostname); + } + } + /* if((struct ctk_button *)data == &closebutton) { + ftpc_close(connection); + }*/ + } else if(ev == ctk_signal_keypress) { + /* if((ctk_arch_key_t)data == ' ') { + if(ptrstate == PTRSTATE_LOCALFILES) { + ptrstate = PTRSTATE_REMOTEFILES; + } else { + ptrstate = PTRSTATE_LOCALFILES; + } + } else */ if((ctk_arch_key_t)data == CH_CURS_UP) { + clearptr(); + if(ptrstate == PTRSTATE_LOCALFILES) { + if(localptr > 0) { + --localptr; + } + } else { + if(remoteptr > 0) { + --remoteptr; + } + } + } else if((ctk_arch_key_t)data == CH_CURS_DOWN) { + clearptr(); + if(ptrstate == PTRSTATE_LOCALFILES) { + if(localptr < FILES_HEIGHT - 1) { + ++localptr; + } + } else { + if(remoteptr < FILES_HEIGHT - 1) { + ++remoteptr; + } + } + } else if((ctk_arch_key_t)data == CH_ENTER) { + if(ptrstate == PTRSTATE_LOCALFILES) { + strncpy(localfilename, + &localfiles[localptr * FILES_WIDTH], FILES_WIDTH); + strncpy(remotefilename, + &localfiles[localptr * FILES_WIDTH], FILES_WIDTH); + make_uploaddialog(); + ctk_dialog_open(&dialog); + } else { + strncpy(localfilename, + &remotefiles[remoteptr * FILES_WIDTH], FILES_WIDTH); + strncpy(remotefilename, + &remotefiles[remoteptr * FILES_WIDTH], FILES_WIDTH); + ftpc_cwd(connection, remotefilename); + /* make_downloaddialog(); + ctk_dialog_open(&dialog);*/ + } + } else if((ctk_arch_key_t)data == 'u') { + ftpc_cdup(connection); + } + + showptr(); + } + } + + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/ +void +ftpc_closed(void) +{ + strcpy(statustext, "Connection closed"); + CTK_WIDGET_REDRAW(&statuslabel); + connection = NULL; +} +/*---------------------------------------------------------------------------*/ +void +ftpc_aborted(void) +{ + strcpy(statustext, "Connection reset"); + CTK_WIDGET_REDRAW(&statuslabel); + connection = NULL; +} +/*---------------------------------------------------------------------------*/ +void +ftpc_timedout(void) +{ + strcpy(statustext, "Connection timed out"); + CTK_WIDGET_REDRAW(&statuslabel); + connection = NULL; +} +/*---------------------------------------------------------------------------*/ +char * +ftpc_username(void) +{ + return username; +} +/*---------------------------------------------------------------------------*/ +char * +ftpc_password(void) +{ + return password; +} +/*---------------------------------------------------------------------------*/ +void +ftpc_list_file(char *filename) +{ + if(remotefileptr < FILES_HEIGHT && filename != NULL) { + strncpy(&remotefiles[remotefileptr * FILES_WIDTH], filename, FILES_WIDTH); + CTK_WIDGET_REDRAW(&remotefileslabel); + ++remotefileptr; + } + + if(filename == NULL) { + strcpy(statustext, "Connected"); + CTK_WIDGET_REDRAW(&statuslabel); + } +} +/*---------------------------------------------------------------------------*/ +void +ftpc_cwd_done(unsigned short status) +{ + if(status == FTPC_COMPLETED || + status == FTPC_OK) { + start_loadremote(); + } else { + make_downloaddialog(); + ctk_dialog_open(&dialog); + } +} +/*---------------------------------------------------------------------------*/ +void +ftpc_connected(void *connection) +{ + strcpy(statustext, "Loading remote directory"); + CTK_WIDGET_REDRAW(&statuslabel); + + start_loadremote(); +} +/*---------------------------------------------------------------------------*/ +void +ftpc_data(u8_t *data, u16_t len) +{ + if(data == NULL) { + show_statustext("Download complete", ""); + close_file(); + start_loaddir(); + } else { + cfs_write(fd, data, len); + } +} +/*---------------------------------------------------------------------------*/ diff --git a/apps/ftp/ftpc.c b/apps/ftp/ftpc.c new file mode 100644 index 000000000..237e580c0 --- /dev/null +++ b/apps/ftp/ftpc.c @@ -0,0 +1,506 @@ +/* + * Copyright (c) 2004, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the Contiki operating system. + * + * Author: Adam Dunkels + * + * $Id: ftpc.c,v 1.1 2006/06/17 22:41:11 adamdunkels Exp $ + */ +#include "contiki.h" +#include "ftpc.h" + +#include +#include + +#define ISO_nl 0x0a +#define ISO_cr 0x0d + +#define DATAPORT 6510 + +#define MAX_FILENAMELEN 32 + +struct ftp_dataconn { + unsigned char type; + unsigned char conntype; +#define CONNTYPE_LIST 0 +#define CONNTYPE_FILE 1 + + u16_t port; + + unsigned char filenameptr; + char filename[MAX_FILENAMELEN]; + + +}; + +struct ftp_connection { + unsigned char type; +#define TYPE_CONTROL 1 +#define TYPE_DATA 2 +#define TYPE_ABORT 3 +#define TYPE_CLOSE 4 + + unsigned char state; +#define STATE_NONE 0 +#define STATE_INITIAL 1 +#define STATE_SEND_USER 2 +#define STATE_USER_SENT 3 +#define STATE_SEND_PASS 4 +#define STATE_PASS_SENT 5 +#define STATE_SEND_PORT 6 +#define STATE_PORT_SENT 7 +#define STATE_SEND_OPTIONS 8 +#define STATE_OPTION_SENT 9 +#define STATE_CONNECTED 10 +#define STATE_SEND_NLST 11 +#define STATE_NLST_SENT 12 +#define STATE_SEND_RETR 13 +#define STATE_RETR_SENT 14 + +#define STATE_SEND_CWD 15 +#define STATE_CWD_SENT 16 + +#define STATE_SEND_CDUP 17 +#define STATE_CDUP_SENT 18 + +#define STATE_SEND_QUIT 19 +#define STATE_QUIT_SENT 20 + + unsigned char connected_confirmed; + + struct ftp_dataconn dataconn; + + char code[3]; + unsigned char codeptr; + + unsigned char optionsptr; + + char filename[MAX_FILENAMELEN]; + +}; + +#define NUM_OPTIONS 1 +static const struct { + unsigned char num; + char *commands[NUM_OPTIONS]; +} options = { + NUM_OPTIONS, + {"TYPE I\r\n"} +}; + +static struct ftp_connection *waiting_for_dataconn; + +MEMB(connections, struct ftp_connection, 1); + +/*---------------------------------------------------------------------------*/ +void +ftpc_init(void) +{ + memb_init(&connections); + /* tcp_listen(HTONS(DATAPORT));*/ +} +/*---------------------------------------------------------------------------*/ +void * +ftpc_connect(u16_t *ipaddr, u16_t port) +{ + struct ftp_connection *c; + + c = (struct ftp_connection *)memb_alloc(&connections); + if(c == NULL) { + return NULL; + } + c->type = TYPE_CONTROL; + c->state = STATE_INITIAL; + c->connected_confirmed = 0; + c->codeptr = 0; + c->dataconn.type = TYPE_DATA; + c->dataconn.port = DATAPORT; + tcp_listen(HTONS(DATAPORT)); + + if(tcp_connect(ipaddr, port, c) == NULL) { + memb_free(&connections, c); + return NULL; + } + + return c; +} +/*---------------------------------------------------------------------------*/ +static void +handle_input(struct ftp_connection *c) +{ + int code; + + code = (c->code[0] - '0') * 100 + + (c->code[1] - '0') * 10 + + (c->code[2] - '0'); + /* printf("Handle input code %d state %d\n", code, c->state);*/ + + if(c->state == STATE_INITIAL) { + if(code == 220) { + c->state = STATE_SEND_USER; + } + } else if(c->state == STATE_USER_SENT) { + if(code == 331) { + c->state = STATE_SEND_PASS; + } + } else if(c->state == STATE_PASS_SENT) { + if(code == 230) { + c->state = STATE_SEND_OPTIONS; + c->optionsptr = 0; + } + } else if(c->state == STATE_PORT_SENT) { + c->state = STATE_CONNECTED; + if(c->connected_confirmed == 0) { + ftpc_connected(c); + c->connected_confirmed = 1; + } + } else if(c->state == STATE_OPTION_SENT) { + if(c->optionsptr >= options.num) { + c->state = STATE_SEND_PORT; + } else { + c->state = STATE_SEND_OPTIONS; + } + } else if((c->state == STATE_NLST_SENT || + c->state == STATE_RETR_SENT || + c->state == STATE_CONNECTED)) { + if(code == 226 || code == 550) { + tcp_unlisten(htons(c->dataconn.port)); + ++c->dataconn.port; + tcp_listen(htons(c->dataconn.port)); + c->state = STATE_SEND_PORT; + } + + if(code == 550) { + ftpc_list_file(NULL); + } + } else if(c->state == STATE_CWD_SENT || + c->state == STATE_CDUP_SENT) { + c->state = STATE_CONNECTED; + ftpc_cwd_done(code); + /* } else if(c->state == STATE_) { + c->state = STATE_CONNECTED;*/ + } +} +/*---------------------------------------------------------------------------*/ +static void +newdata(struct ftp_connection *c) +{ + u16_t i; + u8_t d; + + for(i = 0; i < uip_datalen(); ++i) { + d = ((char *)uip_appdata)[i]; + if(c->codeptr < sizeof(c->code)) { + c->code[c->codeptr] = d; + ++c->codeptr; + } + + if(d == ISO_nl) { + handle_input(c); + c->codeptr = 0; + } + } +} +/*---------------------------------------------------------------------------*/ +static void +acked(struct ftp_connection *c) +{ + switch(c->state) { + case STATE_SEND_USER: + c->state = STATE_USER_SENT; + break; + case STATE_SEND_PASS: + c->state = STATE_PASS_SENT; + break; + case STATE_SEND_PORT: + c->state = STATE_PORT_SENT; + break; + case STATE_SEND_OPTIONS: + ++c->optionsptr; + c->state = STATE_OPTION_SENT; + break; + case STATE_SEND_NLST: + c->state = STATE_NLST_SENT; + break; + case STATE_SEND_RETR: + c->state = STATE_RETR_SENT; + break; + case STATE_SEND_CWD: + c->state = STATE_CWD_SENT; + break; + case STATE_SEND_CDUP: + c->state = STATE_CDUP_SENT; + break; + case STATE_SEND_QUIT: + c->state = STATE_QUIT_SENT; + uip_close(); + break; + } +} +/*---------------------------------------------------------------------------*/ +static void +senddata(struct ftp_connection *c) +{ + u16_t len; + + switch(c->state) { + case STATE_SEND_USER: + strcpy(uip_appdata, "USER "); + strncpy((char *)uip_appdata + 5, ftpc_username(), uip_mss() - 7); + len = strlen(ftpc_username()); + strcpy((char *)uip_appdata + 5 + len, "\r\n"); + uip_send(uip_appdata, len + 2 + 5); + break; + case STATE_SEND_PASS: + strcpy(uip_appdata, "PASS "); + strncpy((char *)uip_appdata + 5, ftpc_password(), uip_mss() - 7); + len = strlen(ftpc_password()); + strcpy((char *)uip_appdata + 5 + len, "\r\n"); + uip_send(uip_appdata, len + 2 + 5); + break; + case STATE_SEND_PORT: + len = sprintf(uip_appdata, "PORT %d,%d,%d,%d,%d,%d\n", + uip_ipaddr1(uip_hostaddr), + uip_ipaddr2(uip_hostaddr), + uip_ipaddr3(uip_hostaddr), + uip_ipaddr4(uip_hostaddr), + (c->dataconn.port) >> 8, + (c->dataconn.port) & 0xff); + uip_send(uip_appdata, len); + break; + case STATE_SEND_OPTIONS: + len = strlen(options.commands[c->optionsptr]); + uip_send(options.commands[c->optionsptr], len); + break; + case STATE_SEND_NLST: + uip_send("NLST\r\n", 6); + break; + case STATE_SEND_RETR: + len = sprintf(uip_appdata, "RETR %s\r\n", c->filename); + uip_send(uip_appdata, len); + break; + case STATE_SEND_CWD: + len = sprintf(uip_appdata, "CWD %s\r\n", c->filename); + uip_send(uip_appdata, len); + break; + case STATE_SEND_CDUP: + uip_send("CDUP\r\n", 6); + break; + case STATE_SEND_QUIT: + uip_send("QUIT\r\n", 6); + break; + } +} +/*---------------------------------------------------------------------------*/ +void +ftpc_appcall(void *state) +{ + int i, t; + struct ftp_connection *c = (struct ftp_connection *)state; + struct ftp_dataconn *d = (struct ftp_dataconn *)state; + + if(uip_connected()) { + if(state == NULL) { + if(waiting_for_dataconn != NULL) { + d = &waiting_for_dataconn->dataconn; + waiting_for_dataconn = NULL; + tcp_markconn(uip_conn, d); + d->filenameptr = 0; + + } else { + uip_abort(); + } + } else { + /* tcp_listen(uip_conn->lport);*/ + senddata(c); + } + return; + } + + if(c->type == TYPE_ABORT) { + uip_abort(); + return; + } + + if(c->type == TYPE_CLOSE) { + uip_close(); + c->type = TYPE_CONTROL; + return; + } + + if(c->type == TYPE_CONTROL) { + if(uip_closed()) { + c->dataconn.type = TYPE_ABORT; + ftpc_closed(); + memb_free(&connections, c); + } + if(uip_aborted()) { + c->dataconn.type = TYPE_ABORT; + ftpc_aborted(); + memb_free(&connections, c); + } + if(uip_timedout()) { + c->dataconn.type = TYPE_ABORT; + ftpc_timedout(); + memb_free(&connections, c); + } + + + if(uip_acked()) { + acked(c); + } + if(uip_newdata()) { + newdata(c); + } + if(uip_rexmit() || + uip_newdata() || + uip_acked()) { + senddata(c); + } else if(uip_poll()) { + senddata(c); + } + } else { + if(d->conntype == CONNTYPE_LIST) { + if(uip_newdata()) { + for(i = 0; i < uip_datalen(); ++i) { + t = ((char *)uip_appdata)[i]; + + if(d->filenameptr < sizeof(d->filename) - 1 && + t != ISO_cr && + t != ISO_nl) { + d->filename[d->filenameptr] = t; + ++d->filenameptr; + } + + if(t == ISO_nl) { + d->filename[d->filenameptr] = 0; + ftpc_list_file(d->filename); + d->filenameptr = 0; + } + + } + } + if(uip_closed()) { + ftpc_list_file(NULL); + } + } else { + if(uip_newdata()) { + ftpc_data(uip_appdata, uip_datalen()); + /* printf("Received %d data bytes: '%s'\n", + uip_datalen(), uip_appdata);*/ + } else if(uip_closed() || uip_timedout() || uip_aborted()) { + ftpc_data(NULL, 0); + } + } + } +} +/*---------------------------------------------------------------------------*/ +char +ftpc_list(void *conn) +{ + struct ftp_connection *c; + + c = conn; + + if(c == NULL || + c->state != STATE_CONNECTED) { + return 0; + } + + c->state = STATE_SEND_NLST; + c->dataconn.conntype = CONNTYPE_LIST; + waiting_for_dataconn = c; + return 1; +} +/*---------------------------------------------------------------------------*/ +char +ftpc_get(void *conn, char *filename) +{ + struct ftp_connection *c; + + c = conn; + + if(c == NULL || + c->state != STATE_CONNECTED) { + return 0; + } + + strncpy(c->filename, filename, sizeof(c->filename)); + + c->state = STATE_SEND_RETR; + c->dataconn.conntype = CONNTYPE_FILE; + waiting_for_dataconn = c; + return 1; +} +/*---------------------------------------------------------------------------*/ +void +ftpc_close(void *conn) +{ + struct ftp_connection *c; + + c = conn; + + if(c == NULL) { + return; + } + + c->type = TYPE_CLOSE; +} +/*---------------------------------------------------------------------------*/ +void +ftpc_cwd(void *conn, char *dirname) +{ + struct ftp_connection *c; + + c = conn; + + if(c == NULL || + c->state != STATE_CONNECTED) { + return; + } + + strncpy(c->filename, dirname, sizeof(c->filename)); + c->state = STATE_SEND_CWD; +} +/*---------------------------------------------------------------------------*/ +void +ftpc_cdup(void *conn) +{ + struct ftp_connection *c; + + c = conn; + + if(c == NULL || + c->state != STATE_CONNECTED) { + return; + } + + c->state = STATE_SEND_CDUP; +} +/*---------------------------------------------------------------------------*/ diff --git a/apps/ftp/ftpc.h b/apps/ftp/ftpc.h new file mode 100644 index 000000000..3d5434b51 --- /dev/null +++ b/apps/ftp/ftpc.h @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2004, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the Contiki operating system. + * + * Author: Adam Dunkels + * + * $Id: ftpc.h,v 1.1 2006/06/17 22:41:11 adamdunkels Exp $ + */ +#ifndef __FTPC_H__ +#define __FTPC_H__ + +#include "contiki-net.h" + +void ftpc_init(void); + +void *ftpc_connect(u16_t *ipaddr, u16_t port); +char ftpc_list(void *connection); +void ftpc_cwd(void *connection, char *dir); +void ftpc_cdup(void *connection); +char ftpc_get(void *connection, char *filename); +void ftpc_close(void *connection); + + +void ftpc_appcall(void *state); + +#define FTPC_OK 200 +#define FTPC_COMPLETED 250 +#define FTPC_NODIR 431 +#define FTPC_NOTDIR 550 + +/* Functions to be implemented by the calling module: */ +void ftpc_connected(void *connection); +void ftpc_cwd_done(unsigned short status); +char *ftpc_username(void); +char *ftpc_password(void); +void ftpc_closed(void); +void ftpc_aborted(void); +void ftpc_timedout(void); +void ftpc_list_file(char *filename); +void ftpc_data(u8_t *data, u16_t len); + +#endif /* __FTPC_H__ */ diff --git a/apps/irc/Makefile.irc b/apps/irc/Makefile.irc new file mode 100644 index 000000000..de23e03a8 --- /dev/null +++ b/apps/irc/Makefile.irc @@ -0,0 +1,3 @@ +APP_SOURCES += irc.c ircc.c psock.c uipbuf.c ircc-strings.c \ + ctk-textentry-cmdline.c +DSC_SOURCES += irc-dsc.c \ No newline at end of file diff --git a/apps/irc/irc-dsc.c b/apps/irc/irc-dsc.c new file mode 100644 index 000000000..935dad456 --- /dev/null +++ b/apps/irc/irc-dsc.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2003, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the Contiki desktop environment + * + * $Id: irc-dsc.c,v 1.1 2006/06/17 22:41:11 adamdunkels Exp $ + * + */ + +#include "sys/dsc.h" + +extern struct ctk_icon irc_icon; +/*-----------------------------------------------------------------------------------*/ +DSC(irc_dsc, + "Internet Relay Chat client", + "irc.prg", + irc_process, + &irc_icon); +/*-----------------------------------------------------------------------------------*/ +#if CTK_CONF_ICON_BITMAPS +static unsigned char irc_icon_bitmap[3*3*8] = { + 0x00, 0x79, 0x43, 0x73, 0x47, 0x77, 0x47, 0x6f, + 0x00, 0xfe, 0xfe, 0xfc, 0xfc, 0xfc, 0xf8, 0xfb, + 0x00, 0x16, 0x02, 0x00, 0x02, 0x00, 0x00, 0xc2, + + 0x48, 0x4c, 0x5f, 0x5f, 0x1f, 0x3f, 0x3f, 0x03, + 0x79, 0xf0, 0xf0, 0xf0, 0xe0, 0xe0, 0xfe, 0xfc, + 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + + 0x77, 0x47, 0x70, 0x43, 0x79, 0x41, 0x7c, 0x00, + 0xfc, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xf7, 0x00, + 0x00, 0x80, 0x00, 0x00, 0x00, 0x84, 0xf0, 0x00 +}; +#endif /* CTK_CONF_ICON_BITMAPS */ + +#if CTK_CONF_ICON_TEXTMAPS +static char irc_icon_textmap[9] = { + 'I', 'R', 'C', + '-', '-', '-', + 'I', 'R', 'C' +}; +#endif /* CTK_CONF_ICON_TEXTMAPS */ + +#if CTK_CONF_ICONS +static struct ctk_icon irc_icon = + {CTK_ICON("IRC client", irc_icon_bitmap, irc_icon_textmap)}; +#endif /* CTK_CONF_ICONS */ +/*-----------------------------------------------------------------------------------*/ diff --git a/apps/irc/irc-dsc.h b/apps/irc/irc-dsc.h new file mode 100644 index 000000000..5efa4dd4c --- /dev/null +++ b/apps/irc/irc-dsc.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2003, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the Contiki OS + * + * $Id: irc-dsc.h,v 1.1 2006/06/17 22:41:11 adamdunkels Exp $ + * + */ +#ifndef __IRC_DSC_H__ +#define __IRC_DSC_H__ + +#include "sys/dsc.h" + +DSC_HEADER(irc_dsc); + +#endif /* __IRC_DSC_H__ */ diff --git a/apps/irc/irc.c b/apps/irc/irc.c new file mode 100644 index 000000000..b549fd638 --- /dev/null +++ b/apps/irc/irc.c @@ -0,0 +1,293 @@ +/* + * Copyright (c) 2004, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the Contiki operating system. + * + * Author: Adam Dunkels + * + * $Id: irc.c,v 1.1 2006/06/17 22:41:11 adamdunkels Exp $ + */ + +#include "contiki-conf.h" +#include "contiki.h" +#include "contiki-net.h" +#include "ircc.h" + +#include "ctk/ctk.h" +#include "lib/ctk-textedit.h" +#include "lib/ctk-textentry-cmdline.h" + +#include "lib/petsciiconv.h" + + +#include + +#ifdef IRC_CONF_WIDTH +#define LOG_WIDTH IRC_CONF_WIDTH +#else +#define LOG_WIDTH 37 +#endif + +#ifdef IRC_CONF_HEIGHT +#define LOG_HEIGHT IRC_CONF_HEIGHT +#else +#define LOG_HEIGHT 17 +#endif + +PROCESS(irc_process, "IRC client"); + +static struct ctk_window window; +static char log[LOG_WIDTH * LOG_HEIGHT]; +static char line[LOG_WIDTH*2]; +static struct ctk_label loglabel = + {CTK_LABEL(0, 0, LOG_WIDTH, LOG_HEIGHT, log)}; +static struct ctk_textentry lineedit = + {CTK_TEXTENTRY_INPUT(0, LOG_HEIGHT, LOG_WIDTH - 2, 1, line, sizeof(line) - 1, + ctk_textentry_cmdline_input)}; + +static struct ctk_window setupwindow; +#define SETUPWINDOW_WIDTH 18 +#define SETUPWINDOW_HEIGHT 9 +#define MAX_SERVERLEN 32 +#define MAX_NICKLEN 16 +static u16_t serveraddr[2]; +static char server[MAX_SERVERLEN + 1]; +static char nick[MAX_NICKLEN + 1]; +static struct ctk_label serverlabel = + {CTK_LABEL(1, 1, 11, 1, "IRC server: ")}; +static struct ctk_textentry serverentry = + {CTK_TEXTENTRY(0, 2, 16, 1, server, MAX_SERVERLEN)}; + +static struct ctk_label nicklabel = + {CTK_LABEL(1, 4, 13, 1, "IRC nickname: ")}; +static struct ctk_textentry nickentry = + {CTK_TEXTENTRY(0, 5, 16, 1, nick, MAX_NICKLEN)}; + +static struct ctk_button connectbutton = + {CTK_BUTTON(0, 7, 7, "Connect")}; +static struct ctk_button quitbutton = + {CTK_BUTTON(12, 7, 4, "Quit")}; + +/*static char nick[] = "asdf"; + static char server[] = "efnet.demon.co.uk";*/ + +static struct ircc_state s; + +/*---------------------------------------------------------------------------*/ +static void +quit(void) +{ + ctk_window_close(&window); + ctk_window_close(&setupwindow); + process_exit(&irc_process); + LOADER_UNLOAD(); +} +/*---------------------------------------------------------------------------*/ +void +ircc_text_output(struct ircc_state *s, char *text1, char *text2) +{ + char *ptr; + int len; + + if(text1 == NULL) { + text1 = ""; + } + + if(text2 == NULL) { + text2 = ""; + } + + /* Scroll previous entries upwards */ + memcpy(log, &log[LOG_WIDTH], LOG_WIDTH * (LOG_HEIGHT - 1)); + + ptr = &log[LOG_WIDTH * (LOG_HEIGHT - 1)]; + len = strlen(text1); + + memset(ptr, 0, LOG_WIDTH); + strncpy(ptr, text1, LOG_WIDTH); + if(len < LOG_WIDTH) { + ptr += len; + *ptr = ':'; + ++len; + if(LOG_WIDTH - len > 0) { + strncpy(ptr + 1, text2, LOG_WIDTH - len); + } + } else { + len = 0; + } + + if(strlen(text2) > LOG_WIDTH - len) { + memcpy(log, &log[LOG_WIDTH], LOG_WIDTH * (LOG_HEIGHT - 1)); + strncpy(&log[LOG_WIDTH * (LOG_HEIGHT - 1)], + text2 + LOG_WIDTH - len, LOG_WIDTH); + } + CTK_WIDGET_REDRAW(&loglabel); + +} +/*---------------------------------------------------------------------------*/ +static void +parse_line(void) +{ + int i; + for(i = 0; i < strlen(line); ++i) { + line[i] &= 0x7f; + } + + + if(line[0] == '/') { + if(strncmp(&line[1], "join", 4) == 0) { + ircc_join(&s, &line[6]); + ircc_text_output(&s, "Join", &line[6]); + } else if(strncmp(&line[1], "list", 4) == 0) { + ircc_list(&s); + ircc_text_output(&s, "Channel list", ""); + } else if(strncmp(&line[1], "part", 4) == 0) { + ircc_part(&s); + ircc_text_output(&s, "Leaving channel", ""); + } else if(strncmp(&line[1], "quit", 4) == 0) { + ircc_quit(&s); + } else if(strncmp(&line[1], "me", 2) == 0) { + petsciiconv_toascii(&line[4], strlen(&line[4])); + ircc_actionmsg(&s, &line[4]); + ircc_text_output(&s, "*", &line[4]); + } else { + ircc_text_output(&s, &line[1], "Not implemented"); + ircc_sent(&s); + } + } else { + petsciiconv_toascii(line, sizeof(line) - 1); + ircc_msg(&s, &line[0]); + ircc_text_output(&s, nick, line); + } + +} +/*---------------------------------------------------------------------------*/ +void +ircc_sent(struct ircc_state *s) +{ + /* ctk_textedit_init(&lineedit);*/ + CTK_TEXTENTRY_CLEAR(&lineedit); + CTK_WIDGET_REDRAW(&lineedit); +} +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(irc_process, ev, data) +{ + ctk_arch_key_t c; + u16_t *ipaddr; + + PROCESS_BEGIN(); + + /* ctk_textedit_init(&lineedit);*/ + CTK_TEXTENTRY_CLEAR(&lineedit); + memset(log, 0, sizeof(log)); + ctk_window_new(&window, LOG_WIDTH, LOG_HEIGHT + 1, "IRC"); + CTK_WIDGET_ADD(&window, &loglabel); + /* ctk_textedit_add(&window, &lineedit); */ + CTK_WIDGET_ADD(&window, &lineedit); + CTK_WIDGET_FOCUS(&window, &lineedit); + + ctk_window_new(&setupwindow, SETUPWINDOW_WIDTH, SETUPWINDOW_HEIGHT, + "IRC setup"); + + CTK_WIDGET_ADD(&setupwindow, &serverlabel); + CTK_WIDGET_ADD(&setupwindow, &serverentry); + CTK_WIDGET_ADD(&setupwindow, &nicklabel); + CTK_WIDGET_ADD(&setupwindow, &nickentry); + CTK_WIDGET_ADD(&setupwindow, &connectbutton); + CTK_WIDGET_ADD(&setupwindow, &quitbutton); + + CTK_WIDGET_FOCUS(&setupwindow, &serverentry); + + ctk_window_open(&setupwindow); + + while(1) { + PROCESS_WAIT_EVENT(); + + if(ev == PROCESS_EVENT_EXIT) { + quit(); + } else if(ev == ctk_signal_window_close) { + quit(); + } else if(ev == tcpip_event) { + ircc_appcall(data); + } else if(ev == ctk_signal_widget_activate) { + if(data == (process_data_t)&lineedit) { + parse_line(); + } else if(data == (process_data_t)&quitbutton) { + quit(); + } else if(data == (process_data_t)&connectbutton) { + ctk_window_close(&setupwindow); + ctk_window_open(&window); + ipaddr = serveraddr; + if(uiplib_ipaddrconv(server, (u8_t *)serveraddr) == 0) { + ipaddr = resolv_lookup(server); + if(ipaddr == NULL) { + resolv_query(server); + } else { + uip_ipaddr_copy(serveraddr, ipaddr); + } + } + if(ipaddr != NULL) { + + ircc_connect(&s, server, serveraddr, nick); + } + } + } else if(ev == resolv_event_found) { + + ipaddr = resolv_lookup(server); + if(ipaddr == NULL) { + ircc_text_output(&s, server, "hostname not found"); + } else { + uip_ipaddr_copy(serveraddr, ipaddr); + ircc_connect(&s, server, serveraddr, nick); + } + + } else if(ev == ctk_signal_keypress) { + c = (ctk_arch_key_t)data; + if(c == CH_ENTER) { + parse_line(); + } else { + /* ctk_textedit_eventhandler(&lineedit, ev, data);*/ + CTK_WIDGET_FOCUS(&window, &lineedit); + } + } + } + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/ +void +ircc_closed(struct ircc_state *s) +{ + ircc_text_output(s, server, "connection closed"); +} +/*---------------------------------------------------------------------------*/ +void +ircc_connected(struct ircc_state *s) +{ + ircc_text_output(s, server, "connected"); +} +/*---------------------------------------------------------------------------*/ diff --git a/apps/irc/ircc-strings b/apps/irc/ircc-strings new file mode 100644 index 000000000..1d53244df --- /dev/null +++ b/apps/irc/ircc-strings @@ -0,0 +1,17 @@ +ircc_strings_nick "NICK " +ircc_strings_crnl_user "\r\nUSER " +ircc_strings_contiki " contiki " +ircc_strings_colon_contiki " :Contiki\r\n" +ircc_strings_join "JOIN " +ircc_strings_crnl "\r\n" +ircc_strings_part "PART " +ircc_strings_list "LIST " +ircc_strings_privmsg "PRIVMSG " +ircc_strings_colon " :" +ircc_strings_ping "PING " +ircc_strings_notice "NOTICE " +ircc_strings_action "\01ACTION " +ircc_strings_version "\01VERSION" +ircc_strings_version_query "\01VERSION\01" +ircc_strings_ctcpcrnl "\01\r\n" +ircc_strings_version_string " Contiki 1.2-devel1 " \ No newline at end of file diff --git a/apps/irc/ircc-strings.c b/apps/irc/ircc-strings.c new file mode 100644 index 000000000..f23c9b632 --- /dev/null +++ b/apps/irc/ircc-strings.c @@ -0,0 +1,51 @@ +const char ircc_strings_nick[6] = +/* "NICK " */ +{0x4e, 0x49, 0x43, 0x4b, 0x20, }; +const char ircc_strings_crnl_user[8] = +/* "\r\nUSER " */ +{0xd, 0xa, 0x55, 0x53, 0x45, 0x52, 0x20, }; +const char ircc_strings_contiki[10] = +/* " contiki " */ +{0x20, 0x63, 0x6f, 0x6e, 0x74, 0x69, 0x6b, 0x69, 0x20, }; +const char ircc_strings_colon_contiki[12] = +/* " :Contiki\r\n" */ +{0x20, 0x3a, 0x43, 0x6f, 0x6e, 0x74, 0x69, 0x6b, 0x69, 0xd, 0xa, }; +const char ircc_strings_join[6] = +/* "JOIN " */ +{0x4a, 0x4f, 0x49, 0x4e, 0x20, }; +const char ircc_strings_crnl[3] = +/* "\r\n" */ +{0xd, 0xa, }; +const char ircc_strings_part[6] = +/* "PART " */ +{0x50, 0x41, 0x52, 0x54, 0x20, }; +const char ircc_strings_list[6] = +/* "LIST " */ +{0x4c, 0x49, 0x53, 0x54, 0x20, }; +const char ircc_strings_privmsg[9] = +/* "PRIVMSG " */ +{0x50, 0x52, 0x49, 0x56, 0x4d, 0x53, 0x47, 0x20, }; +const char ircc_strings_colon[3] = +/* " :" */ +{0x20, 0x3a, }; +const char ircc_strings_ping[6] = +/* "PING " */ +{0x50, 0x49, 0x4e, 0x47, 0x20, }; +const char ircc_strings_notice[8] = +/* "NOTICE " */ +{0x4e, 0x4f, 0x54, 0x49, 0x43, 0x45, 0x20, }; +const char ircc_strings_action[9] = +/* "\01ACTION " */ +{0x1, 0x41, 0x43, 0x54, 0x49, 0x4f, 0x4e, 0x20, }; +const char ircc_strings_version[9] = +/* "\01VERSION" */ +{0x1, 0x56, 0x45, 0x52, 0x53, 0x49, 0x4f, 0x4e, }; +const char ircc_strings_version_query[10] = +/* "\01VERSION\01" */ +{0x1, 0x56, 0x45, 0x52, 0x53, 0x49, 0x4f, 0x4e, 0x1, }; +const char ircc_strings_ctcpcrnl[4] = +/* "\01\r\n" */ +{0x1, 0xd, 0xa, }; +const char ircc_strings_version_string[14] = +/* " Contiki 1.2 " */ +{0x20, 0x43, 0x6f, 0x6e, 0x74, 0x69, 0x6b, 0x69, 0x20, 0x31, 0x2e, 0x32, 0x20, }; diff --git a/apps/irc/ircc-strings.h b/apps/irc/ircc-strings.h new file mode 100644 index 000000000..72748292a --- /dev/null +++ b/apps/irc/ircc-strings.h @@ -0,0 +1,17 @@ +extern const char ircc_strings_nick[6]; +extern const char ircc_strings_crnl_user[8]; +extern const char ircc_strings_contiki[10]; +extern const char ircc_strings_colon_contiki[12]; +extern const char ircc_strings_join[6]; +extern const char ircc_strings_crnl[3]; +extern const char ircc_strings_part[6]; +extern const char ircc_strings_list[6]; +extern const char ircc_strings_privmsg[9]; +extern const char ircc_strings_colon[3]; +extern const char ircc_strings_ping[6]; +extern const char ircc_strings_notice[8]; +extern const char ircc_strings_action[9]; +extern const char ircc_strings_version[9]; +extern const char ircc_strings_version_query[10]; +extern const char ircc_strings_ctcpcrnl[4]; +extern const char ircc_strings_version_string[14]; diff --git a/apps/irc/ircc.c b/apps/irc/ircc.c new file mode 100644 index 000000000..62a74966e --- /dev/null +++ b/apps/irc/ircc.c @@ -0,0 +1,531 @@ +/* + * Copyright (c) 2004, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the Contiki operating system. + * + * Author: Adam Dunkels + * + * $Id: ircc.c,v 1.1 2006/06/17 22:41:11 adamdunkels Exp $ + */ + +#include "contiki.h" +#include "ircc.h" + +#include "ircc-strings.h" + +#include "lib/petsciiconv.h" + +#include + +#ifdef IRC_CONF_SYSTEM_STRING +#define IRC_SYSTEM_STRING IRC_CONF_SYSTEM_STRING +#else +#define IRC_SYSTEM_STRING "Contiki" +#endif + +#define PORT 6667 + +#define SEND_STRING(s, str) PSOCK_SEND(s, str, strlen(str)) + +#define ISO_space 0x20 +#define ISO_bang 0x21 +#define ISO_at 0x40 +#define ISO_cr 0x0d +#define ISO_nl 0x0a +#define ISO_colon 0x3a +#define ISO_O 0x4f + +enum { + COMMAND_NONE, + COMMAND_JOIN, + COMMAND_PART, + COMMAND_MSG, + COMMAND_ACTIONMSG, + COMMAND_LIST, + COMMAND_QUIT +}; + +/*---------------------------------------------------------------------------*/ +void +ircc_init(void) +{ + +} +/*---------------------------------------------------------------------------*/ +static char * +copystr(char *dest, const char *src, int n) +{ + int len; + + len = strlen(src); + strncpy(dest, src, n); + + if(len > n) { + return dest + n; + } else { + return dest + len; + } +} +/*---------------------------------------------------------------------------*/ +static +PT_THREAD(setup_connection(struct ircc_state *s)) +{ + char *ptr; + + + PSOCK_BEGIN(&s->s); + + ptr = s->outputbuf; + ptr = copystr(ptr, ircc_strings_nick, sizeof(s->outputbuf)); + ptr = copystr(ptr, s->nick, sizeof(s->outputbuf) - (ptr - s->outputbuf)); + ptr = copystr(ptr, ircc_strings_crnl_user, sizeof(s->outputbuf) - (ptr - s->outputbuf)); + ptr = copystr(ptr, s->nick, sizeof(s->outputbuf) - (ptr - s->outputbuf)); + ptr = copystr(ptr, ircc_strings_contiki, sizeof(s->outputbuf) - (ptr - s->outputbuf)); + ptr = copystr(ptr, s->server, sizeof(s->outputbuf) - (ptr - s->outputbuf)); + ptr = copystr(ptr, ircc_strings_colon_contiki, sizeof(s->outputbuf) - (ptr - s->outputbuf)); + + SEND_STRING(&s->s, s->outputbuf); + + PSOCK_END(&s->s); +} +/*---------------------------------------------------------------------------*/ +static +PT_THREAD(join_channel(struct ircc_state *s)) +{ + PSOCK_BEGIN(&s->s); + + SEND_STRING(&s->s, ircc_strings_join); + SEND_STRING(&s->s, s->channel); + SEND_STRING(&s->s, ircc_strings_crnl); + + ircc_sent(s); + + PSOCK_END(&s->s); +} +/*---------------------------------------------------------------------------*/ +static +PT_THREAD(part_channel(struct ircc_state *s)) +{ + PSOCK_BEGIN(&s->s); + + SEND_STRING(&s->s, ircc_strings_part); + SEND_STRING(&s->s, s->channel); + SEND_STRING(&s->s, ircc_strings_crnl); + + ircc_sent(s); + + PSOCK_END(&s->s); +} +/*---------------------------------------------------------------------------*/ +static +PT_THREAD(list_channel(struct ircc_state *s)) +{ + PSOCK_BEGIN(&s->s); + + SEND_STRING(&s->s, ircc_strings_list); + SEND_STRING(&s->s, s->channel); + SEND_STRING(&s->s, ircc_strings_crnl); + + ircc_sent(s); + + PSOCK_END(&s->s); +} +/*---------------------------------------------------------------------------*/ +static +PT_THREAD(send_message(struct ircc_state *s)) +{ + char *ptr; + + PSOCK_BEGIN(&s->s); + + ptr = s->outputbuf; + ptr = copystr(ptr, ircc_strings_privmsg, sizeof(s->outputbuf)); + ptr = copystr(ptr, s->channel, sizeof(s->outputbuf) - (ptr - s->outputbuf)); + ptr = copystr(ptr, ircc_strings_colon, sizeof(s->outputbuf) - (ptr - s->outputbuf)); + ptr = copystr(ptr, s->msg, sizeof(s->outputbuf) - (ptr - s->outputbuf)); + ptr = copystr(ptr, ircc_strings_crnl, sizeof(s->outputbuf) - (ptr - s->outputbuf)); + + SEND_STRING(&s->s, s->outputbuf); + + ircc_sent(s); + + PSOCK_END(&s->s); +} +/*---------------------------------------------------------------------------*/ +static +PT_THREAD(send_actionmessage(struct ircc_state *s)) +{ + char *ptr; + + PSOCK_BEGIN(&s->s); + + ptr = s->outputbuf; + ptr = copystr(ptr, ircc_strings_privmsg, sizeof(s->outputbuf)); + ptr = copystr(ptr, s->channel, sizeof(s->outputbuf) - (ptr - s->outputbuf)); + ptr = copystr(ptr, ircc_strings_colon, sizeof(s->outputbuf) - (ptr - s->outputbuf)); + ptr = copystr(ptr, ircc_strings_action, sizeof(s->outputbuf) - (ptr - s->outputbuf)); + ptr = copystr(ptr, s->msg, sizeof(s->outputbuf) - (ptr - s->outputbuf)); + ptr = copystr(ptr, ircc_strings_ctcpcrnl, sizeof(s->outputbuf) - (ptr - s->outputbuf)); + + + SEND_STRING(&s->s, s->outputbuf); + + ircc_sent(s); + + PSOCK_END(&s->s); +} +/*---------------------------------------------------------------------------*/ +struct parse_result { + char *msg; + + char *user; + char *host; + char *name; + char *command; + char *middle; + char *trailing; +}; +static struct parse_result r; +static void +parse_whitespace(void) +{ + while(*r.msg == ISO_space) ++r.msg; +} +static void +parse_word(void) +{ + char *ptr; + ptr = strchr(r.msg, ISO_space); + if(ptr != NULL) { + r.msg = ptr; + } +} +static void +parse_user(void) +{ + parse_whitespace(); + r.user = r.msg; + parse_word(); + *r.msg = 0; + ++r.msg; +} +static void +parse_host(void) +{ + parse_whitespace(); + r.host = r.msg; + parse_word(); + *r.msg = 0; + ++r.msg; +} + +static void +parse_name(void) +{ + parse_whitespace(); + r.name = r.msg; + parse_word(); + *r.msg = 0; + ++r.msg; +} + +static void +parse_prefix(void) +{ + parse_name(); + if(*r.msg == ISO_bang) { + ++r.msg; + parse_user(); + } + if(*r.msg == ISO_at) { + ++r.msg; + parse_host(); + } +} + +static void +parse_command(void) +{ + parse_whitespace(); + r.command = r.msg; + parse_word(); + *r.msg = 0; + ++r.msg; +} + +/*static void +parse_trailing(void) +{ + r.trailing = r.msg; + while(*r.msg != 0 && *r.msg != ISO_cr && *r.msg != ISO_nl) ++r.msg; + *r.msg = 0; + ++r.msg; +}*/ + +static void +parse_params(void) +{ + char *ptr; + + parse_whitespace(); + ptr = strchr(r.msg, ISO_colon); + if(ptr != NULL) { + r.trailing = ptr + 1; + ptr = strchr(ptr, ISO_cr); + if(ptr != NULL) { + *ptr = 0; + } + } +} + +static void +parse(char *msg, struct parse_result *dummy) +{ + r.msg = msg; + if(*r.msg == ISO_cr || *r.msg == ISO_nl) { + return; + } + if(*r.msg == ISO_colon) { + ++r.msg; + parse_prefix(); + } + + parse_command(); + parse_params(); + + /* printf("user %s host %s name %s command %s middle %s trailing %s\n", + r.user, r.host, r.name, r.command, r.middle, r.trailing);*/ +} + +/*---------------------------------------------------------------------------*/ +static +PT_THREAD(handle_input(struct ircc_state *s)) +{ + char *ptr; + /* struct parse_result r;*/ + + PSOCK_BEGIN(&s->s); + + PSOCK_READTO(&s->s, ISO_nl); + + if(PSOCK_DATALEN(&s->s) > 0) { + + s->inputbuf[PSOCK_DATALEN(&s->s)] = 0; + + if(strncmp(s->inputbuf, ircc_strings_ping, 5) == 0) { + strncpy(s->outputbuf, s->inputbuf, sizeof(s->outputbuf)); + + /* Turn "PING" into "PONG" */ + s->outputbuf[1] = ISO_O; + SEND_STRING(&s->s, s->outputbuf); + } else { + + memset(&r, 0, sizeof(r)); + + parse(s->inputbuf, &r); + + if(r.name != NULL) { + ptr = strchr(r.name, ISO_bang); + if(ptr != NULL) { + *ptr = 0; + } + } + + if(r.command != NULL && strncmp(r.command, ircc_strings_join, 4) == 0) { + ircc_text_output(s, "Joined channel", r.name); + } else if(r.command != NULL && strncmp(r.command, ircc_strings_part, 4) == 0) { + ircc_text_output(s, "Left channel", r.name); + } else if(r.trailing != NULL) { + if(strncmp(r.trailing, ircc_strings_action, + strlen(ircc_strings_action)) == 0) { + ptr = strchr(&r.trailing[1], 1); + if(ptr != NULL) { + *ptr = 0; + } + ptr = &r.trailing[strlen(ircc_strings_action)]; + petsciiconv_topetscii(r.name, strlen(r.name)); + petsciiconv_topetscii(ptr, strlen(ptr)); + ircc_text_output(s, r.name, ptr); + } else if(strncmp(r.trailing, ircc_strings_version_query, + strlen(ircc_strings_version_query)) == 0) { + if(r.name != NULL) { + strncpy(s->outputbuf, r.name, sizeof(s->outputbuf)); + SEND_STRING(&s->s, ircc_strings_notice); + /* user is temporarily stored in outputbuf. */ + SEND_STRING(&s->s, s->outputbuf); + SEND_STRING(&s->s, ircc_strings_colon); + SEND_STRING(&s->s, ircc_strings_version); + SEND_STRING(&s->s, ircc_strings_version_string); + SEND_STRING(&s->s, IRC_SYSTEM_STRING); + SEND_STRING(&s->s, ircc_strings_ctcpcrnl); + } + } else { + petsciiconv_topetscii(r.name, strlen(r.name)); + petsciiconv_topetscii(r.trailing, strlen(r.trailing)); + ircc_text_output(s, r.name, r.trailing); + } + } + } + } + + PSOCK_END(&s->s); +} +/*---------------------------------------------------------------------------*/ +static +PT_THREAD(data_or_command(struct ircc_state *s)) +{ + PSOCK_BEGIN(&s->s); + + PSOCK_WAIT_UNTIL(&s->s, PSOCK_NEWDATA(&s->s) || + (s->command != COMMAND_NONE)); + + PSOCK_END(&s->s); +} +/*---------------------------------------------------------------------------*/ +static +PT_THREAD(handle_connection(struct ircc_state *s)) +{ + PT_BEGIN(&s->pt); + + PSOCK_INIT(&s->s, s->inputbuf, sizeof(s->inputbuf) - 1); + + PT_WAIT_THREAD(&s->pt, setup_connection(s)); + + while(1) { + + PT_WAIT_UNTIL(&s->pt, data_or_command(s)); + + if(PSOCK_NEWDATA(&s->s)) { + PT_WAIT_THREAD(&s->pt, handle_input(s)); + } + + switch(s->command) { + case COMMAND_JOIN: + s->command = COMMAND_NONE; + PT_WAIT_THREAD(&s->pt, join_channel(s)); + break; + case COMMAND_PART: + s->command = COMMAND_NONE; + PT_WAIT_THREAD(&s->pt, part_channel(s)); + break; + case COMMAND_MSG: + s->command = COMMAND_NONE; + PT_WAIT_THREAD(&s->pt, send_message(s)); + break; + case COMMAND_ACTIONMSG: + s->command = COMMAND_NONE; + PT_WAIT_THREAD(&s->pt, send_actionmessage(s)); + break; + case COMMAND_LIST: + s->command = COMMAND_NONE; + PT_WAIT_THREAD(&s->pt, list_channel(s)); + break; + case COMMAND_QUIT: + s->command = COMMAND_NONE; + tcp_markconn(uip_conn, NULL); + PSOCK_CLOSE(&s->s); + process_post(PROCESS_CURRENT(), PROCESS_EVENT_EXIT, NULL); + PT_EXIT(&s->pt); + break; + default: + break; + } + } + + PT_END(&s->pt); +} +/*---------------------------------------------------------------------------*/ +void +ircc_appcall(void *s) +{ + if(uip_closed() || uip_aborted() || uip_timedout()) { + ircc_closed(s); + } else if(uip_connected()) { + ircc_connected(s); + PT_INIT(&((struct ircc_state *)s)->pt); + memset(((struct ircc_state *)s)->channel, 0, + sizeof(((struct ircc_state *)s)->channel)); + ((struct ircc_state *)s)->command = COMMAND_NONE; + handle_connection(s); + } else if(s != NULL) { + handle_connection(s); + } +} +/*---------------------------------------------------------------------------*/ +struct ircc_state * +ircc_connect(struct ircc_state *s, char *servername, u16_t *ipaddr, + char *nick) +{ + s->conn = tcp_connect(ipaddr, HTONS(PORT), s); + if(s->conn == NULL) { + return NULL; + } + s->server = servername; + s->nick = nick; + return s; +} +/*---------------------------------------------------------------------------*/ +void +ircc_list(struct ircc_state *s) +{ + s->command = COMMAND_LIST; +} +/*---------------------------------------------------------------------------*/ +void +ircc_join(struct ircc_state *s, char *channel) +{ + strncpy(s->channel, channel, sizeof(s->channel)); + s->command = COMMAND_JOIN; +} +/*---------------------------------------------------------------------------*/ +void +ircc_part(struct ircc_state *s) +{ + s->command = COMMAND_PART; +} +/*---------------------------------------------------------------------------*/ +void +ircc_quit(struct ircc_state *s) +{ + s->command = COMMAND_QUIT; +} +/*---------------------------------------------------------------------------*/ +void +ircc_msg(struct ircc_state *s, char *msg) +{ + s->msg = msg; + s->command = COMMAND_MSG; +} +/*---------------------------------------------------------------------------*/ +void +ircc_actionmsg(struct ircc_state *s, char *msg) +{ + s->msg = msg; + s->command = COMMAND_ACTIONMSG; +} +/*---------------------------------------------------------------------------*/ diff --git a/apps/irc/ircc.h b/apps/irc/ircc.h new file mode 100644 index 000000000..92eef0845 --- /dev/null +++ b/apps/irc/ircc.h @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2004, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the Contiki operating system. + * + * Author: Adam Dunkels + * + * $Id: ircc.h,v 1.1 2006/06/17 22:41:11 adamdunkels Exp $ + */ +#ifndef __IRCC_H__ +#define __IRCC_H__ + +#include "contiki-net.h" + +struct ircc_state { + + struct pt pt; + struct psock s; + + struct uip_conn *conn; + + unsigned char command; + + char *msg; + char channel[32]; + char outputbuf[200]; + char inputbuf[400]; + char *nick; + char *server; +}; + +void ircc_init(void); + +void ircc_appcall(void *s); + +struct ircc_state *ircc_connect(struct ircc_state *s, + char *server, u16_t *ipaddr, char *nick); + +void ircc_join(struct ircc_state *s, char *channel); +void ircc_part(struct ircc_state *s); +void ircc_list(struct ircc_state *s); +void ircc_msg(struct ircc_state *s, char *msg); +void ircc_actionmsg(struct ircc_state *s, char *msg); + +void ircc_sent(struct ircc_state *s); + +void ircc_text_output(struct ircc_state *s, char *text1, char *text2); + +void ircc_connected(struct ircc_state *s); +void ircc_closed(struct ircc_state *s); + +void ircc_quit(struct ircc_state *s); + +#endif /* __IRCC_H__ */ diff --git a/apps/netconf/Makefile.netconf b/apps/netconf/Makefile.netconf new file mode 100644 index 000000000..20e53a918 --- /dev/null +++ b/apps/netconf/Makefile.netconf @@ -0,0 +1,2 @@ +APP_SOURCES += netconf.c +DSC_SOURCES += netconf-dsc.c \ No newline at end of file diff --git a/apps/netconf/netconf-dsc.c b/apps/netconf/netconf-dsc.c new file mode 100644 index 000000000..4828cde6c --- /dev/null +++ b/apps/netconf/netconf-dsc.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2003, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the Contiki desktop environment + * + * $Id: netconf-dsc.c,v 1.1 2006/06/17 22:41:11 adamdunkels Exp $ + * + */ + +#include "sys/dsc.h" + +extern struct ctk_icon netconf_icon; +/*-----------------------------------------------------------------------------------*/ +DSC(netconf_dsc, + "Network configuration", + "netconf.prg", + netconf_process, + &netconf_icon); +/*-----------------------------------------------------------------------------------*/ +#if CTK_CONF_ICON_BITMAPS +static unsigned char tcpipconficon_bitmap[3*3*8] = { + 0x00, 0x79, 0x43, 0x73, 0x47, 0x77, 0x47, 0x6f, + 0x00, 0xfe, 0xfe, 0xfc, 0xfc, 0xfc, 0xf8, 0xfb, + 0x00, 0x16, 0x02, 0x00, 0x02, 0x00, 0x00, 0xc2, + + 0x48, 0x4c, 0x5f, 0x5f, 0x1f, 0x3f, 0x3f, 0x03, + 0x79, 0xf0, 0xf0, 0xf0, 0xe0, 0xe0, 0xfe, 0xfc, + 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + + 0x77, 0x47, 0x70, 0x43, 0x79, 0x41, 0x7c, 0x00, + 0xfc, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xf7, 0x00, + 0x00, 0x80, 0x00, 0x00, 0x00, 0x84, 0xf0, 0x00 +}; +#endif /* CTK_CONF_ICON_BITMAPS */ + +#if CTK_CONF_ICON_TEXTMAPS +static char tcpipconficon_textmap[9] = { + 'T', 'C', 'P', + '/', 'I', 'P', + 'C', 'f', 'g' +}; +#endif /* CTK_CONF_ICON_TEXTMAPS */ + +#if CTK_CONF_ICONS +static struct ctk_icon netconf_icon = + {CTK_ICON("Network setup", tcpipconficon_bitmap, tcpipconficon_textmap)}; +#endif /* CTK_CONF_ICONS */ +/*-----------------------------------------------------------------------------------*/ diff --git a/apps/netconf/netconf-dsc.h b/apps/netconf/netconf-dsc.h new file mode 100644 index 000000000..485a3bd09 --- /dev/null +++ b/apps/netconf/netconf-dsc.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2003, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the Contiki desktop environment + * + * $Id: netconf-dsc.h,v 1.1 2006/06/17 22:41:11 adamdunkels Exp $ + * + */ +#ifndef __NETCONF_DSC_H__ +#define __NETCONF_DSC_H__ + +#include "sys/dsc.h" + +DSC_HEADER(netconf_dsc); + +#endif /* __NETCONF_DSC_H__ */ diff --git a/apps/netconf/netconf.c b/apps/netconf/netconf.c new file mode 100644 index 000000000..7a36f97d9 --- /dev/null +++ b/apps/netconf/netconf.c @@ -0,0 +1,246 @@ +/* + * Copyright (c) 2002, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the Contiki desktop environment + * + * $Id: netconf.c,v 1.1 2006/06/17 22:41:11 adamdunkels Exp $ + * + */ + +#include "contiki-net.h" +#include "ctk/ctk.h" + + +/* TCP/IP configuration window. */ +static struct ctk_window tcpipwindow; + +#ifdef WITH_ETHERNET +static struct ctk_label ipaddrlabel = + {CTK_LABEL(0, 1, 10, 1, "IP address")}; +static char ipaddr[17]; +static struct ctk_textentry ipaddrtextentry = + {CTK_TEXTENTRY(11, 1, 16, 1, ipaddr, 16)}; +static struct ctk_label netmasklabel = + {CTK_LABEL(0, 3, 10, 1, "Netmask")}; +static char netmask[17]; +static struct ctk_textentry netmasktextentry = + {CTK_TEXTENTRY(11, 3, 16, 1, netmask, 16)}; +static struct ctk_label gatewaylabel = + {CTK_LABEL(0, 5, 10, 1, "Gateway")}; +static char gateway[17]; +static struct ctk_textentry gatewaytextentry = + {CTK_TEXTENTRY(11, 5, 16, 1, gateway, 16)}; +static struct ctk_label dnsserverlabel = + {CTK_LABEL(0, 7, 10, 1, "DNS server")}; +static char dnsserver[17]; +static struct ctk_textentry dnsservertextentry = + {CTK_TEXTENTRY(11, 7, 16, 1, dnsserver, 16)}; +#else /* WITH_ETHERNET */ +static struct ctk_label ipaddrlabel = + {CTK_LABEL(0, 2, 10, 1, "IP address")}; +static char ipaddr[17]; +static struct ctk_textentry ipaddrtextentry = + {CTK_TEXTENTRY(11, 2, 16, 1, ipaddr, 16)}; +static struct ctk_label dnsserverlabel = + {CTK_LABEL(0, 4, 10, 1, "DNS server")}; +static char dnsserver[17]; +static struct ctk_textentry dnsservertextentry = + {CTK_TEXTENTRY(11, 4, 16, 1, dnsserver, 16)}; +#endif /* WITH_ETHERNET */ + +static struct ctk_button tcpipclosebutton = + {CTK_BUTTON(0, 9, 2, "Ok")}; + +PROCESS(netconf_process, "Network configurator"); + +static void makestrings(void); + +/*-----------------------------------------------------------------------------------*/ +static char * +makebyte(u8_t byte, char *str) +{ + if(byte >= 100) { + *str++ = (byte / 100 ) % 10 + '0'; + } + if(byte >= 10) { + *str++ = (byte / 10) % 10 + '0'; + } + *str++ = (byte % 10) + '0'; + + return str; +} +/*-----------------------------------------------------------------------------------*/ +static void +makeaddr(u16_t *addr, char *str) +{ + str = makebyte(HTONS(addr[0]) >> 8, str); + *str++ = '.'; + str = makebyte(HTONS(addr[0]) & 0xff, str); + *str++ = '.'; + str = makebyte(HTONS(addr[1]) >> 8, str); + *str++ = '.'; + str = makebyte(HTONS(addr[1]) & 0xff, str); + *str++ = 0; +} +/*-----------------------------------------------------------------------------------*/ +static void +makestrings(void) +{ + u16_t addr[2], *addrptr; + +#ifdef WITH_UIP + uip_gethostaddr(addr); + makeaddr(addr, ipaddr); + +#ifdef WITH_ETHERNET + uip_getnetmask(addr); + makeaddr(addr, netmask); + + uip_getdraddr(addr); + makeaddr(addr, gateway); +#endif /* WITH_ETHERNET */ + + addrptr = resolv_getserver(); + if(addrptr != NULL) { + makeaddr(addrptr, dnsserver); + } + +#endif /* WITH_UIP */ + +} +/*-----------------------------------------------------------------------------------*/ +static void +nullterminate(char *cptr) +{ + /* Find the first space character in the ipaddr and put a zero there + to end the string. */ + for(; *cptr != ' ' && *cptr != 0; ++cptr); + *cptr = 0; +} +/*-----------------------------------------------------------------------------------*/ +static void +apply_tcpipconfig(void) +{ + u16_t addr[2]; + +#ifdef WITH_UIP + nullterminate(ipaddr); + if(uiplib_ipaddrconv(ipaddr, (unsigned char *)addr)) { + uip_sethostaddr(addr); + } + +#ifdef WITH_ETHERNET + nullterminate(netmask); + if(uiplib_ipaddrconv(netmask, (unsigned char *)addr)) { + uip_setnetmask(addr); + } + + nullterminate(gateway); + if(uiplib_ipaddrconv(gateway, (unsigned char *)addr)) { + uip_setdraddr(addr); + } +#endif /* WITH_ETHERNET */ + + nullterminate(dnsserver); + if(uiplib_ipaddrconv(dnsserver, (unsigned char *)addr)) { + resolv_conf(addr); + } +#endif /* WITH_UIP */ +} +/*-----------------------------------------------------------------------------------*/ +static void +netconf_quit(void) +{ + process_exit(&netconf_process); + LOADER_UNLOAD(); +} +/*-----------------------------------------------------------------------------------*/ +PROCESS_THREAD(netconf_process, ev, data) +{ + + PROCESS_BEGIN(); + + + /* Create TCP/IP configuration window. */ + ctk_window_new(&tcpipwindow, 30, 10, "TCP/IP config"); + /* if(ctk_desktop_width(tcpipwindow.desktop) < 30) { + ctk_window_move(&tcpipwindow, 0, + (ctk_desktop_height(tcpipwindow.desktop) - 10) / 2 - 2); + } else { + ctk_window_move(&tcpipwindow, + (ctk_desktop_width(tcpipwindow.desktop) - 30) / 2, + (ctk_desktop_height(tcpipwindow.desktop) - 10) / 2 - 2); + }*/ + +#ifdef WITH_ETHERNET + CTK_WIDGET_ADD(&tcpipwindow, &ipaddrlabel); + CTK_WIDGET_ADD(&tcpipwindow, &ipaddrtextentry); + CTK_WIDGET_ADD(&tcpipwindow, &netmasklabel); + CTK_WIDGET_ADD(&tcpipwindow, &netmasktextentry); + CTK_WIDGET_ADD(&tcpipwindow, &gatewaylabel); + CTK_WIDGET_ADD(&tcpipwindow, &gatewaytextentry); + CTK_WIDGET_ADD(&tcpipwindow, &dnsserverlabel); + CTK_WIDGET_ADD(&tcpipwindow, &dnsservertextentry); +#else + CTK_WIDGET_ADD(&tcpipwindow, &ipaddrlabel); + CTK_WIDGET_ADD(&tcpipwindow, &ipaddrtextentry); + CTK_WIDGET_ADD(&tcpipwindow, &dnsserverlabel); + CTK_WIDGET_ADD(&tcpipwindow, &dnsservertextentry); +#endif /* WITH_ETHERNET */ + + CTK_WIDGET_ADD(&tcpipwindow, &tcpipclosebutton); + + CTK_WIDGET_FOCUS(&tcpipwindow, &ipaddrtextentry); + + /* Fill the configuration strings with values from the current + configuration */ + makestrings(); + + ctk_window_open(&tcpipwindow); + + while(1) { + PROCESS_WAIT_EVENT(); + + if(ev == ctk_signal_button_activate) { + if(data == (process_data_t)&tcpipclosebutton) { + apply_tcpipconfig(); + ctk_window_close(&tcpipwindow); + netconf_quit(); + /* ctk_desktop_redraw(tcpipwindow.desktop);*/ + } + } else if(ev == ctk_signal_window_close || + ev == PROCESS_EVENT_EXIT) { + ctk_window_close(&tcpipwindow); + netconf_quit(); + } + } + + PROCESS_END(); +} +/*-----------------------------------------------------------------------------------*/ diff --git a/apps/process-list/Makefile.process-list b/apps/process-list/Makefile.process-list new file mode 100644 index 000000000..6a84ea57b --- /dev/null +++ b/apps/process-list/Makefile.process-list @@ -0,0 +1,2 @@ +APP_SOURCES += process-list.c +DSC_SOURCES += process-list-dsc.c \ No newline at end of file diff --git a/apps/process-list/process-list-dsc.c b/apps/process-list/process-list-dsc.c new file mode 100644 index 000000000..5f33797b9 --- /dev/null +++ b/apps/process-list/process-list-dsc.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2003, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the Contiki desktop environment + * + * $Id: process-list-dsc.c,v 1.1 2006/06/17 22:41:12 adamdunkels Exp $ + * + */ + +#include "sys/dsc.h" + +extern struct ctk_icon processes_icon; +/*-----------------------------------------------------------------------------------*/ +DSC(processes_dsc, + "Process information", + "processes.prg", + processes_process, + &processes_icon); +/*-----------------------------------------------------------------------------------*/ +#if CTK_CONF_ICON_BITMAPS +static unsigned char processesicon_bitmap[3*3*8] = { + 0x00, 0x7f, 0x43, 0x4c, 0x58, 0x53, 0x60, 0x6f, + 0x00, 0xff, 0x00, 0x7e, 0x00, 0xff, 0x00, 0xff, + 0x00, 0xfe, 0xc2, 0x32, 0x1a, 0xca, 0x06, 0xf6, + + 0x40, 0x5f, 0x40, 0x5f, 0x40, 0x5f, 0x40, 0x4f, + 0x00, 0xff, 0x00, 0xff, 0x00, 0xfc, 0x01, 0xf3, + 0x02, 0xfa, 0x02, 0x82, 0x3e, 0xfe, 0xfe, 0xfe, + + 0x60, 0x67, 0x50, 0x59, 0x4c, 0x43, 0x7f, 0x00, + 0x07, 0xe7, 0x0f, 0xef, 0x0f, 0x0f, 0xff, 0x00, + 0x8e, 0x06, 0x06, 0x06, 0x8e, 0xfe, 0xfe, 0x00 +}; +#endif /* CTK_CONF_ICON_BITMAPS */ + +#if CTK_CONF_ICON_TEXTMAPS +static char processesicon_textmap[9] = { + '0', '1', ' ', + ' ', '0', '1', + '1', '0', '/' +}; +#endif /* CTK_CONF_ICON_TEXTMAPS */ + +#if CTK_CONF_ICONS +static struct ctk_icon processes_icon = + {CTK_ICON("Processes", processesicon_bitmap, processesicon_textmap)}; +#endif /* CTK_CONF_ICONS */ +/*-----------------------------------------------------------------------------------*/ diff --git a/apps/process-list/process-list-dsc.h b/apps/process-list/process-list-dsc.h new file mode 100644 index 000000000..e13469df9 --- /dev/null +++ b/apps/process-list/process-list-dsc.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2003, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the Contiki desktop environment + * + * $Id: process-list-dsc.h,v 1.1 2006/06/17 22:41:12 adamdunkels Exp $ + * + */ +#ifndef __PROCESSES_DSC_H__ +#define __PROCESSES_DSC_H__ + +#include "sys/dsc.h" + +DSC_HEADER(processes_dsc); + +#endif /* __PROCESSES_DSC_H__ */ diff --git a/apps/process-list/process-list.c b/apps/process-list/process-list.c new file mode 100644 index 000000000..b42b5d471 --- /dev/null +++ b/apps/process-list/process-list.c @@ -0,0 +1,194 @@ +/* + * Copyright (c) 2002, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the Contiki desktop environment + * + * $Id: process-list.c,v 1.1 2006/06/17 22:41:12 adamdunkels Exp $ + * + */ + +#include "ctk/ctk.h" +#include "contiki.h" + +#include + +#define MAX_PROCESSLABELS 13 +static struct ctk_window processwindow; +static unsigned char ids[MAX_PROCESSLABELS][4]; +static struct ctk_label processidlabels[MAX_PROCESSLABELS]; +static struct ctk_label processnamelabels[MAX_PROCESSLABELS]; + +static struct ctk_label killlabel = + {CTK_LABEL(0, 14, 12, 1, "Kill process")}; +static char killprocnum[4]; +static struct ctk_textentry killtextentry = + {CTK_TEXTENTRY(13, 14, 3, 1, killprocnum, 3)}; +static struct ctk_button killbutton = + {CTK_BUTTON(19, 14, 2, "Ok")}; +static struct ctk_button processupdatebutton = + {CTK_BUTTON(0, 15, 6, "Update")}; +static struct ctk_button processclosebutton = + {CTK_BUTTON(19, 15, 5, "Close")}; + +PROCESS(processes_process, "Process listing"); + +enum { + EVENT_UPDATE +}; + +/*-----------------------------------------------------------------------------------*/ +static void +update_processwindow(void) +{ + unsigned char i, j, *idsptr; + struct process *p; + + /* Step through each possible process ID and see if there is a + matching process. */ + j = 0; + for(p = PROCESS_LIST(); p != NULL && j < MAX_PROCESSLABELS; p = p->next) { + idsptr = ids[j]; + i = (int)&p; + idsptr[0] = '0' + i / 100; + if(idsptr[0] == '0') { + idsptr[0] = ' '; + } + idsptr[1] = '0' + (i / 10) % 10; + idsptr[2] = '0' + i % 10; + idsptr[3] = 0; + CTK_LABEL_NEW(&processidlabels[j], + 0, j + 1, 3, 1, idsptr); + CTK_WIDGET_ADD(&processwindow, &processidlabels[j]); + + CTK_LABEL_NEW(&processnamelabels[j], + 4, j + 1, 22, 1, (char *)p->name); + CTK_WIDGET_ADD(&processwindow, &processnamelabels[j]); + + ++j; + } + + CTK_WIDGET_ADD(&processwindow, &killlabel); + + CTK_WIDGET_ADD(&processwindow, &killtextentry); + CTK_WIDGET_ADD(&processwindow, &killbutton); + + CTK_WIDGET_ADD(&processwindow, &processupdatebutton); + CTK_WIDGET_ADD(&processwindow, &processclosebutton); + CTK_WIDGET_FOCUS(&processwindow, &processupdatebutton); + +} +/*-----------------------------------------------------------------------------------*/ +static void +processes_quit(void) +{ + process_exit(&processes_process); + LOADER_UNLOAD(); +} +/*-----------------------------------------------------------------------------------*/ +static void +killproc(void) +{ +#if 0 + int procnum; + unsigned char i, j; + struct ek_proc *p; + + /* Find first zero char in killprocnum string. */ + for(i = 0; killprocnum[i] != 0 && + i < sizeof(killprocnum); ++i); + + if(i == 0) { + return; + } + + procnum = 0; + + for(j = 0; j < i; ++j) { + procnum = procnum * 10 + (killprocnum[j] - '0'); + killprocnum[j] = 0; + } + + /* Make sure the process ID exists. */ + for(p = EK_PROCS(); p != NULL; p = p->next) { + if(EK_PROC_ID(p) == procnum) { + break; + } + } + + if(p != NULL) { + /* ek_post(procnum, EK_EVENT_REQUEST_EXIT, NULL); + ek_post(id, EVENT_UPDATE, NULL);*/ + CTK_TEXTENTRY_CLEAR(&killtextentry); + CTK_WIDGET_REDRAW(&killtextentry); + CTK_WIDGET_FOCUS(&processwindow, &processupdatebutton); + CTK_WIDGET_REDRAW(&killbutton); + CTK_WIDGET_REDRAW(&processupdatebutton); + } +#endif +} +/*-----------------------------------------------------------------------------------*/ +PROCESS_THREAD(processes_process, ev, data) +{ + + PROCESS_BEGIN(); + + ctk_window_new(&processwindow, 26, 16, "Processes"); + update_processwindow(); + + ctk_window_open(&processwindow); + + while(1) { + PROCESS_WAIT_EVENT(); + if(ev == EVENT_UPDATE) { + ctk_window_clear(&processwindow); + update_processwindow(); + ctk_window_open(&processwindow); + } else if(ev == ctk_signal_button_activate) { + if(data == (process_data_t)&processupdatebutton) { + ctk_window_clear(&processwindow); + update_processwindow(); + ctk_window_open(&processwindow); + } else if(data == (process_data_t)&processclosebutton) { + ctk_window_close(&processwindow); + processes_quit(); + /* ctk_desktop_redraw(processwindow.desktop); */ + } else if(data == (process_data_t)&killbutton) { + killproc(); + } + } else if(ev == PROCESS_EVENT_EXIT || + (ev == ctk_signal_window_close && + data == (process_data_t)&processwindow)) { + ctk_window_close(&processwindow); + processes_quit(); + } + } + + PROCESS_END(); +} +/*-----------------------------------------------------------------------------------*/ diff --git a/apps/program-handler/Makefile.program-handler b/apps/program-handler/Makefile.program-handler new file mode 100644 index 000000000..2aa939769 --- /dev/null +++ b/apps/program-handler/Makefile.program-handler @@ -0,0 +1,2 @@ +APP_SOURCES += program-handler.c +DSC_SOURCES += \ No newline at end of file diff --git a/apps/program-handler/program-handler.c b/apps/program-handler/program-handler.c new file mode 100644 index 000000000..aadb1ff70 --- /dev/null +++ b/apps/program-handler/program-handler.c @@ -0,0 +1,385 @@ +/** + * \file + * The program handler, used for loading programs and starting the + * screensaver. + * \author Adam Dunkels + * + * The Contiki program handler is responsible for the Contiki menu and + * the desktop icons, as well as for loading programs and displaying a + * dialog with a message telling which program that is loading. + * + * The program handler also is responsible for starting the + * screensaver when the CTK detects that it should be started. + */ + +/* + * Copyright (c) 2003, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the Contiki desktop OS + * + * $Id: program-handler.c,v 1.1 2006/06/17 22:41:12 adamdunkels Exp $ + * + */ + +#include + +#include "contiki.h" +#include "ctk/ctk.h" +#include "ctk/ctk-draw.h" + +#include "program-handler.h" + + +/* Menus */ +static struct ctk_menu contikimenu; + +#ifndef PROGRAM_HANDLER_CONF_MAX_NUMDSCS +#define MAX_NUMDSCS 10 +#else /* PROGRAM_HANDLER_CONF_MAX_NUMDSCS */ +#define MAX_NUMDSCS PROGRAM_HANDLER_CONF_MAX_NUMDSCS +#endif /* PROGRAM_HANDLER_CONF_MAX_NUMDSCS */ + +static struct dsc *contikidsc[MAX_NUMDSCS]; +static unsigned char contikidsclast = 0; + +#if WITH_LOADER_ARCH +/* "Run..." window */ +static struct ctk_window runwindow; +static unsigned char runmenuitem; +static struct ctk_label namelabel = + {CTK_LABEL(0, 0, 13, 1, "Program name:")}; +static char name[31]; +static struct ctk_textentry nameentry = + {CTK_TEXTENTRY(0, 1, 14, 1, name, 30)}; +static struct ctk_button loadbutton = + {CTK_BUTTON(10, 2, 4, "Load")}; + +static struct ctk_window loadingdialog; +static struct ctk_label loadingmsg = + {CTK_LABEL(0, 0, 8, 1, "Starting")}; +static struct ctk_label loadingname = + {CTK_LABEL(9, 0, 16, 1, name)}; + +static struct ctk_window errordialog; +static struct ctk_label errormsg = + {CTK_LABEL(0, 1, 22, 1, "Error loading program:")}; +static char errorfilename[22]; +static struct ctk_label errorfilelabel = + {CTK_LABEL(0, 3, 22, 1, errorfilename)}; +static struct ctk_label errortype = + {CTK_LABEL(4, 5, 16, 1, "")}; +static struct ctk_button errorokbutton = + {CTK_BUTTON(9, 7, 2, "Ok")}; + + +#endif /* WITH_LOADER_ARCH */ + +PROCESS(program_handler_process, "Program handler"); + +static const char * const errormsgs[] = { + "Ok", + "Read error", + "Header error", + "OS error", + "Data format error", + "Out of memory", + "File not found", + "No loader" +}; + +#define LOADER_EVENT_LOAD 1 +#define LOADER_EVENT_DISPLAY_NAME 2 + +static char *displayname; + +#if CTK_CONF_SCREENSAVER +char program_handler_screensaver[20]; +#endif /* CTK_CONF_SCREENSAVER */ + +/*-----------------------------------------------------------------------------------*/ +/** + * Add a program to the program handler. + * + * \param dsc The DSC description structure for the program to be added. + * + * \param menuname The name that the program should have in the + * Contiki menu. + * + * \param desktop Flag which specifies if the program should show up + * as an icon on the desktop or not. + */ +/*-----------------------------------------------------------------------------------*/ +void +program_handler_add(struct dsc *dsc, char *menuname, + unsigned char desktop) +{ + contikidsc[contikidsclast++] = dsc; + ctk_menuitem_add(&contikimenu, menuname); + if(desktop) { + CTK_ICON_ADD(dsc->icon, &program_handler_process); + } +} +/*-----------------------------------------------------------------------------------*/ +/** + * Initializes the program handler. + * + * Is called by the initialization before any programs have been added + * with program_handler_add(). + * + */ +/*-----------------------------------------------------------------------------------*/ +#ifdef WITH_LOADER_ARCH +#define NUM_PNARGS 6 +#define NAMELEN 32 +struct pnarg { + char name[NAMELEN]; + char *arg; +}; +static struct pnarg pnargs[NUM_PNARGS]; +static struct pnarg * +pnarg_copy(char *name, char *arg) +{ + char i; + struct pnarg *pnargsptr; + + pnargsptr = pnargs; + /* Allocate a place in the loadernames table. */ + for(i = 0; i < NUM_PNARGS; ++i) { + if(*(pnargsptr->name) == 0) { + strncpy(pnargsptr->name, name, NAMELEN); + pnargsptr->arg = arg; + return pnargsptr; + } + ++pnargsptr; + } + return NULL; +} + +static void +pnarg_free(struct pnarg *pn) +{ + *(pn->name) = 0; +} +#endif /* WITH_LOADER_ARCH */ +/*-----------------------------------------------------------------------------------*/ +/** + * Loads a program and displays a dialog telling the user about it. + * + * \param name The name of the program to be loaded. + * + * \param arg An argument which is passed to the new process when it + * is loaded. + */ +/*-----------------------------------------------------------------------------------*/ +void +program_handler_load(char *name, char *arg) +{ +#ifdef WITH_LOADER_ARCH + struct pnarg *pnarg; + + pnarg = pnarg_copy(name, arg); + if(pnarg != NULL) { + process_post(&program_handler_process, LOADER_EVENT_DISPLAY_NAME, pnarg); + } else { + ctk_label_set_text(&errortype, "Out of memory"); + ctk_dialog_open(&errordialog); + } + /* ctk_redraw(); */ + /* ctk_window_redraw(&loadingdialog);*/ +#endif /* WITH_LOADER_ARCH */ +} + +#ifdef WITH_LOADER_ARCH +#define RUN(prg, name, arg) program_handler_load(prg, arg) +#else /* WITH_LOADER_ARCH */ +#define RUN(prg, process, arg) process_start(process, arg) +#endif /* WITH_LOADER_ARCH */ +/*-----------------------------------------------------------------------------------*/ +/** + * Configures the name of the screensaver to be loaded when + * appropriate. + * + * \param name The name of the screensaver or NULL if no screensaver + * should be used. + */ +/*-----------------------------------------------------------------------------------*/ +#if CTK_CONF_SCREENSAVER +void +program_handler_setscreensaver(char *name) +{ + if(name == NULL) { + program_handler_screensaver[0] = 0; + } else { + strncpy(program_handler_screensaver, name, sizeof(program_handler_screensaver)); + } +} +#endif /* CTK_CONF_SCREENSAVER */ +/*-----------------------------------------------------------------------------------*/ +static void +make_windows(void) +{ +#ifdef WITH_LOADER_ARCH + ctk_window_new(&runwindow, 16, 3, "Run"); + + CTK_WIDGET_ADD(&runwindow, &namelabel); + CTK_WIDGET_ADD(&runwindow, &nameentry); + CTK_WIDGET_ADD(&runwindow, &loadbutton); + + CTK_WIDGET_FOCUS(&runwindow, &nameentry); + + ctk_dialog_new(&loadingdialog, 25, 1); + CTK_WIDGET_ADD(&loadingdialog, &loadingmsg); + CTK_WIDGET_ADD(&loadingdialog, &loadingname); + + ctk_dialog_new(&errordialog, 22, 8); + CTK_WIDGET_ADD(&errordialog, &errormsg); + CTK_WIDGET_ADD(&errordialog, &errorfilelabel); + CTK_WIDGET_ADD(&errordialog, &errortype); + CTK_WIDGET_ADD(&errordialog, &errorokbutton); + CTK_WIDGET_FOCUS(&errordialog, &errorokbutton); +#endif /* WITH_LOADER_ARCH */ +} +/*-----------------------------------------------------------------------------------*/ +PROCESS_THREAD(program_handler_process, ev, data) +{ +#ifdef WITH_LOADER_ARCH + unsigned char err; + struct dsc *dsc; +#endif /* WITH_LOADER_ARCH */ + unsigned char i; + struct dsc **dscp; + + PROCESS_BEGIN(); + + /* Create the menus */ + ctk_menu_new(&contikimenu, "Contiki"); + ctk_menu_add(&contikimenu); +#if WITH_LOADER_ARCH + runmenuitem = ctk_menuitem_add(&contikimenu, "Run program..."); + + make_windows(); +#endif /* WITH_LOADER_ARCH */ + + displayname = NULL; + +#if CTK_CONF_SCREENSAVER + program_handler_screensaver[0] = 0; +#endif /* CTK_CONF_SCREENSAVER */ + + while(1) { + PROCESS_WAIT_EVENT(); + if(ev == ctk_signal_button_activate) { +#ifdef WITH_LOADER_ARCH + if(data == (process_data_t)&loadbutton) { + ctk_window_close(&runwindow); + program_handler_load(name, NULL); + } else if(data == (process_data_t)&errorokbutton) { + ctk_dialog_close(); + } +#endif /* WITH_LOADER_ARCH */ + dscp = &contikidsc[0]; + for(i = 0; i < CTK_CONF_MAXMENUITEMS; ++i) { + if(*dscp != NULL && + data == (process_data_t)(*dscp)->icon) { + RUN((*dscp)->prgname, (*dscp)->process, NULL); + break; + } + ++dscp; + } + } else if(ev == ctk_signal_menu_activate) { + if((struct ctk_menu *)data == &contikimenu) { +#if WITH_LOADER_ARCH + dsc = contikidsc[contikimenu.active]; + if(dsc != NULL) { + RUN(dsc->prgname, dsc->process, NULL); + } else if(contikimenu.active == runmenuitem) { + make_windows(); + ctk_window_close(&runwindow); + ctk_window_open(&runwindow); + CTK_WIDGET_FOCUS(&runwindow, &nameentry); + } +#else /* WITH_LOADER_ARCH */ + if(contikidsc[contikimenu.active] != NULL) { + RUN(contikidsc[contikimenu.active]->prgname, + contikidsc[contikimenu.active]->process, + NULL); + } +#endif /* WITH_LOADER_ARCH */ + } +#if CTK_CONF_SCREENSAVER + } else if(ev == ctk_signal_screensaver_start) { +#if WITH_LOADER_ARCH + if(program_handler_screensaver[0] != 0) { + program_handler_load(program_handler_screensaver, NULL); + } +#endif /* WITH_LOADER_ARCH */ +#endif /* CTK_CONF_SCREENSAVER */ + } else if(ev == LOADER_EVENT_DISPLAY_NAME) { +#if WITH_LOADER_ARCH + if(displayname == NULL) { + make_windows(); + + ctk_label_set_text(&loadingname, ((struct pnarg *)data)->name); + ctk_dialog_open(&loadingdialog); + process_post(&program_handler_process, LOADER_EVENT_LOAD, data); + displayname = data; + } else { + /* Try again. */ + process_post(&program_handler_process, LOADER_EVENT_DISPLAY_NAME, data); + } +#endif /* WITH_LOADER_ARCH */ + } else if(ev == LOADER_EVENT_LOAD) { +#if WITH_LOADER_ARCH + if(displayname == data) { + ctk_dialog_close(); + displayname = NULL; + log_message("Loading ", ((struct pnarg *)data)->name); + err = LOADER_LOAD(((struct pnarg *)data)->name, + ((struct pnarg *)data)->arg); + if(err != LOADER_OK) { + make_windows(); + errorfilename[0] = '"'; + strncpy(errorfilename + 1, ((struct pnarg *)data)->name, + sizeof(errorfilename) - 2); + errorfilename[1 + strlen(((struct pnarg *)data)->name)] = '"'; + ctk_label_set_text(&errortype, (char *)errormsgs[err]); + ctk_dialog_open(&errordialog); + log_message((char *)errormsgs[err], errorfilename); + } + pnarg_free(data); + } else { + /* Try again. */ + process_post(&program_handler_process, LOADER_EVENT_DISPLAY_NAME, data); + } +#endif /* WITH_LOADEER_ARCH */ + } + } + PROCESS_END(); +} +/*-----------------------------------------------------------------------------------*/ diff --git a/apps/program-handler/program-handler.h b/apps/program-handler/program-handler.h new file mode 100644 index 000000000..ff240ecc4 --- /dev/null +++ b/apps/program-handler/program-handler.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2002, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the Contiki desktop environment for the C64. + * + * $Id: program-handler.h,v 1.1 2006/06/17 22:41:12 adamdunkels Exp $ + * + */ +#ifndef __PROGRAM_HANDLER_H__ +#define __PROGRAM_HANDLER_H__ + +#include "sys/dsc.h" + +#define program_handler_getscreensaver() program_handler_screensaver + +extern char program_handler_screensaver[]; + +void program_handler_init(void); +void program_handler_load(char *name, char *arg); +void program_handler_setscreensaver(char *name); + +void program_handler_add(struct dsc *dsc, char *menuname, + unsigned char desktop); + +PROCESS_NAME(program_handler_process); + +#endif /* __PROGRAM_HANDLER_H__ */ diff --git a/apps/shell/Makefile.shell b/apps/shell/Makefile.shell new file mode 100644 index 000000000..bbbe64890 --- /dev/null +++ b/apps/shell/Makefile.shell @@ -0,0 +1,2 @@ +APP_SOURCES += shell-gui.c shell.c ctk-textentry-cmdline.c +DSC_SOURCES += shell-dsc.c \ No newline at end of file diff --git a/apps/shell/shell-dsc.c b/apps/shell/shell-dsc.c new file mode 100644 index 000000000..44e001c16 --- /dev/null +++ b/apps/shell/shell-dsc.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2003, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the Contiki desktop environment + * + * $Id: shell-dsc.c,v 1.1 2006/06/17 22:41:12 adamdunkels Exp $ + * + */ + +#include "sys/dsc.h" + +extern struct ctk_icon shell_icon; +/*-----------------------------------------------------------------------------------*/ +DSC(shell_dsc, + "The Contiki command shell", + "shell.prg", + shell_gui_process, + &shell_icon); +/*-----------------------------------------------------------------------------------*/ +#if CTK_CONF_ICON_BITMAPS +static unsigned char shellicon_bitmap[3*3*8] = { + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 +}; +#endif /* CTK_CONF_ICON_BITMAPS */ + +#if CTK_CONF_ICON_TEXTMAPS +static char shellicon_textmap[9] = { + 'C', 'o', 'n', + 't', 'i', 'k', + 'i', 'S', 'h' +}; +#endif /* CTK_CONF_ICON_TEXTMAPS */ + +#if CTK_CONF_ICONS +static struct ctk_icon shell_icon = + {CTK_ICON("Command shell", shellicon_bitmap, shellicon_textmap)}; +#endif /* CTK_CONF_ICONS */ +/*-----------------------------------------------------------------------------------*/ diff --git a/apps/shell/shell-dsc.h b/apps/shell/shell-dsc.h new file mode 100644 index 000000000..b89c8772f --- /dev/null +++ b/apps/shell/shell-dsc.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2003, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the Contiki desktop environment + * + * $Id: shell-dsc.h,v 1.1 2006/06/17 22:41:12 adamdunkels Exp $ + * + */ +#ifndef __SHELL_DSC_H__ +#define __SHELL_DSC_H__ + +#include "sys/dsc.h" + +DSC_HEADER(shell_dsc); + +#endif /* __SHELL_DSC_H__ */ diff --git a/apps/shell/shell-gui.c b/apps/shell/shell-gui.c new file mode 100644 index 000000000..02c0c5f59 --- /dev/null +++ b/apps/shell/shell-gui.c @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2003, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the Contiki desktop OS. + * + * $Id: shell-gui.c,v 1.1 2006/06/17 22:41:12 adamdunkels Exp $ + * + */ + + +#include "program-handler.h" +#include "contiki.h" + +#include "shell.h" + +#include "lib/ctk-textentry-cmdline.h" + +#include + +#ifdef SHELL_GUI_CONF_XSIZE +#define SHELL_GUI_XSIZE SHELL_GUI_CONF_XSIZE +#else +#define SHELL_GUI_XSIZE 10 +#endif + +#ifdef SHELL_GUI_CONF_YSIZE +#define SHELL_GUI_YSIZE SHELL_GUI_CONF_YSIZE +#else +#define SHELL_GUI_YSIZE 10 +#endif + + +static struct ctk_window window; +static char log[SHELL_GUI_XSIZE * SHELL_GUI_YSIZE]; +static struct ctk_label loglabel = + {CTK_LABEL(0, 0, SHELL_GUI_XSIZE, SHELL_GUI_YSIZE, log)}; +static char command[SHELL_GUI_XSIZE - 1]; +static struct ctk_textentry commandentry = + {CTK_TEXTENTRY_INPUT(0, SHELL_GUI_YSIZE, SHELL_GUI_XSIZE - 2, 1, command, + SHELL_GUI_XSIZE - 2, ctk_textentry_cmdline_input)}; + +PROCESS(shell_gui_process, "Command shell"); + +/*-----------------------------------------------------------------------------------*/ +void +shell_quit(char *str) +{ + ctk_window_close(&window); + process_exit(&shell_gui_process); + LOADER_UNLOAD(); +} +/*-----------------------------------------------------------------------------------*/ +void +shell_output(char *str1, char *str2) +{ + static unsigned char i, len; + + for(i = 1; i < SHELL_GUI_YSIZE; ++i) { + memcpy(&log[(i - 1) * SHELL_GUI_XSIZE], + &log[i * SHELL_GUI_XSIZE], SHELL_GUI_XSIZE); + } + memset(&log[(SHELL_GUI_YSIZE - 1) * SHELL_GUI_XSIZE], + 0, SHELL_GUI_XSIZE); + + len = strlen(str1); + + strncpy(&log[(SHELL_GUI_YSIZE - 1) * SHELL_GUI_XSIZE], + str1, SHELL_GUI_XSIZE); + if(len < SHELL_GUI_XSIZE) { + strncpy(&log[(SHELL_GUI_YSIZE - 1) * SHELL_GUI_XSIZE] + len, + str2, SHELL_GUI_XSIZE - len); + } + + CTK_WIDGET_REDRAW(&loglabel); +} +/*-----------------------------------------------------------------------------------*/ +void +shell_prompt(char *str) +{ + +} +/*-----------------------------------------------------------------------------------*/ +PROCESS_THREAD(shell_gui_process, ev, data) +{ + + PROCESS_BEGIN(); + + ctk_window_new(&window, SHELL_GUI_XSIZE, + SHELL_GUI_YSIZE + 1, "Command shell"); + CTK_WIDGET_ADD(&window, &loglabel); + /* CTK_WIDGET_SET_FLAG(&loglabel, CTK_WIDGET_FLAG_MONOSPACE);*/ + CTK_WIDGET_ADD(&window, &commandentry); + /* CTK_WIDGET_SET_FLAG(&commandentry, CTK_WIDGET_FLAG_MONOSPACE);*/ + CTK_WIDGET_FOCUS(&window, &commandentry); + memset(log, 0, sizeof(log)); + + shell_init(); + ctk_window_open(&window); + shell_start(); + + while(1) { + PROCESS_WAIT_EVENT(); + + if(ev == ctk_signal_widget_activate && + data == (process_data_t)&commandentry) { + shell_output("> ", command); + shell_input(command); + CTK_TEXTENTRY_CLEAR(&commandentry); + CTK_WIDGET_REDRAW(&commandentry); + } else if(ev == ctk_signal_window_close || + ev == PROCESS_EVENT_EXIT) { + shell_quit(NULL); + } else { + shell_eventhandler(ev, data); + } + } + PROCESS_END(); +} +/*-----------------------------------------------------------------------------------*/ diff --git a/apps/shell/shell.c b/apps/shell/shell.c new file mode 100644 index 000000000..3f08feb1c --- /dev/null +++ b/apps/shell/shell.c @@ -0,0 +1,284 @@ + /* + * Copyright (c) 2003, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the Contiki desktop OS. + * + * $Id: shell.c,v 1.1 2006/06/17 22:41:12 adamdunkels Exp $ + * + */ + +#include "program-handler.h" +#include "contiki-net.h" +#include "cfs/cfs.h" + +#include "shell.h" + +#include + +static char showingdir = 0; +static struct cfs_dir dir; +static unsigned int totsize; + +struct ptentry { + char c1; + char c2; + void (* pfunc)(char *str); +}; + +/*-----------------------------------------------------------------------------------*/ +static void +parse(register char *str, struct ptentry *t) +{ + register struct ptentry *p; + char *sstr; + + sstr = str; + + /* Loop over the parse table entries in t in order to find one that + matches the first character in str. */ + for(p = t; p->c1 != 0; ++p) { + if(*str == p->c1 || *str == p->c2) { + /* Skip rest of the characters up to the first space. */ + while(*str != ' ') { + ++str; + } + + /* Skip all spaces.*/ + while(*str == ' ') { + ++str; + } + + /* Call parse table entry function and return. */ + p->pfunc(str); + return; + } + } + + /* Did not find matching entry in parse table. We just call the + default handler supplied by the caller and return. */ + p->pfunc(str); +} +/*-----------------------------------------------------------------------------------*/ +static void +inttostr(register char *str, unsigned int i) +{ + str[0] = '0' + i / 100; + if(str[0] == '0') { + str[0] = ' '; + } + str[1] = '0' + (i / 10) % 10; + if(str[0] == ' ' && str[1] == '0') { + str[1] = ' '; + } + str[2] = '0' + i % 10; + str[3] = ' '; + str[4] = 0; +} +/*-----------------------------------------------------------------------------------*/ +static void +processes(char *str) +{ + static char idstr[5]; + struct process *p; + + shell_output("Processes:", ""); + /* Step through each possible process ID and see if there is a + matching process. */ + for(p = PROCESS_LIST(); p != NULL; p = p->next) { + /* inttostr(idstr, p->id);*/ + shell_output(idstr, (char *)p->name); + } +} +/*-----------------------------------------------------------------------------------*/ +static char * +nullterminate(char *str) +{ + char *nt; + + /* Nullterminate string. Start with finding newline character. */ + for(nt = str; *nt != '\r' && + *nt != '\n'; ++nt); + + /* Replace newline with a null char. */ + *nt = 0; + + /* Remove trailing spaces. */ + while(nt > str && *(nt - 1) == ' ') { + *(nt - 1) = 0; + --nt; + } + + /* Return pointer to null char. */ + return nt; +} +/*-----------------------------------------------------------------------------------*/ +static void +runfile(char *str) +{ + nullterminate(str); + + if(strlen(str) > 0) { + /* Call loader function. */ + program_handler_load(str, NULL); + shell_output("Starting program ", str); + } else { + shell_output("Must supply a program name", ""); + } +} +/*-----------------------------------------------------------------------------------*/ +static void +execfile(char *str) +{ + runfile(str); + shell_quit(NULL); +} +/*-----------------------------------------------------------------------------------*/ +static void +killproc(char *str) +{ + char procnum, j, c; + char procstr[5]; + + nullterminate(str); + + procnum = 0; + + for(j = 0; j < 4; ++j) { + c = str[(unsigned int)j]; + if(c >= '0' && c <= '9') { + procnum = procnum * 10 + (str[(unsigned int)j] - '0'); + } else { + break; + } + } + if(procnum != 0) { + inttostr(procstr, procnum); + shell_output("Killing process ", procstr); + } else { + shell_output("Invalid process number", ""); + } + +} +/*-----------------------------------------------------------------------------------*/ +static void +help(char *str) +{ + shell_output("Available commands:", ""); + shell_output("run - start program", ""); + shell_output("exec - start program & exit shell", ""); + shell_output("ps - show processes", ""); + shell_output("kill - kill process", ""); + shell_output("ls - display directory", ""); + shell_output("quit - quit shell", ""); + shell_output("? - show this help", ""); +} +/*-----------------------------------------------------------------------------------*/ +static void +directory(char *str) +{ + if(cfs_opendir(&dir, ".") != 0) { + shell_output("Cannot open directory", ""); + showingdir = 0; + } else { + shell_output("Disk directory:", ""); + showingdir = 1; + totsize = 0; + process_post(PROCESS_CURRENT(), PROCESS_EVENT_CONTINUE, NULL); + } + +} +/*-----------------------------------------------------------------------------------*/ +static void +none(char *str) +{ +} +/*-----------------------------------------------------------------------------------*/ +static struct ptentry configparsetab[] = + {{'e', 'E', execfile}, + {'r', 'R', runfile}, + {'k', 'K', killproc}, + {'p', 'P', processes}, + {'l', 'L', directory}, + {'q', 'Q', shell_quit}, + {'h', '?', help}, + + /* Default action */ + {0, 0, none}}; +/*-----------------------------------------------------------------------------------*/ +void +shell_init(void) +{ +} +/*-----------------------------------------------------------------------------------*/ +void +shell_start(void) +{ + showingdir = 0; + shell_output("Contiki command shell", ""); + shell_output("Type '?' and return for help", ""); + shell_prompt("contiki> "); +} +/*-----------------------------------------------------------------------------------*/ +void +shell_input(char *cmd) +{ + if(showingdir != 0) { + showingdir = 0; + shell_output("Directory stopped", ""); + cfs_closedir(&dir); + } + parse(cmd, configparsetab); + if(showingdir == 0) { + shell_prompt("contiki> "); + } +} +/*-----------------------------------------------------------------------------------*/ +void +shell_eventhandler(process_event_t ev, process_data_t data) +{ + static struct cfs_dirent dirent; + static char size[10]; + + if(ev == PROCESS_EVENT_CONTINUE) { + if(showingdir != 0) { + if(cfs_readdir(&dir, &dirent) != 0) { + cfs_closedir(&dir); + showingdir = 0; + inttostr(size, totsize); + shell_output("Total number of blocks: ", size); + shell_prompt("contiki> "); + } else { + totsize += dirent.size; + inttostr(size, dirent.size); + shell_output(size, dirent.name); + process_post(PROCESS_CURRENT(), PROCESS_EVENT_CONTINUE, NULL); + } + } + } +} +/*-----------------------------------------------------------------------------------*/ diff --git a/apps/shell/shell.h b/apps/shell/shell.h new file mode 100644 index 000000000..7fbe4c4e5 --- /dev/null +++ b/apps/shell/shell.h @@ -0,0 +1,114 @@ +/** + * \file + * Interface for the Contiki shell. + * \author Adam Dunkels + * + * Some of the functions declared in this file must be implemented as + * a shell back-end in the architecture specific files of a Contiki + * port. + */ + + +/* + * Copyright (c) 2003, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the Contiki desktop OS. + * + * $Id: shell.h,v 1.1 2006/06/17 22:41:12 adamdunkels Exp $ + * + */ +#ifndef __SHELL_H__ +#define __SHELL_H__ + +/** + * Initialize the shell. + * + * Called when the shell front-end process starts. This function may + * be used to start listening for signals. + */ +void shell_init(void); + +/** + * Start the shell back-end. + * + * Called by the front-end when a new shell is started. + */ +void shell_start(void); + +/** + * The shell event handler. + * + * This function will be called when an event is received. + */ +void shell_eventhandler(process_event_t ev, process_data_t data); + +/** + * Process a shell command. + * + * This function will be called by the shell GUI / telnet server whan + * a command has been entered that should be processed by the shell + * back-end. + * + * \param command The command to be processed. + */ +void shell_input(char *command); + +/** + * Quit the shell. + * + */ +void shell_quit(char *); + + +/** + * Print a string to the shell window. + * + * This function is implemented by the shell GUI / telnet server and + * can be called by the shell back-end to output a string in the + * shell window. The string is automatically appended with a linebreak. + * + * \param str1 The first half of the string to be output. + * \param str2 The second half of the string to be output. + */ +void shell_output(char *str1, char *str2); + +/** + * Print a prompt to the shell window. + * + * This function can be used by the shell back-end to print out a + * prompt to the shell window. + * + * \param prompt The prompt to be printed. + * + */ +void shell_prompt(char *prompt); + +#endif /* __SHELL_H__ */ + + + diff --git a/apps/telnet/Makefile.telnet b/apps/telnet/Makefile.telnet new file mode 100644 index 000000000..92ffd3a60 --- /dev/null +++ b/apps/telnet/Makefile.telnet @@ -0,0 +1,2 @@ +APP_SOURCES += simpletelnet.c telnet.c +DSC_SOURCES += telnet-dsc.c \ No newline at end of file diff --git a/apps/telnet/simpletelnet.c b/apps/telnet/simpletelnet.c new file mode 100644 index 000000000..b2726deee --- /dev/null +++ b/apps/telnet/simpletelnet.c @@ -0,0 +1,310 @@ +/* + * Copyright (c) 2002, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the Contiki desktop environment + * + * $Id: simpletelnet.c,v 1.1 2006/06/17 22:41:12 adamdunkels Exp $ + * + */ + +#include + +#include "contiki-net.h" +#include "lib/petsciiconv.h" +#include "ctk/ctk.h" + +#include "telnet.h" +#include "simpletelnet.h" + +/* Telnet window */ +static struct ctk_window telnetwindow; + +static struct ctk_label telnethostlabel = + {CTK_LABEL(1, 0, 4, 1, "Host")}; +static char telnethost[25]; +static struct ctk_textentry telnethosttextentry = + {CTK_TEXTENTRY(0, 1, 24, 1, telnethost, 24)}; + +static struct ctk_label telnetportlabel = + {CTK_LABEL(31, 0, 4, 1, "Port")}; +static char telnetport[6]; +static struct ctk_textentry telnetporttextentry = + {CTK_TEXTENTRY(30, 1, 5, 1, telnetport, 5)}; + +static struct ctk_button telnetconnectbutton = + {CTK_BUTTON(2, 3, 7, "Connect")}; +static struct ctk_button telnetdisconnectbutton = + {CTK_BUTTON(25, 3, 10, "Disconnect")}; + +static char telnetline[31]; +static struct ctk_textentry telnetlinetextentry = + {CTK_TEXTENTRY(0, 5, 30, 1, telnetline, 30)}; + + +static struct ctk_button telnetsendbutton = + {CTK_BUTTON(32, 5, 4, "Send")}; + +static struct ctk_label telnetstatus = + {CTK_LABEL(0, 19, 38, 1, "")}; + +static struct ctk_separator telnetsep1 = + {CTK_SEPARATOR(0, 7, 38)}; + +static struct ctk_separator telnetsep2 = + {CTK_SEPARATOR(0, 18, 38)}; + +static char telnettext[38*10]; +static struct ctk_label telnettextarea = + {CTK_LABEL(0, 8, 38, 10, telnettext)}; + +static struct telnet_state ts_appstate; + +#define ISO_NL 0x0a +#define ISO_CR 0x0d + +static char sendline[31+2]; + +PROCESS(simpletelnet_process, "Telnet client"); + +/*-----------------------------------------------------------------------------------*/ +static void +scrollup(void) +{ + unsigned char i; + for(i = 1; i < 10; ++i) { + memcpy(&telnettext[(i - 1) * 38], &telnettext[i * 38], 38); + } + memset(&telnettext[9 * 38], 0, 38); +} +/*-----------------------------------------------------------------------------------*/ +static void +add_text(char *text) +{ + unsigned char i; + unsigned int len; + + len = strlen(text); + + i = 0; + while(len > 0) { + if(*text == '\n') { + scrollup(); + i = 0; + } else if(*text == '\r') { + i = 0; + } else if(*text >= ' ') { + telnettext[9 * 38 + i] = *text; + ++i; + if(i == 38) { + scrollup(); + i = 0; + } + } + ++text; + --len; + } + + /* if(strlen(text) > 37) { + memcpy(&telnettext[9 * 38], text, 37); + } else { + memcpy(&telnettext[9 * 38], text, strlen(text)); + } + */ +} +/*-----------------------------------------------------------------------------------*/ +static void +show(char *text) +{ + add_text(text); + add_text("\n"); + ctk_label_set_text(&telnetstatus, text); + ctk_window_redraw(&telnetwindow); +} +/*-----------------------------------------------------------------------------------*/ +static void +connect(void) +{ + u16_t addr[2], *addrptr; + u16_t port; + char *cptr; + struct uip_conn *conn; + + /* Find the first space character in host and put a zero there + to end the string. */ + for(cptr = telnethost; *cptr != ' ' && *cptr != 0; ++cptr); + *cptr = 0; + + addrptr = &addr[0]; + if(uiplib_ipaddrconv(telnethost, (unsigned char *)addr) == 0) { + addrptr = resolv_lookup(telnethost); + if(addrptr == NULL) { + resolv_query(telnethost); + show("Resolving host..."); + return; + } + } + + port = 0; + for(cptr = telnetport; *cptr != ' ' && *cptr != 0; ++cptr) { + if(*cptr < '0' || *cptr > '9') { + show("Port number error"); + return; + } + port = 10 * port + *cptr - '0'; + } + + + conn = tcp_connect(addrptr, htons(port), &ts_appstate); + if(conn == NULL) { + show("Out of memory error"); + return; + } + + show("Connecting..."); + +} +/*-----------------------------------------------------------------------------------*/ +PROCESS_THREAD(simpletelnet_process, ev, data) +{ + struct ctk_widget *w; + int sendlen; + + PROCESS_BEGIN(); + + ctk_window_new(&telnetwindow, 38, 20, "Simple telnet"); + + strcpy(telnetport, "23"); + + CTK_WIDGET_ADD(&telnetwindow, &telnethostlabel); + CTK_WIDGET_ADD(&telnetwindow, &telnetportlabel); + CTK_WIDGET_ADD(&telnetwindow, &telnethosttextentry); + CTK_WIDGET_ADD(&telnetwindow, &telnetporttextentry); + CTK_WIDGET_ADD(&telnetwindow, &telnetconnectbutton); + CTK_WIDGET_ADD(&telnetwindow, &telnetdisconnectbutton); + CTK_WIDGET_ADD(&telnetwindow, &telnetlinetextentry); + CTK_WIDGET_ADD(&telnetwindow, &telnetsendbutton); + + CTK_WIDGET_ADD(&telnetwindow, &telnetsep1); + CTK_WIDGET_ADD(&telnetwindow, &telnettextarea); + + CTK_WIDGET_ADD(&telnetwindow, &telnetsep2); + CTK_WIDGET_ADD(&telnetwindow, &telnetstatus); + + CTK_WIDGET_FOCUS(&telnetwindow, &telnethosttextentry); + + ctk_window_open(&telnetwindow); + + while(1) { + PROCESS_WAIT_EVENT(); + if(ev == ctk_signal_button_activate) { + + w = (struct ctk_widget *)data; + if(w == (struct ctk_widget *)&telnetsendbutton) { + strcpy(sendline, telnetline); + sendlen = strlen(sendline); + petsciiconv_toascii(sendline, sendlen); + sendline[sendlen++] = ISO_CR; + sendline[sendlen++] = ISO_NL; + if(telnet_send(&ts_appstate, sendline, sendlen)) { + /* Could not send. */ + ctk_label_set_text(&telnetstatus, "Could not send"); + ctk_window_redraw(&telnetwindow); + /* } else {*/ + /* Could send */ + } + } else if(w == (struct ctk_widget *)&telnetdisconnectbutton) { + telnet_close(&ts_appstate); + show("Closing..."); + } else if(w == (struct ctk_widget *)&telnetconnectbutton) { + connect(); + ctk_window_redraw(&telnetwindow); + } + } else if(ev == resolv_event_found) { + if(strcmp(data, telnethost) == 0) { + if(resolv_lookup(telnethost) != NULL) { + connect(); + } else { + show("Host not found"); + } + } + } else if(ev == ctk_signal_window_close || + ev == PROCESS_EVENT_EXIT) { + process_exit(&simpletelnet_process); + ctk_window_close(&telnetwindow); + LOADER_UNLOAD(); + } else if(ev == tcpip_event) { + telnet_app(data); + } + } + PROCESS_END(); +} +/*-----------------------------------------------------------------------------------*/ +void +telnet_connected(struct telnet_state *s) +{ + show("Connected"); +} +/*-----------------------------------------------------------------------------------*/ +void +telnet_closed(struct telnet_state *s) +{ + show("Connection closed"); +} +/*-----------------------------------------------------------------------------------*/ +void +telnet_sent(struct telnet_state *s) +{ + petsciiconv_topetscii(sendline, sizeof(sendline)); + scrollup(); + add_text(sendline); + CTK_TEXTENTRY_CLEAR(&telnetlinetextentry); + ctk_window_redraw(&telnetwindow); +} +/*-----------------------------------------------------------------------------------*/ +void +telnet_aborted(struct telnet_state *s) +{ + show("Connection reset by peer"); +} +/*-----------------------------------------------------------------------------------*/ +void +telnet_timedout(struct telnet_state *s) +{ + show("Connection timed out"); +} +/*-----------------------------------------------------------------------------------*/ +void +telnet_newdata(struct telnet_state *s, char *data, u16_t len) +{ + petsciiconv_topetscii(data, len); + data[len] = 0; + add_text(data); + ctk_window_redraw(&telnetwindow); +} +/*-----------------------------------------------------------------------------------*/ diff --git a/apps/telnet/simpletelnet.h b/apps/telnet/simpletelnet.h new file mode 100644 index 000000000..3c2794397 --- /dev/null +++ b/apps/telnet/simpletelnet.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2002, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the Contiki desktop environment for the C64. + * + * $Id: simpletelnet.h,v 1.1 2006/06/17 22:41:12 adamdunkels Exp $ + * + */ +#ifndef __SIMPLETELNET_H__ +#define __SIMPLETELNET_H__ + +void simpletelnet_init(char *arg); + +#endif /* __SIMPLETELNET_H__ */ diff --git a/apps/telnet/telnet-dsc.c b/apps/telnet/telnet-dsc.c new file mode 100644 index 000000000..472325c6a --- /dev/null +++ b/apps/telnet/telnet-dsc.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2003, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the Contiki desktop environment + * + * $Id: telnet-dsc.c,v 1.1 2006/06/17 22:41:12 adamdunkels Exp $ + * + */ + +#include "sys/dsc.h" + +extern struct ctk_icon telnet_icon; +/*-----------------------------------------------------------------------------------*/ +DSC(telnet_dsc, + "A simple Telnet client", + "telnet.prg", + simpletelnet_process, + &telnet_icon); +/*-----------------------------------------------------------------------------------*/ +#if CTK_CONF_ICON_BITMAPS +static unsigned char telneticon_bitmap[3*3*8] = { + 0x00, 0x7f, 0x43, 0x4c, 0x58, 0x53, 0x60, 0x6f, + 0x00, 0xff, 0x00, 0x7e, 0x00, 0xff, 0x00, 0xff, + 0x00, 0xfe, 0xc2, 0x32, 0x1a, 0xca, 0x06, 0xf6, + + 0x40, 0x5f, 0x40, 0x5f, 0x40, 0x5f, 0x40, 0x4f, + 0x00, 0xff, 0x00, 0xff, 0x00, 0xfc, 0x01, 0xf3, + 0x02, 0xfa, 0x02, 0x82, 0x3e, 0xfe, 0xfe, 0xfe, + + 0x60, 0x67, 0x50, 0x59, 0x4c, 0x43, 0x7f, 0x00, + 0x07, 0xe7, 0x0f, 0xef, 0x0f, 0x0f, 0xff, 0x00, + 0x8e, 0x06, 0x06, 0x06, 0x8e, 0xfe, 0xfe, 0x00 +}; +#endif /* CTK_CONF_ICON_BITMAPS */ + +#if CTK_CONF_ICON_TEXTMAPS +static char telneticon_textmap[9] = { + 't', 'e', 'l', + 'n', 'e', 't', + '-', '-', '-' +}; +#endif /* CTK_CONF_ICON_TEXTMAPS */ + +#if CTK_CONF_ICONS +static struct ctk_icon telnet_icon = + {CTK_ICON("Telnet", telneticon_bitmap, telneticon_textmap)}; +#endif /* CTK_CONF_ICONS */ +/*-----------------------------------------------------------------------------------*/ diff --git a/apps/telnet/telnet-dsc.h b/apps/telnet/telnet-dsc.h new file mode 100644 index 000000000..14ee95fba --- /dev/null +++ b/apps/telnet/telnet-dsc.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2003, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the Contiki desktop environment + * + * $Id: telnet-dsc.h,v 1.1 2006/06/17 22:41:12 adamdunkels Exp $ + * + */ +#ifndef __TELNET_DSC_H__ +#define __TELNET_DSC_H__ + +#include "sys/dsc.h" + +DSC_HEADER(telnet_dsc); + +#endif /* __TELNET_DSC_H__ */ diff --git a/apps/telnet/telnet.c b/apps/telnet/telnet.c new file mode 100644 index 000000000..72f8bb5d2 --- /dev/null +++ b/apps/telnet/telnet.c @@ -0,0 +1,152 @@ +/* + * Copyright (c) 2002, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the uIP TCP/IP stack. + * + * $Id: telnet.c,v 1.1 2006/06/17 22:41:13 adamdunkels Exp $ + * + */ + +#include "contiki-net.h" + +#include "telnet.h" + +#ifndef NULL +#define NULL (void *)0 +#endif /* NULL */ + +#define FLAG_CLOSE 1 +#define FLAG_ABORT 2 +/*-----------------------------------------------------------------------------------*/ +unsigned char +telnet_send(struct telnet_state *s, char *text, u16_t len) +{ + if(s->text != NULL) { + return 1; + } + s->text = text; + s->textlen = len; + s->sentlen = 0; + return 0; +} +/*-----------------------------------------------------------------------------------*/ +unsigned char +telnet_close(struct telnet_state *s) +{ + s->flags = FLAG_CLOSE; + if(s->text != NULL) { + return 1; + } + return 0; +} +/*-----------------------------------------------------------------------------------*/ +unsigned char +telnet_abort(struct telnet_state *s) +{ + s->flags = FLAG_ABORT; + if(s->text != NULL) { + return 1; + } + return 0; +} +/*-----------------------------------------------------------------------------------*/ +static void +acked(struct telnet_state *s) +{ + s->textlen -= s->sentlen; + if(s->textlen == 0) { + s->text = NULL; + telnet_sent(s); + } else { + s->text += s->sentlen; + } + s->sentlen = 0; +} +/*-----------------------------------------------------------------------------------*/ +static void +senddata(struct telnet_state *s) +{ + if(s->text == NULL) { + uip_send(s->text, 0); + return; + } + if(s->textlen > uip_mss()) { + s->sentlen = uip_mss(); + } else { + s->sentlen = s->textlen; + } + uip_send(s->text, s->sentlen); +} +/*-----------------------------------------------------------------------------------*/ +void +telnet_app(void *ts) +{ + struct telnet_state *s = (struct telnet_state *)ts; + + if(uip_connected()) { + s->flags = 0; + telnet_connected(s); + senddata(s); + return; + } + + if(uip_closed()) { + telnet_closed(s); + } + + if(uip_aborted()) { + telnet_aborted(s); + } + if(uip_timedout()) { + telnet_timedout(s); + } + + + if(s->flags & FLAG_CLOSE) { + uip_close(); + return; + } + if(s->flags & FLAG_ABORT) { + uip_abort(); + return; + } + if(uip_acked()) { + acked(s); + } + if(uip_newdata()) { + telnet_newdata(s, (char *)uip_appdata, uip_datalen()); + } + if(uip_rexmit() || + uip_newdata() || + uip_acked()) { + senddata(s); + } else if(uip_poll()) { + senddata(s); + } +} +/*-----------------------------------------------------------------------------------*/ diff --git a/apps/telnet/telnet.h b/apps/telnet/telnet.h new file mode 100644 index 000000000..baaae1bc8 --- /dev/null +++ b/apps/telnet/telnet.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2002, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the uIP TCP/IP stack. + * + * $Id: telnet.h,v 1.1 2006/06/17 22:41:13 adamdunkels Exp $ + * + */ +#ifndef __TELNET_H__ +#define __TELNET_H__ + +#include "contiki-net.h" + +struct telnet_state { + unsigned char flags; + char *text; + u16_t textlen; + u16_t sentlen; +}; + +/*DISPATCHER_UIPCALL(telnet_app, s);*/ +void telnet_app(void *s); +unsigned char telnet_send(struct telnet_state *s, char *text, u16_t len); +unsigned char telnet_close(struct telnet_state *s); +unsigned char telnet_abort(struct telnet_state *s); + +/* Callbacks, implemented by the caller. */ +void telnet_connected(struct telnet_state *s); +void telnet_closed(struct telnet_state *s); +void telnet_sent(struct telnet_state *s); +void telnet_aborted(struct telnet_state *s); +void telnet_timedout(struct telnet_state *s); +void telnet_newdata(struct telnet_state *s, char *data, u16_t len); +#endif /* __TELNET_H__ */ diff --git a/apps/telnetd/Makefile.telnetd b/apps/telnetd/Makefile.telnetd new file mode 100644 index 000000000..fcfd002af --- /dev/null +++ b/apps/telnetd/Makefile.telnetd @@ -0,0 +1,2 @@ +APP_SOURCES += telnetd.c shell.c +DSC_SOURCES += telnetd-dsc.c diff --git a/apps/telnetd/telnetd-dsc.c b/apps/telnetd/telnetd-dsc.c new file mode 100644 index 000000000..01a5cc175 --- /dev/null +++ b/apps/telnetd/telnetd-dsc.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2003, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the Contiki desktop environment + * + * $Id: telnetd-dsc.c,v 1.1 2006/06/17 22:41:13 adamdunkels Exp $ + * + */ + +#include "sys/dsc.h" + +extern struct ctk_icon telnetd_icon; +/*-----------------------------------------------------------------------------------*/ +DSC(telnetd_dsc, + "Telnet shell server", + "telnetd.prg", + telnetd_process, + &telnetd_icon); +/*-----------------------------------------------------------------------------------*/ +#if CTK_CONF_ICON_BITMAPS +static unsigned char telnetdicon_bitmap[3*3*8] = { + 0x00, 0x7f, 0x43, 0x4c, 0x58, 0x53, 0x60, 0x6f, + 0x00, 0xff, 0x00, 0x7e, 0x00, 0xff, 0x00, 0xff, + 0x00, 0xfe, 0xc2, 0x32, 0x1a, 0xca, 0x06, 0xf6, + + 0x40, 0x5f, 0x40, 0x5f, 0x40, 0x5f, 0x40, 0x4f, + 0x00, 0xff, 0x00, 0xff, 0x00, 0xfc, 0x01, 0xf3, + 0x02, 0xfa, 0x02, 0x82, 0x3e, 0xfe, 0xfe, 0xfe, + + 0x60, 0x67, 0x50, 0x59, 0x4c, 0x43, 0x7f, 0x00, + 0x07, 0xe7, 0x0f, 0xef, 0x0f, 0x0f, 0xff, 0x00, + 0x8e, 0x06, 0x06, 0x06, 0x8e, 0xfe, 0xfe, 0x00 +}; +#endif /* CTK_CONF_ICON_BITMAPS */ + +#if CTK_CONF_ICON_TEXTMAPS +static char telnetdicon_textmap[9] = { + 't', 'e', 'l', + 'n', 'e', 't', + 's', 'r', 'v' +}; +#endif /* CTK_CONF_ICON_TEXTMAPS */ + +#if CTK_CONF_ICONS +static struct ctk_icon telnetd_icon = + {CTK_ICON("Telnet server", telnetdicon_bitmap, telnetdicon_textmap)}; +#endif /* CTK_CONF_ICONS */ +/*-----------------------------------------------------------------------------------*/ diff --git a/apps/telnetd/telnetd-dsc.h b/apps/telnetd/telnetd-dsc.h new file mode 100644 index 000000000..1501f6fbd --- /dev/null +++ b/apps/telnetd/telnetd-dsc.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2003, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the Contiki desktop environment + * + * $Id: telnetd-dsc.h,v 1.1 2006/06/17 22:41:13 adamdunkels Exp $ + * + */ +#ifndef __TELNETD_DSC_H__ +#define __TELNETD_DSC_H__ + +#include "sys/dsc.h" + +DSC_HEADER(telnetd_dsc); + +#endif /* __TELNETD_DSC_H__ */ diff --git a/apps/telnetd/telnetd-gui.c b/apps/telnetd/telnetd-gui.c new file mode 100644 index 000000000..f09f12097 --- /dev/null +++ b/apps/telnetd/telnetd-gui.c @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2003, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the Contiki desktop OS. + * + * $Id: telnetd-gui.c,v 1.1 2006/06/17 22:41:13 adamdunkels Exp $ + * + */ + +#include "program-handler.h" +#include "contiki-net.h" +#include "lib/petsciiconv.h" + +#include "shell.h" +#include "telnetd.h" + +#include + +#define ISO_nl 0x0a +#define ISO_cr 0x0d + +#define XSIZE 36 +#define YSIZE 12 + +static struct ctk_window window; +static char log[XSIZE * YSIZE]; +static struct ctk_label loglabel = + {CTK_LABEL(0, 0, XSIZE, YSIZE, log)}; + +/*-----------------------------------------------------------------------------------*/ +void +telnetd_gui_output(char *str1, char *str2) +{ + static unsigned int len, i; + + for(i = 1; i < YSIZE; ++i) { + memcpy(&log[(i - 1) * XSIZE], &log[i * XSIZE], XSIZE); + } + memset(&log[(YSIZE - 1) * XSIZE], 0, XSIZE); + + len = strlen(str1); + + strncpy(&log[(YSIZE - 1) * XSIZE], str1, XSIZE); + if(len < XSIZE) { + strncpy(&log[(YSIZE - 1) * XSIZE] + len, str2, XSIZE - len); + } + + CTK_WIDGET_REDRAW(&loglabel); +} +/*-----------------------------------------------------------------------------------*/ +void +telnetd_gui_quit(void) +{ + ctk_window_close(&window); +} +/*-----------------------------------------------------------------------------------*/ +void +telnetd_gui_init(void) +{ + ctk_window_new(&window, XSIZE, YSIZE, "Shell server"); + CTK_WIDGET_ADD(&window, &loglabel); + memset(log, 0, sizeof(log)); + ctk_window_open(&window); +} +/*-----------------------------------------------------------------------------------*/ +void +telnetd_gui_eventhandler(process_event_t ev, process_data_t data) +{ + if(ev == ctk_signal_window_close) { + telnetd_quit(); + } +} +/*-----------------------------------------------------------------------------------*/ diff --git a/apps/telnetd/telnetd.c b/apps/telnetd/telnetd.c new file mode 100644 index 000000000..34ed57c88 --- /dev/null +++ b/apps/telnetd/telnetd.c @@ -0,0 +1,399 @@ +/* + * Copyright (c) 2003, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the Contiki desktop OS. + * + * $Id: telnetd.c,v 1.1 2006/06/17 22:41:13 adamdunkels Exp $ + * + */ + +#include "contiki-net.h" +#include "lib/petsciiconv.h" +#include "contiki-lib.h" + +#include "shell.h" +#include "telnetd.h" + + +#include + +#define ISO_nl 0x0a +#define ISO_cr 0x0d + +#define XSIZE 36 +#define YSIZE 12 + +PROCESS(telnetd_process, "Shell server"); + +#ifndef TELNETD_CONF_LINELEN +#define TELNETD_CONF_LINELEN 40 +#endif +#ifndef TELNETD_CONF_NUMLINES +#define TELNETD_CONF_NUMLINES 16 +#endif + +struct telnetd_line { + char line[TELNETD_CONF_LINELEN]; +}; +MEMB(linemem, struct telnetd_line, TELNETD_CONF_NUMLINES); + +struct telnetd_state { + char *lines[TELNETD_CONF_NUMLINES]; + char buf[TELNETD_CONF_LINELEN]; + char bufptr; + u8_t numsent; + u8_t state; +#define STATE_NORMAL 0 +#define STATE_IAC 1 +#define STATE_WILL 2 +#define STATE_WONT 3 +#define STATE_DO 4 +#define STATE_DONT 5 + +#define STATE_CLOSE 6 +}; +static struct telnetd_state s; + +#define TELNET_IAC 255 +#define TELNET_WILL 251 +#define TELNET_WONT 252 +#define TELNET_DO 253 +#define TELNET_DONT 254 +/*-----------------------------------------------------------------------------------*/ +static char * +alloc_line(void) +{ + return memb_alloc(&linemem); +} +/*-----------------------------------------------------------------------------------*/ +static void +dealloc_line(char *line) +{ + memb_free(&linemem, line); +} +/*-----------------------------------------------------------------------------------*/ +void +shell_quit(char *str) +{ + s.state = STATE_CLOSE; +} +/*-----------------------------------------------------------------------------------*/ +void +telnetd_quit(void) +{ +#if TELNETD_CONF_GUI + telnetd_gui_quit(); +#endif /* TELNETD_CONF_GUI */ + process_exit(&telnetd_process); + LOADER_UNLOAD(); +} +/*-----------------------------------------------------------------------------------*/ +static void +sendline(char *line) +{ + static unsigned int i; + + for(i = 0; i < TELNETD_CONF_NUMLINES; ++i) { + if(s.lines[i] == NULL) { + s.lines[i] = line; + break; + } + } + if(i == TELNETD_CONF_NUMLINES) { + dealloc_line(line); + } +} +/*-----------------------------------------------------------------------------------*/ +void +shell_prompt(char *str) +{ + char *line; + line = alloc_line(); + if(line != NULL) { + strncpy(line, str, TELNETD_CONF_LINELEN); + petsciiconv_toascii(line, TELNETD_CONF_LINELEN); + sendline(line); + } +} +/*-----------------------------------------------------------------------------------*/ +void +shell_output(char *str1, char *str2) +{ + static unsigned len; + char *line; + + line = alloc_line(); + if(line != NULL) { + len = strlen(str1); + strncpy(line, str1, TELNETD_CONF_LINELEN); + if(len < TELNETD_CONF_LINELEN) { + strncpy(line + len, str2, TELNETD_CONF_LINELEN - len); + } + len = strlen(line); + if(len < TELNETD_CONF_LINELEN - 2) { + line[len] = ISO_cr; + line[len+1] = ISO_nl; + line[len+2] = 0; + } + petsciiconv_toascii(line, TELNETD_CONF_LINELEN); + sendline(line); + } +} +/*-----------------------------------------------------------------------------------*/ +PROCESS_THREAD(telnetd_process, ev, data) +{ + PROCESS_BEGIN(); + + tcp_listen(HTONS(23)); + memb_init(&linemem); + shell_init(); + + while(1) { + PROCESS_WAIT_EVENT(); + if(ev == tcpip_event) { + telnetd_appcall(data); + } else if(ev == PROCESS_EVENT_EXIT) { + telnetd_quit(); + } else { +#if TELNETD_CONF_GUI + telnetd_gui_eventhandler(ev, data); +#endif /* TELNETD_CONF_GUI */ + } + } + + PROCESS_END(); +} +/*-----------------------------------------------------------------------------------*/ +static void +acked(void) +{ + static unsigned int i; + + while(s.numsent > 0) { + dealloc_line(s.lines[0]); + for(i = 1; i < TELNETD_CONF_NUMLINES; ++i) { + s.lines[i - 1] = s.lines[i]; + } + s.lines[TELNETD_CONF_NUMLINES - 1] = NULL; + --s.numsent; + } +} +/*-----------------------------------------------------------------------------------*/ +static void +senddata(void) +{ + static char *bufptr, *lineptr; + static int buflen, linelen; + + bufptr = uip_appdata; + buflen = 0; + for(s.numsent = 0; s.numsent < TELNETD_CONF_NUMLINES && + s.lines[s.numsent] != NULL ; ++s.numsent) { + lineptr = s.lines[s.numsent]; + linelen = strlen(lineptr); + if(linelen > TELNETD_CONF_LINELEN) { + linelen = TELNETD_CONF_LINELEN; + } + if(buflen + linelen < uip_mss()) { + memcpy(bufptr, lineptr, linelen); + bufptr += linelen; + buflen += linelen; + } else { + break; + } + } + uip_send(uip_appdata, buflen); +} +/*-----------------------------------------------------------------------------------*/ +static void +closed(void) +{ + static unsigned int i; + + for(i = 0; i < TELNETD_CONF_NUMLINES; ++i) { + if(s.lines[i] != NULL) { + dealloc_line(s.lines[i]); + } + } +} +/*-----------------------------------------------------------------------------------*/ +static void +get_char(u8_t c) +{ + if(c == ISO_cr) { + return; + } + + s.buf[(int)s.bufptr] = c; + if(s.buf[(int)s.bufptr] == ISO_nl || + s.bufptr == sizeof(s.buf) - 1) { + if(s.bufptr > 0) { + s.buf[(int)s.bufptr] = 0; + petsciiconv_topetscii(s.buf, TELNETD_CONF_LINELEN); + } + shell_input(s.buf); + s.bufptr = 0; + } else { + ++s.bufptr; + } +} +/*-----------------------------------------------------------------------------------*/ +static void +sendopt(u8_t option, u8_t value) +{ + char *line; + line = alloc_line(); + if(line != NULL) { + line[0] = TELNET_IAC; + line[1] = option; + line[2] = value; + line[3] = 0; + sendline(line); + } +} +/*-----------------------------------------------------------------------------------*/ +static void +newdata(void) +{ + u16_t len; + u8_t c; + + + len = uip_datalen(); + + while(len > 0 && s.bufptr < sizeof(s.buf)) { + c = *(char *)uip_appdata; + ++((char *)uip_appdata); + --len; + switch(s.state) { + case STATE_IAC: + if(c == TELNET_IAC) { + get_char(c); + s.state = STATE_NORMAL; + } else { + switch(c) { + case TELNET_WILL: + s.state = STATE_WILL; + break; + case TELNET_WONT: + s.state = STATE_WONT; + break; + case TELNET_DO: + s.state = STATE_DO; + break; + case TELNET_DONT: + s.state = STATE_DONT; + break; + default: + s.state = STATE_NORMAL; + break; + } + } + break; + case STATE_WILL: + /* Reply with a DONT */ + sendopt(TELNET_DONT, c); + s.state = STATE_NORMAL; + break; + + case STATE_WONT: + /* Reply with a DONT */ + sendopt(TELNET_DONT, c); + s.state = STATE_NORMAL; + break; + case STATE_DO: + /* Reply with a WONT */ + sendopt(TELNET_WONT, c); + s.state = STATE_NORMAL; + break; + case STATE_DONT: + /* Reply with a WONT */ + sendopt(TELNET_WONT, c); + s.state = STATE_NORMAL; + break; + case STATE_NORMAL: + if(c == TELNET_IAC) { + s.state = STATE_IAC; + } else { + get_char(c); + } + break; + } + + + } + +} +/*-----------------------------------------------------------------------------------*/ +void +telnetd_appcall(void *ts) +{ + static unsigned int i; + if(uip_connected()) { + tcp_markconn(uip_conn, &s); + for(i = 0; i < TELNETD_CONF_NUMLINES; ++i) { + s.lines[i] = NULL; + } + s.bufptr = 0; + s.state = STATE_NORMAL; + + shell_start(); + } + + if(s.state == STATE_CLOSE) { + s.state = STATE_NORMAL; + uip_close(); + return; + } + + if(uip_closed() || + uip_aborted() || + uip_timedout()) { + closed(); + } + + if(uip_acked()) { + acked(); + } + + if(uip_newdata()) { + newdata(); + } + + if(uip_rexmit() || + uip_newdata() || + uip_acked() || + uip_connected() || + uip_poll()) { + senddata(); + } +} +/*-----------------------------------------------------------------------------------*/ +void +program_handler_load(char *name, char *arg) +{} diff --git a/apps/telnetd/telnetd.h b/apps/telnetd/telnetd.h new file mode 100644 index 000000000..c347a2d85 --- /dev/null +++ b/apps/telnetd/telnetd.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2003, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the Contiki desktop environment + * + * $Id: telnetd.h,v 1.1 2006/06/17 22:41:13 adamdunkels Exp $ + * + */ +#ifndef __TELNETD_H__ +#define __TELNETD_H__ + +#include "contiki.h" + + +PROCESS_NAME(telnetd_process); + +void telnetd_gui_eventhandler(process_event_t ev, process_data_t data); +void telnetd_appcall(void *data); +void telnetd_gui_output(char *str1, char *str2); +void telnetd_gui_quit(void); +void telnetd_quit(void); + +#endif /* __TELNETD_H__ */ diff --git a/apps/webbrowser/Makefile.webbrowser b/apps/webbrowser/Makefile.webbrowser new file mode 100644 index 000000000..fede31c05 --- /dev/null +++ b/apps/webbrowser/Makefile.webbrowser @@ -0,0 +1,3 @@ +APP_SOURCES += www.c webclient.c http-strings.c http-user-agent-string.c \ + htmlparser.c html-strings.c +DSC_SOURCES += www-dsc.c \ No newline at end of file diff --git a/apps/webbrowser/html-strings b/apps/webbrowser/html-strings new file mode 100644 index 000000000..e3c43c93b --- /dev/null +++ b/apps/webbrowser/html-strings @@ -0,0 +1,36 @@ +html_slasha "/a\0" +html_slashcenter "/center\0" +html_slashform "/form\0" +html_slashh "/h\0" +html_slashscript "/script\0" +html_slashselect "/select\0" +html_slashstyle "/style\0" +html_a "a\0" +html_body "body\0" +html_br "br\0" +html_center "center\0" +html_form "form\0" +html_frame "frame\0" +html_h1 "h1\0" +html_h2 "h2\0" +html_h3 "h3\0" +html_h4 "h4\0" +html_img "img\0" +html_input "input\0" +html_li "li\0" +html_p "p\0" +html_script "script\0" +html_select "select\0" +html_style "style\0" +html_tr "tr\0" +html_href "href\0" +html_alt "alt\0" +html_src "src\0" +html_type "type\0" +html_submit "submit\0" +html_value "value\0" +html_action "action\0" +html_name "name\0" +html_text "text\0" +html_size "size\0" +html_image "image\0" \ No newline at end of file diff --git a/apps/webbrowser/html-strings.c b/apps/webbrowser/html-strings.c new file mode 100644 index 000000000..6292280e6 --- /dev/null +++ b/apps/webbrowser/html-strings.c @@ -0,0 +1,108 @@ +const char html_slasha[4] = +/* "/a\0" */ +{0x2f, 0x61, 00, }; +const char html_slashcenter[9] = +/* "/center\0" */ +{0x2f, 0x63, 0x65, 0x6e, 0x74, 0x65, 0x72, 00, }; +const char html_slashform[7] = +/* "/form\0" */ +{0x2f, 0x66, 0x6f, 0x72, 0x6d, 00, }; +const char html_slashh[4] = +/* "/h\0" */ +{0x2f, 0x68, 00, }; +const char html_slashscript[9] = +/* "/script\0" */ +{0x2f, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 00, }; +const char html_slashselect[9] = +/* "/select\0" */ +{0x2f, 0x73, 0x65, 0x6c, 0x65, 0x63, 0x74, 00, }; +const char html_slashstyle[8] = +/* "/style\0" */ +{0x2f, 0x73, 0x74, 0x79, 0x6c, 0x65, 00, }; +const char html_a[3] = +/* "a\0" */ +{0x61, 00, }; +const char html_body[6] = +/* "body\0" */ +{0x62, 0x6f, 0x64, 0x79, 00, }; +const char html_br[4] = +/* "br\0" */ +{0x62, 0x72, 00, }; +const char html_center[8] = +/* "center\0" */ +{0x63, 0x65, 0x6e, 0x74, 0x65, 0x72, 00, }; +const char html_form[6] = +/* "form\0" */ +{0x66, 0x6f, 0x72, 0x6d, 00, }; +const char html_frame[7] = +/* "frame\0" */ +{0x66, 0x72, 0x61, 0x6d, 0x65, 00, }; +const char html_h1[4] = +/* "h1\0" */ +{0x68, 0x31, 00, }; +const char html_h2[4] = +/* "h2\0" */ +{0x68, 0x32, 00, }; +const char html_h3[4] = +/* "h3\0" */ +{0x68, 0x33, 00, }; +const char html_h4[4] = +/* "h4\0" */ +{0x68, 0x34, 00, }; +const char html_img[5] = +/* "img\0" */ +{0x69, 0x6d, 0x67, 00, }; +const char html_input[7] = +/* "input\0" */ +{0x69, 0x6e, 0x70, 0x75, 0x74, 00, }; +const char html_li[4] = +/* "li\0" */ +{0x6c, 0x69, 00, }; +const char html_p[3] = +/* "p\0" */ +{0x70, 00, }; +const char html_script[8] = +/* "script\0" */ +{0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 00, }; +const char html_select[8] = +/* "select\0" */ +{0x73, 0x65, 0x6c, 0x65, 0x63, 0x74, 00, }; +const char html_style[7] = +/* "style\0" */ +{0x73, 0x74, 0x79, 0x6c, 0x65, 00, }; +const char html_tr[4] = +/* "tr\0" */ +{0x74, 0x72, 00, }; +const char html_href[6] = +/* "href\0" */ +{0x68, 0x72, 0x65, 0x66, 00, }; +const char html_alt[5] = +/* "alt\0" */ +{0x61, 0x6c, 0x74, 00, }; +const char html_src[5] = +/* "src\0" */ +{0x73, 0x72, 0x63, 00, }; +const char html_type[6] = +/* "type\0" */ +{0x74, 0x79, 0x70, 0x65, 00, }; +const char html_submit[8] = +/* "submit\0" */ +{0x73, 0x75, 0x62, 0x6d, 0x69, 0x74, 00, }; +const char html_value[7] = +/* "value\0" */ +{0x76, 0x61, 0x6c, 0x75, 0x65, 00, }; +const char html_action[8] = +/* "action\0" */ +{0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 00, }; +const char html_name[6] = +/* "name\0" */ +{0x6e, 0x61, 0x6d, 0x65, 00, }; +const char html_text[6] = +/* "text\0" */ +{0x74, 0x65, 0x78, 0x74, 00, }; +const char html_size[6] = +/* "size\0" */ +{0x73, 0x69, 0x7a, 0x65, 00, }; +const char html_image[7] = +/* "image\0" */ +{0x69, 0x6d, 0x61, 0x67, 0x65, 00, }; diff --git a/apps/webbrowser/html-strings.h b/apps/webbrowser/html-strings.h new file mode 100644 index 000000000..21c6c129d --- /dev/null +++ b/apps/webbrowser/html-strings.h @@ -0,0 +1,36 @@ +extern const char html_slasha[4]; +extern const char html_slashcenter[9]; +extern const char html_slashform[7]; +extern const char html_slashh[4]; +extern const char html_slashscript[9]; +extern const char html_slashselect[9]; +extern const char html_slashstyle[8]; +extern const char html_a[3]; +extern const char html_body[6]; +extern const char html_br[4]; +extern const char html_center[8]; +extern const char html_form[6]; +extern const char html_frame[7]; +extern const char html_h1[4]; +extern const char html_h2[4]; +extern const char html_h3[4]; +extern const char html_h4[4]; +extern const char html_img[5]; +extern const char html_input[7]; +extern const char html_li[4]; +extern const char html_p[3]; +extern const char html_script[8]; +extern const char html_select[8]; +extern const char html_style[7]; +extern const char html_tr[4]; +extern const char html_href[6]; +extern const char html_alt[5]; +extern const char html_src[5]; +extern const char html_type[6]; +extern const char html_submit[8]; +extern const char html_value[7]; +extern const char html_action[8]; +extern const char html_name[6]; +extern const char html_text[6]; +extern const char html_size[6]; +extern const char html_image[7]; diff --git a/apps/webbrowser/htmlparser.c b/apps/webbrowser/htmlparser.c new file mode 100644 index 000000000..0d0c5a7f2 --- /dev/null +++ b/apps/webbrowser/htmlparser.c @@ -0,0 +1,852 @@ +/* + * Copyright (c) 2002, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the Contiki desktop environment + * + * $Id: htmlparser.c,v 1.1 2006/06/17 22:41:13 adamdunkels Exp $ + * + */ + +/* htmlparser.c: + * + * Implements a very simplistic HTML parser. It recognizes HTML links + * (-tags), HTML img alt tags, a few text flow break tags +G * (
,

, ), the

  • tag (but does not even try to + * distinguish between
      or