3 * Copyright (C) 2007 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com)
4 * Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com)
5 * Copyright (C) 2009 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com)
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #include <partition.h>
35 #include <net/socket.h>
50 command_t command_list
;
51 extern partition_t partition_list
;
53 unsigned char test
[80];
55 typedef void (*void_fn_void_t
)(void);
57 extern task_t task_list
;
58 extern vfs_t vfs_list
;
59 extern int cstrcmp (char *one
, char *two
);
60 extern unsigned long file_cache_id
;
61 extern task_t
*_curr_task
;
62 extern module_t
*module_load (char *modname
);
63 extern unsigned long timer_ticks
;
66 char *argparse (char *cmd
)
68 unsigned cmd_len
= strlen (cmd
);
81 /*************************************************************\
83 \*************************************************************/
86 unsigned command_help (char *command
, unsigned len
)
94 for (ctx
= command_list
.next
; ctx
!= &command_list
; ctx
= ctx
->next
) {
95 printf ("%s : %s\n", ctx
->name
, ctx
->desc
);
97 if (tty
->screen_y
>= (tty_char
.y
-1)) {
101 printf ("Press enter to continue");
103 settextcolor (15, 0);
106 /* wait, until enter key is pressed */
108 if (tty
== currtty
) {
109 if (getkey () != '\n')
123 unsigned command_hdd (char *command
, unsigned len
)
137 printf ("/dev/hda not installed\n");
148 printf ("/dev/hda installed - CHS=%d-%d:%d:%d\n", c
, c2
, h
, s
);
152 printf ("/dev/hdb not installed\n");
163 printf ("/dev/hdb installed - CHS=%d-%d:%d:%d\n", c
, c2
, h
, s
);
170 unsigned command_reboot (char *command
, unsigned len
)
179 unsigned command_halt (char *command
, unsigned len
)
181 arch_cpu_shutdown ();
183 puts ("\nSystem halted\nPlease press power button ..");
192 unsigned command_tasks (char *command
, unsigned len
)
194 puts ("id\tname\tpriority\n");
197 for (task
= task_list
.next
; task
!= &task_list
; task
= task
->next
)
198 printf ("%d\t%s\t%u\n", task
->id
, task
->name
, task
->priority
);
203 unsigned command_ps (char *command
, unsigned len
)
210 unsigned command_uptime (char *command
, unsigned len
)
217 unsigned command_version (char *command
, unsigned len
)
224 unsigned command_debug (char *command
, unsigned len
)
228 DPRINT ("developer mode was enabled.");
233 DPRINT ("developer mode was disabled.");
239 unsigned command_mount (char *command
, unsigned len
)
241 strcpy (test
, argparse (command
));
245 unsigned l
= strlen (test
);
253 memcpy (devname
, test
, x
);
255 strcpy (mountpoint
, argparse (test
));
256 unsigned y
= strlen (mountpoint
);
258 if (mountpoint
[y
-1] != '/') {
260 mountpoint
[y
+1] = '\0';
264 partition_t
*p
= partition_find (devname
);
267 mount (p
, "", mountpoint
);
269 printf ("ERROR -> partition %s does not exists\n", devname
);
276 unsigned command_umount (char *command
, unsigned len
)
279 strcpy (mountpoint
, argparse (command
));
281 unsigned y
= strlen (mountpoint
);
284 if (mountpoint
[y
-1] != '/') {
286 mountpoint
[y
+1] = '\0';
290 partition_t
*partition
;
291 for (partition
= partition_list
.next
; partition
!= &partition_list
; partition
= partition
->next
) {
292 if (umount (partition
, mountpoint
))
297 printf ("ERROR -> directory %s is not mounted\n", mountpoint
);
300 printf ("WARNING -> multiple (%d) umount of %s\n", x
, mountpoint
);
307 unsigned command_env (char *command
, unsigned len
)
314 unsigned command_cd (char *command
, unsigned len
)
316 strcpy (test
, argparse (command
));
323 unsigned command_ls (char *command
, unsigned len
)
325 strcpy (test
, argparse (command
));
332 unsigned command_cat (char *command
, unsigned len
)
334 strcpy (test
, argparse (command
));
341 unsigned command_rm (char *command
, unsigned len
)
343 strcpy (test
, argparse (command
));
350 unsigned command_mkdir (char *command
, unsigned len
)
352 strcpy (test
, argparse (command
));
359 unsigned command_touch (char *command
, unsigned len
)
361 strcpy (test
, argparse (command
));
368 unsigned command_exec (char *command
, unsigned len
)
370 if (!strncmp ("./", command
, 2))
371 strcpy (test
, command
+2);
373 strcpy (test
, argparse (command
));
375 unsigned arg_len
= strlen (argparse (test
));
377 strcpy (arg
, argparse (test
));
380 unsigned test_len
= strlen (test
);
382 /* lock current tty keyboard */
385 /* if there is argument after name, rewrite space character to zero */
386 if (test
[test_len
-(arg_len
+1)] == ' ')
387 test
[test_len
-(arg_len
+1)] = '\0';
389 test
[test_len
-arg_len
] = '\0';
391 /* read file data from filesystem */
392 int ret
= vfs_read (test
, strlen (test
));
395 printf ("%s: command not found\n", test
);
396 DPRINT ("ERROR -> vfs_read () - '%s'\n", test
);
397 tty_unlock (currtty
);
401 unsigned bin_len
= file_cache_id
;
403 unsigned char *bin
= (unsigned char *) swmalloc (bin_len
);
406 printf ("ERROR -> out of memory\n");
410 /* copy image to page aligned memory */
411 memcpy (bin
, file_cache
, bin_len
);
413 bin
[file_cache_id
] = '\0';
415 unsigned entry
, code
, data
, data_off
, bss
;
416 int err
= exec_elf (bin
, &entry
, &data
, &data_off
, &bss
);
419 printf ("ERROR -> invalid ELF exec\n");
420 tty_unlock (currtty
);
425 proc_t
*proc
= proc_create (currtty
, test
, entry
);
427 /* check for & character as app parameter */
429 while (d
< arg_len
) {
431 if (proc_flag_set (proc
, PROC_FLAG_DAEMON
))
432 printf ("%s: started as daemon\n", test
);
436 if (arg_len
> 2 && arg
[d
-1] == ' ') {
449 printf ("ERROR -> Invalid process: %s\n", test
);
451 tty_unlock (currtty
);
453 /* free image of elf-bss section */
456 /* free program image */
461 /* save process information to structure for later use */
462 proc
->start
= (unsigned) bin
;
465 proc
->data_off
= data_off
;
467 proc
->end
= (unsigned) (bin
+ bin_len
);
471 /* well, set argument for out app */
472 proc_arg_set (proc
, arg
, arg_len
);
474 proc_vmem_map (proc
);
476 /* Is this process started as daemon ? */
477 /* wait here, until pid != 0*/
478 if (!(proc
->flags
& PROC_FLAG_DAEMON
))
482 /* enable interrupts */
485 /* unlock tty console - user can write in */
486 tty_unlock (currtty
);
488 _curr_task
= proc
->tty
->task
; // this is pretty needed for correct return to our tty task
490 if (!(proc
->flags
& PROC_FLAG_DAEMON
)) {
491 if (!proc_done (proc
))
492 while (1) // NOTE: heh, this is good stuff :P
495 /* free image of elf-bss section */
498 /* free program image */
499 swfree (bin
, bin_len
);
502 /* switch to next task */
508 unsigned command_lsdev (char *command
, unsigned len
)
515 unsigned command_login (char *command
, unsigned len
)
517 currtty
->user
= NULL
;
518 currtty
->logged
= false;
526 unsigned command_serialw (char *command
, unsigned len
)
528 dev_t
*dev
= dev_find ("/dev/com0");
531 unsigned len
= strlen (argparse (command
));
533 memcpy (data
, argparse (command
), len
);
536 dev
->handler (DEV_ACT_WRITE
, data
, len
);
538 printf ("serialw: %s\n", data
);
544 unsigned command_serialr (char *command
, unsigned len
)
546 dev_t
*dev
= dev_find ("/dev/com0");
551 dev
->handler (DEV_ACT_READ
, data
, 1);
553 printf ("serialr: %s\n", data
);
559 unsigned command_fdisk (char *command
, unsigned len
)
561 char *parm
= argparse (command
);
563 fdisk (parm
, strlen (parm
));
568 unsigned command_hdcat (char *command
, unsigned len
)
572 dev_t
*dev
= (dev_t
*) dev_find (argparse (command
));
578 switch (dev
->devname
[7]) {
598 unsigned char block
[512];
600 printf ("dev: %s\n", dev
->devname
);
602 while (!key_pressed (1)) {
603 if (key_pressed (72) == 1) {
604 printf ("##block: %d\n", d
);
605 dev
->handler (DEV_ACT_READ
, &p
, block
, "", d
);
607 for (c
= 0; c
< 512; c
++)
608 putch ((unsigned) block
[c
]);
615 printf ("Please specify block device, example: hdcat /dev/hda\n");
617 tty_unlock (currtty
);
622 unsigned command_free (char *command
, unsigned len
)
629 unsigned command_date (char *command
, unsigned len
)
631 tm
*t
= rtc_getcurrtime ();
633 printf ("%02u:%02u:%02u, %u.%u.%u\n",
634 t
->tm_hour
, t
->tm_min
, t
->tm_sec
, t
->tm_mday
, t
->tm_mon
, t
->tm_year
);
674 void play_tone (dev_t
*dev
, char tone
, char type
, char time
)
696 printf ("play_tone (.., %c, %d, %d);\n", tone
, t
, tt
);
700 dev
->handler (DEV_ACT_PLAY
, 131*t
);
703 dev
->handler (DEV_ACT_PLAY
, 147*t
);
706 dev
->handler (DEV_ACT_PLAY
, 165*t
);
709 dev
->handler (DEV_ACT_PLAY
, 175*t
);
712 dev
->handler (DEV_ACT_PLAY
, 196*t
);
715 dev
->handler (DEV_ACT_PLAY
, 220*t
);
718 dev
->handler (DEV_ACT_PLAY
, 247*t
);
721 dev
->handler (DEV_ACT_PLAY
, 136*t
);
724 dev
->handler (DEV_ACT_PLAY
, 188*t
);
742 printf ("end: play_tone ();\n");
744 dev
->handler (DEV_ACT_PLAY
, 0);
747 void play_song (dev_t
*dev
, char *data
)
749 printf ("play_song ();\n");
750 unsigned i
= 0, l
= strlen (data
);
754 printf ("switch ()\n");
775 play_tone (dev
, data
[i
], data
[i
+1], data
[i
+2]);
785 unsigned command_spk (char *command
, unsigned len
)
787 unsigned int freq
= 20;
789 dev_t
*dev
= dev_find ("/dev/pcspk");
793 We wish you a merry christmas v1.0
795 D2(1/8) G2(1/8) G2(1/16) A2(1/16) G2(1/16) Fis2(1/16) E2(1/8) C2(1/8) E2(1/8) A2(1/8) A2(1/16) H2(1/16) A2(1/16) G2(1/16) Fis2(1/8) D2(1/4) H2(1/8) H2(1/16) C3(1/16) H2(1/16) A2(1/16) G2(1/8) E2(1/8) D2(1/16) D2(1/16) E2(1/8) A2(1/8) Fis2(1/8) G2(1/8)
798 play_song (dev
, "d21 g21 g22 a22 g22 F22 e21 c21 e21 a21 a22 h22 a22 g22 F21 d20 h21 h22 c32 h22 a22 g21 e21 d22 d22 e21 a21 F21 g21");
803 We wish you a merry christmas v3.0
805 G2(1/8) C3(1/8) C3(1/16) D3(1/16) C3(1/16) H2(1/16) A2(1/4) D3(1/8) D3(1/16) E3(1/16) D3(1/16) C3(1/16) H2(1/4) G2(1/8) E3(1/8) E3(1/16) F3(1/16) E3(1/16) D3(1/16) C3(1/8) A2(1/8) G2(1/8) A2(1/8) D3(1/8) H2(1/8) C3(1/8)
808 play_song (dev
, "g21 c31 c32 d32 c32 h22 a20 d31 d32 e32 d32 c32 h20 g21 e31 e32 f32 e32 d32 c31 a21 g21 a21 d31 h21 c31");
814 G2(1/8) C3(1/8) P(1/16) G2(1/16) G3(1/8) C3(1/16) E3(1/8) D3(1/16) E3(1/16) C3(1/8) G2(1/8) C3(1/8) A3(1/8) G3(1/8) E3(1/16) F3(1/16) G3(1/8) G3(1/16) P(1/16) G2(1/8) C3(1/8) A3(1/8) G3(1/8) E3(1/16) F3(1/16) G3(1/8) D3(1/16) E3(1/16) C3(1/8) G2(1/8) C3(1/8) E3(1/16) F3(1/16) D3(1/8) G3(1/8) G3(1/8)
816 /* play_song (dev, "g21 c31 p2 g22 g31 c32 e31 d32 e32 c31 g21 c31 a31 g31 e32 f32 g31 g32 p2 g21 c31 a31 g31 e32 f32 g31 d32 e32 c31 g21 c31 e32 f32 d31 g31 g31");*/
824 extern bool bus_pci_acthandler (unsigned act
, char *block
, unsigned block_len
);
825 extern netif_t netif_list
;
826 extern void ext2_dump ();
833 unsigned long timer_start
= timer_ticks
+ ((unsigned) 1 * 1000);
835 while (timer_start
> timer_ticks
)
840 extern unsigned start
;
842 extern bool ide_acthandler (unsigned act
, partition_t
*p
, char *block
, char *more
, int n
);
843 unsigned command_test (char *command
, unsigned len
)
846 sockaddr_un local, remote;
850 if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
855 local.sun_family = AF_UNIX;
856 strcpy(local.sun_path, "test");
857 // unlink(local.sun_path);
858 l = strlen(local.sun_path) + sizeof(local.sun_family);
859 if (bind(s, (sockaddr *) &local, l) == -1) {
864 if (listen(s, 5) == -1) {
871 printf("Waiting for a connection... - %d\n", s);
873 if ((s2 = accept(s, (struct sockaddr *)&remote, &t)) == -1) {
878 printf("Connected - server - %d\n", s2);
887 if (send(s2, "Jejda", 5, 0) < 0) {
891 int ret = recv(s2, str, 99, 0);
895 printf ("recv: %s : %d\n", str, ret);
905 fdisk ("/dev/hda 0 83 50", 16);
909 /*partition_t *p = partition_find ("/dev/hda0");
912 mount (p, "", "/mnt/hdd/");
914 printf ("WARNING -> partition /dev/hda0 does not exists\n");
916 //char *t = (char *) 0x400000+0x1;
919 //printf ("ddd: 0x%x, 0x%x\n", start, end);
921 /* paging_disable ();
923 task_t *task = task_find (0);
927 char *t = (char *) 0x400000;
934 printf ("Start2: 0x%x\n", *t);
935 unsigned r = page_mmap (task->page_cover, (void *) 0x0, (void *) 0x1000, 1, 0);
949 printf ("Start3: 0x%x\n", *t);
955 t = (char *) 0x400000;
957 printf ("Start4: 0x%x\n", *t);
963 cd ((char *) "/mnt/floppy");
967 //while (++ i < 100) {
968 command_exec ("exec zde", 8);
977 /* Create virtual block device */
979 dev_t *dev = (dev_t *) dev_register ("vbd", "Virtual Block Device", DEV_ATTR_BLOCK, (dev_handler_t *) &ide_acthandler);
981 partition_t *p = partition_add (dev, fs_supported ("znfs"));
983 znfs_init (partition_add (dev, fs_supported ("znfs")), "192.168.1.2"); // small HACK
986 mount (p, "", "/mnt/hdd/");
988 printf ("WARNING -> partition /dev/hda0 does not exists\n");
990 cd ((char *) "/mnt/hdd");
992 //printf ("Je to na 0x%x\n", vesafb);
997 unsigned command_test2 (char *command
, unsigned len
)
1003 if ((s
= socket(AF_UNIX
, SOCK_STREAM
, 0)) == -1) {
1004 printf ("socket\n");
1008 printf("Trying to connect... - %d\n", s
);
1010 remote
.sun_family
= AF_UNIX
;
1011 strcpy(remote
.sun_path
, "test");
1012 l
= strlen(remote
.sun_path
) + sizeof(remote
.sun_family
);
1013 if (connect(s
, (sockaddr
*)&remote
, l
) == -1) {
1014 printf ("connect\n");
1018 printf("Connected - Client\n");
1020 strcpy (str
, "Jedna dve, hovno jde :)");
1024 if ((t
=recv(s
, str
, 99, 0)) > 0) {
1026 printf("echo> %s", str
);
1029 if (send(s
, "hovno_hovno", 11, 0) == -1) {
1041 unsigned command_test3 (char *command
, unsigned len
)
1047 unsigned command_test4 (char *command
, unsigned len
)
1054 unsigned command_mouse (char *command
, unsigned len
)
1056 printf ("PS/2 Mouse test\n");
1058 dev_t
*dev
= dev_find ("/dev/mouseps2");
1065 int ps2_fd
= open ("/dev/mouseps2", O_RDONLY
);
1072 while (!key_pressed (1)) {
1073 int r
= read (ps2_fd
, &mouse
, sizeof (dev_mouse_t
));
1076 kprintf ("oj oj\n");
1080 kprintf ("ps2mouse: x,y: %d, %d | 0x%x \n", mouse
.pos_x
, mouse
.pos_y
, mouse
.flags
);
1082 lseek (ps2_fd
, 0, SEEK_SET
);
1090 unsigned command_vesa (char *command
, unsigned len
)
1092 if (!init_video_vesa ())
1093 printf ("vesa -> failed\n");
1098 unsigned command_kill (char *command
, unsigned len
)
1100 strcpy (test
, argparse (currtty
->shell
));
1102 pid_t pid
= (pid_t
) atoi (test
);
1104 proc_t
*proc
= proc_findbypid (pid
);
1107 printf ("kill: (%s) - No such process\n", test
);
1111 /* send SIGTERM to selected process */
1112 if (!proc_signal (proc
, SIGTERM
))
1115 /* check for daemon */
1116 if (proc
->flags
& PROC_FLAG_DAEMON
)
1117 if (!proc_done (proc
))
1123 unsigned command_modprobe (char *command
, unsigned len
)
1125 unsigned arg_len
= strlen (argparse (currtty
->shell
));
1126 char arg
[arg_len
+1];
1127 strcpy (arg
, argparse (currtty
->shell
));
1128 arg
[arg_len
] = '\0';
1135 unsigned command_lsmod (char *command
, unsigned len
)
1142 #ifdef CONFIG_DRV_PCI
1143 unsigned command_lspci (char *command
, unsigned len
)
1152 unsigned command_iflist (char *command
, unsigned len
)
1159 unsigned command_ifconfig (char *command
, unsigned len
)
1161 strcpy (test
, argparse (command
));
1165 unsigned l
= strlen (test
);
1173 memcpy (ifid
, test
, x
);
1176 strcpy (ip
, argparse (test
));
1177 unsigned y
= strlen (ip
);
1179 netif_t
*netif
= netif_findbyname (ifid
);
1182 printf ("ifconfig -> bad network interface name, example: eth0\n");
1188 if (ipv4
= net_proto_ip_convert (ip
)) {
1189 netif_ip_addr (netif
, ipv4
);
1191 printf ("%s: IPv4 ", ifid
);
1192 net_proto_ip_print (ipv4
);
1194 } else if (net_proto_ipv6_convert (ipv6
, ip
)) {
1195 netif_ipv6_addr (netif
, ipv6
);
1197 printf ("%s: IPv6 ", ifid
);
1198 net_proto_ipv6_print (ipv6
);
1201 printf ("ifconfig -> bad ip address format, example:\n\t\t192.168.1.1 for IPv4\n\t\tfc00:0:0:0:0:0:0:10 for IPv6\n");
1208 unsigned command_ifroute (char *command
, unsigned len
)
1210 strcpy (test
, argparse (command
));
1214 unsigned l
= strlen (test
);
1222 memcpy (ifid
, test
, x
);
1225 strcpy (ip
, argparse (test
));
1226 unsigned y
= strlen (ip
);
1228 netif_t
*netif
= netif_findbyname (ifid
);
1231 printf ("ifroute -> bad network interface name, example: eth0\n");
1256 printf ("ifroute -> bad ip address format, example: 192.168.1.254\n");
1265 printf ("%s->gw: %d.%d.%d.%d - OK\n", ifid
, a
, b
, c
, d
);
1267 return netif_gw_addr (netif
, NET_IPV4_TO_ADDR (a
, b
, c
, d
));
1270 unsigned command_dnsconfig (char *command
, unsigned len
)
1272 strcpy (test
, argparse (currtty
->shell
));
1277 unsigned l
= strlen (test
);
1280 printf ("dnsconfig -> your domain name server is: ");
1281 net_proto_ip_print (dns_addr_get ());
1287 printf ("dnsconfig: %s - OK\n", test
);
1289 net_ipv4 dns
= net_proto_ip_convert (test
);
1299 unsigned command_tunconfig (char *command
, unsigned len
)
1301 strcpy (test
, argparse (currtty
->shell
));
1306 unsigned l
= strlen (test
);
1309 printf ("tunconfig -> wrong syntax !\ntunconfig <ipv4tunnel> for enable or tunconfig 0 for disable\n");
1314 /* you can disable this service over character '0' as parameter */
1315 if (l
== 1 && test
[0] == '0') {
1318 printf ("tunconfig: disabled - OK\n");
1323 /* classical ipv4 address from tunnel server */
1324 net_ipv4 tunnel
= net_proto_ip_convert (test
);
1327 printf ("tunconfig -> wrong syntax !\nExample: tunconfig 216.66.80.30\n");
1334 printf ("tunconfig: ::%s - OK\n", test
);
1339 unsigned command_kbdmap (char *command
, unsigned len
)
1341 strcpy (test
, argparse (currtty
->shell
));
1346 unsigned ret
= keyboard_setlayout (test
);
1349 printf ("Keyboard layout was changed to '%s'\n", test
);
1354 unsigned command_mkzexfs (char *command
, unsigned len
)
1357 strcpy (test
, argparse (currtty
->shell
));
1362 partition_t
*p
= partition_find ("/dev/hda0");
1369 unsigned command_mkext2 (char *command
, unsigned len
)
1372 strcpy (test
, argparse (currtty
->shell
));
1377 partition_t
*p
= partition_find ("/dev/hda0");
1384 unsigned command_ping (char *command
, unsigned len
)
1386 strcpy (test
, argparse (currtty
->shell
));
1391 netif_t
*netif
= netif_findbyname ("eth0");
1394 printf ("ping -> network interface does not exists\n");
1405 unsigned y
= strlen (test
);
1408 printf ("ping -> wrong syntax, please specify address\n");
1415 if (test
[i
] == '.') {
1424 net_ipv4 target
= 0;
1427 strcpy (test
, argparse (currtty
->shell
));
1428 target
= dns_cache_get (test
);
1431 target
= dns_send_request (test
);
1434 printf ("ping -> bad hostname or ip address format, example: 192.168.1.1\n");
1439 b
= atoi (test
+h
[0]);
1440 c
= atoi (test
+h
[1]);
1441 d
= atoi (test
+h
[2]);
1443 target
= NET_IPV4_TO_ADDR (a
, b
, c
, d
);
1445 strcpy (test
, argparse (currtty
->shell
));
1449 net_proto_ip_convert2 (target
, address
);
1454 unsigned long time_a
= timer_ticks
;
1455 unsigned ret
= net_proto_icmp_ping (netif
, target
);
1457 printf ("ping -> %s (%s) - %ums\n", test
, address
, (timer_ticks
- time_a
));
1459 printf ("ping -> Host %s is unreachable\n", test
);
1469 unsigned command_ping6 (char *command
, unsigned len
)
1471 strcpy (test
, argparse (currtty
->shell
));
1476 netif_t
*netif
= netif_findbyname ("eth0");
1479 printf ("ping -> network interface does not exists\n");
1494 unsigned y
= strlen (test
);
1497 printf ("ping -> wrong syntax, please specify ipv6 address\n");
1504 if (test
[i
] == ':') {
1516 /*strcpy (test, argparse (currtty->shell));
1517 target = dns_cache_get (test);
1520 target = dns_send_request (test);
1523 // printf ("ping -> bad hostname or ip address format, example: 192.168.1.1\n");
1526 printf ("ping -> wrong syntax, please specify ipv6 address\n");
1531 a
= strtol (test
, &endptr
, 16);
1532 b
= strtol (test
+k
[0], &endptr
, 16);
1533 c
= strtol (test
+k
[1], &endptr
, 16);
1534 d
= strtol (test
+k
[2], &endptr
, 16);
1535 e
= strtol (test
+k
[3], &endptr
, 16);
1536 f
= strtol (test
+k
[4], &endptr
, 16);
1537 g
= strtol (test
+k
[5], &endptr
, 16);
1538 h
= strtol (test
+k
[6], &endptr
, 16);
1540 NET_IPV6_TO_ADDR (target
, a
, b
, c
, d
, e
, f
, g
, h
);
1542 //printf ("ipv6: %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n", a, b, c, d, e, f, g, h);
1544 strcpy (test
, argparse (currtty
->shell
));
1548 //net_proto_ipv6_convert2 (target, address);
1553 unsigned long time_a
= timer_ticks
;
1554 unsigned ret
= net_proto_icmp6_ping (netif
, target
);
1556 printf ("ping6 -> %s (%s) - %ums\n", test
, test
, (timer_ticks
- time_a
));
1558 printf ("ping6 -> Host %s is unreachable\n", test
);
1568 unsigned command_netexec (char *command
, unsigned len
)
1570 strcpy (test
, argparse (command
));
1575 if (!strlen (test
)) {
1576 printf ("Syntax:\nnetexec <ip_of_tftp> <filename> [parameters]\n");
1580 unsigned arg_len
= strlen (argparse (test
));
1581 char arg
[arg_len
+1];
1582 strcpy (arg
, argparse (test
));
1583 arg
[arg_len
] = '\0';
1585 unsigned test_len
= strlen (test
);
1586 test
[test_len
-arg_len
] = '\0';
1588 if (test
[test_len
-arg_len
-1] == ' ') {
1589 test
[test_len
-arg_len
-1] = '\0';
1593 char file
[arg_len
+1];
1594 unsigned file_len
= 0;
1595 memcpy (file
, arg
, arg_len
);
1596 while (file_len
< arg_len
) {
1597 if (file
[file_len
] == ' ') {
1598 file
[file_len
] = '\0';
1604 if (file
[arg_len
] != '\0')
1605 file
[arg_len
] = '\0';
1607 unsigned l
= file_len
;
1609 unsigned ret
= tftp_client_connect (test
, 69, file
, &l
);
1612 printf ("tftp -> something go wrong !\n");
1616 printf ("tftp -> file length: %ubytes\t\t[OK]\n", l
);
1618 char *bin
= (unsigned char *) pmalloc (sizeof (char) * (l
+1));
1623 int ret2
= tftp_client_read (ret
, bin
, l
);
1626 printf ("tftp -> tftp_client_read () error\n");
1631 memcpy (file_cache
, bin
, l
);
1633 unsigned entry
, code
, data
, data_off
, bss
;
1634 int err
= exec_elf (bin
, &entry
, &data
, &data_off
, &bss
);
1637 printf ("ERROR -> invalid ELF exec\n");
1643 /* create process */
1644 proc_t
*proc
= proc_create (currtty
, "netexec", entry
);
1648 /* check for & character as app parameter */
1650 while (d < arg_len) {
1651 if (arg[d] == '&') {
1652 if (proc_flag_set (proc, PROC_FLAG_DAEMON))
1653 printf ("%s: started as daemon\n", test);
1657 if (arg_len > 2 && arg[d-1] == ' ') {
1670 printf ("ERROR -> Invalid process: %s\n", test
);
1676 /* save process information to structure for later use */
1677 proc
->start
= (unsigned) bin
;
1680 proc
->data_off
= data_off
;
1682 proc
->end
= (unsigned) (bin
+ l
);
1686 /* well, set argument for out app */
1687 proc_arg_set (proc
, arg
+file_len
+1, arg_len
-file_len
-1);
1691 /* Is this process started as daemon ? */
1692 /* wait here, until pid != 0*/
1693 if (!(proc
->flags
& PROC_FLAG_DAEMON
))
1699 /* enable interrupts */
1702 /* unlock tty console - user can write in */
1703 tty_unlock (proc
->tty
);
1705 _curr_task
= proc
->tty
->task
; // this is pretty needed for correct return to our tty task
1707 if (!(proc
->flags
& PROC_FLAG_DAEMON
)) {
1708 if (!proc_done (proc
))
1709 while (1) // NOTE: heh, this is good stuff :P
1712 /* free image of app */
1717 /* switch to next task */
1725 unsigned command_netcp (char *command
, unsigned len
)
1727 strcpy (test
, argparse (command
));
1732 if (!strlen (test
)) {
1733 printf ("Syntax:\nnetcp <ip_of_tftp> <tftp_file> <output_file>\n");
1737 unsigned arg_len
= strlen (argparse (test
));
1738 char arg
[arg_len
+1];
1739 strcpy (arg
, argparse (test
));
1740 arg
[arg_len
] = '\0';
1742 unsigned test_len
= strlen (test
);
1743 test
[test_len
-arg_len
] = '\0';
1745 if (test
[test_len
-arg_len
-1] == ' ') {
1746 test
[test_len
-arg_len
-1] = '\0';
1750 char file
[arg_len
+1];
1751 unsigned file_len
= 0;
1752 memcpy (file
, arg
, arg_len
);
1753 while (file_len
< arg_len
) {
1754 if (file
[file_len
] == ' ') {
1755 file
[file_len
] = '\0';
1761 if (file
[arg_len
] != '\0')
1762 file
[arg_len
] = '\0';
1764 unsigned l
= file_len
;
1766 unsigned ret
= tftp_client_connect (test
, 69, file
, &l
);
1769 printf ("tftp -> something go wrong !\n");
1773 printf ("tftp -> file length: %ubytes\t\t[OK]\n", l
);
1774 printf ("DDDDDDDD: '%s' :: '%s' :: '%s'\n", test
, file
, arg
);
1775 char *bin
= (unsigned char *) malloc (sizeof (char) * (l
+1));
1780 int ret2
= tftp_client_read (ret
, bin
, l
);
1783 printf ("tftp -> tftp_client_read () error\n");
1793 char *output
= argparse (arg
);
1797 printf ("ERROR -> output file name is empty\n");
1801 int fd
= open (output
, O_WRONLY
| O_CREAT
);
1805 printf ("ERROR -> something go wrong with %s\n", output
);
1809 ret
= write (fd
, bin
, l
);
1813 printf ("ERROR -> File '%s' could'nt be writed\n", output
);
1816 file_cache
= (unsigned char *) 0x350000;
1821 void task_savemode ()
1824 /* disable cpu for cycle */
1830 unsigned command_savemode (char *command
, unsigned len
)
1832 task_t
*task
= (task_t
*) task_create ("savemode", (unsigned) &task_savemode
, 16);
1835 printf ("ERROR -> Save mode thread was'nt created\n");
1839 printf ("Save mode was succefully started\n");
1844 unsigned command_cpuinfo (char *command
, unsigned len
)
1846 printf ("Processor info:\n");
1848 cat ("/proc/cpuinfo");
1853 unsigned command_adm (char *command
, unsigned len
)
1855 printf ("Automatic Device Mounter - init ()\n");
1862 unsigned command_ttyctrl (char *command
, unsigned len
)
1864 char *parm
= argparse (command
);
1867 printf ("ttyctrl <operation> [parameter]\n\t\toperations: add; list; change <ttyid>");
1871 if (!strncmp (parm
, "add", 3)) {
1872 tty_t
*tty
= tty_create ();
1877 settextcolor (7, 0);
1879 tty_write (tty
, "\nlogin: ", 8);
1881 printf ("New tty '%s' was created\n", tty
->name
);
1883 if (!strncmp (parm
, "list", 4)) {
1886 if (!strncmp (parm
, "change", 6)) {
1887 tty_t
*tty
= tty_find ((char *) argparse (parm
));
1900 /*************************************************************\
1902 \*************************************************************/
1904 unsigned command_parser (char *command
, unsigned len
)
1906 /* find first non-space in command */
1908 for (i
= 0; i
< len
; i
++) {
1909 if (command
[i
] != ' ')
1914 /* try to find the command */
1915 for (ctx
= command_list
.next
; ctx
!= &command_list
; ctx
= ctx
->next
) {
1916 if (!cstrcmp (ctx
->name
, command
+i
)) {
1917 ctx
->handler (command
+i
, len
-i
);
1922 printf ("%s: command not found\n", command
);
1927 void commands (int i
)
1929 // currtty->shell_len has been set to zero already
1930 command_parser (currtty
->shell
, strlen(currtty
->shell
));
1933 unsigned command_register (char *name
, char *desc
, command_handler_t
*handler
, unsigned flags
)
1936 /* we dont want commands with same name */
1937 for (c
= command_list
.next
; c
!= &command_list
; c
= c
->next
)
1938 if (!strcmp(c
->name
, name
))
1943 // alloc and init context
1944 ctx
= (command_t
*) kmalloc (sizeof (command_t
));
1949 unsigned name_len
= strlen (name
);
1950 ctx
->name
= (char *) kmalloc (sizeof (char) * name_len
+1);
1955 memcpy (ctx
->name
, name
, name_len
);
1956 ctx
->name
[name_len
] = '\0';
1958 unsigned desc_len
= strlen (desc
);
1959 ctx
->desc
= (char *) kmalloc (sizeof (char) * desc_len
+1);
1964 memcpy (ctx
->desc
, desc
, desc_len
);
1965 ctx
->desc
[desc_len
] = '\0';
1967 ctx
->handler
= handler
;
1970 ctx
->next
= &command_list
;
1971 ctx
->prev
= command_list
.prev
;
1972 ctx
->prev
->next
= ctx
;
1973 ctx
->next
->prev
= ctx
;
1978 unsigned command_unregister (char *name
)
1982 for (ctx
= command_list
.next
; ctx
!= &command_list
; ctx
= ctx
->next
) {
1983 if (!strcmp(ctx
->name
, name
)) {
1984 ctx
->next
->prev
= ctx
->prev
;
1985 ctx
->prev
->next
= ctx
->next
;
1994 /*************************************************************\
1995 | INITIALIZATION OF COMMANDS |
1996 \*************************************************************/
1998 unsigned int init_commands ()
2000 command_list
.next
= &command_list
;
2001 command_list
.prev
= &command_list
;
2004 command_register ("help", "Displays list of available commands", &command_help
, 0);
2005 command_register ("hdd", "Detect HDD", &command_hdd
, 0);
2006 command_register ("reboot", "Reboot computer", &command_reboot
, 0);
2007 command_register ("halt", "Shutdown computer", &command_halt
, 0);
2008 command_register ("tasks", "Print all tasks", &command_tasks
, 0);
2009 command_register ("ps", "Print all process", &command_ps
, 0);
2010 command_register ("uptime", "Print uptime in seconds", &command_uptime
, 0);
2011 command_register ("version", "Displays a version of system", &command_version
, 0);
2012 command_register ("debug", "Change to developer mode", &command_debug
, 0);
2013 command_register ("mount", "Mount device to selected directory", &command_mount
, 0);
2014 command_register ("umount", "Unmount mounted directory", &command_umount
, 0);
2015 command_register ("env", "Displays all env variables", &command_env
, 0);
2016 command_register ("cd", "Change directory", &command_cd
, 0);
2017 command_register ("ls", " Displays files in current directory", &command_ls
, 0);
2018 command_register ("cat", "Displays text in selected file", &command_cat
, 0);
2019 command_register ("rm", "Remove a file", &command_rm
, 0);
2020 command_register ("mkdir", "Create a directory", &command_mkdir
, 0);
2021 command_register ("touch", "Create a file", &command_touch
, 0);
2022 command_register ("exec", "Execute a selected program", &command_exec
, 0);
2023 command_register ("lsdev", "Displays found devices", &command_lsdev
, 0);
2024 command_register ("login", "Login as another user", &command_login
, 0);
2025 command_register ("fdisk", "Partition table manipulator", &command_fdisk
, 0);
2026 command_register ("hdcat", "Read selected block of data from drive", &command_hdcat
, 0);
2027 command_register ("free", "Display amount of free and used memory", &command_free
, 0);
2028 command_register ("date", "Show current date and time", &command_date
, 0);
2029 //command_register ("xmastime", "play noel on pc-speaker", &command_spk, 0);
2030 command_register ("test", "Some test", &command_test
, 0);
2031 //command_register ("testb", "Some test", &command_test2, 0);
2032 //command_register ("testc", "Some test", &command_test3, 0);
2033 //command_register ("testd", "Some test", &command_test4, 0);
2034 //command_register ("vesa", "Some test", &command_vesa, 0);
2035 command_register ("kill", "Send a signal to process", &command_kill
, 0);
2036 command_register ("modprobe", "program to add modules from the kernel", &command_modprobe
, 0);
2037 command_register ("lsmod", "program to show the status of modules", &command_lsmod
, 0);
2038 #ifdef CONFIG_DRV_PCI
2039 command_register ("lspci", "list all pci devices", &command_lspci
, 0);
2041 command_register ("mouse", "ps2 mouse test", &command_mouse
, 0);
2042 command_register ("iflist", "Show network interface", &command_iflist
, 0);
2043 command_register ("ifconfig", "Configure network interface", &command_ifconfig
, 0);
2044 command_register ("ifroute", "Configure gateway address", &command_ifroute
, 0);
2045 command_register ("dnsconfig", "Configure domain name server address", &command_dnsconfig
, 0);
2046 #ifdef CONFIG_PROTO_TUN6
2047 command_register ("tunconfig", "Configure IPv6 tunnel server address", &command_tunconfig
, 0);
2049 command_register ("kbdmap", "Change keyboard layout", &command_kbdmap
, 0);
2050 #ifdef CONFIG_DRV_ZEXFS
2051 command_register ("mkzexfs", "Create zexfs filesystem on hdd", &command_mkzexfs
, 0);
2053 #ifdef CONFIG_DRV_EXT2
2054 command_register ("mkext2", "Create ext2 filesystem on hdd", &command_mkext2
, 0);
2056 #ifdef CONFIG_PROTO_IPV4
2057 command_register ("ping", "Send ICMP echo request", &command_ping
, 0);
2059 #ifdef CONFIG_PROTO_IPV6
2060 command_register ("ping6", "Send ICMPv6 echo request", &command_ping6
, 0);
2062 command_register ("netexec", "Execute file from network", &command_netexec
, 0);
2063 command_register ("netcp", "Copy file from network to filesystem", &command_netcp
, 0);
2064 command_register ("savemode", "Make less cpu load", &command_savemode
, 0);
2065 command_register ("cpuinfo", "Show CPU info", &command_cpuinfo
, 0);
2067 command_register ("adm", "Automatic Device Mounter", &command_adm
, 0);
2068 command_register ("ttyctrl", "TTY Console control", &command_ttyctrl
, 0);