Пример #1
0
static void 
proc_reg_resp(struct msg_ac_reg_resp_t *msg, int len, int proto)
{
	sys_debug("Receive ac reg response packet\n");
	if(len < sizeof(*msg)) {
		sys_err("Receive error msg ac reg response packet\n");
		return;
	}

	/* md5sum3 = packet + random1 + password */
	if(chap_msg_cmp_md5((void *)msg, sizeof(*msg), 
			get_random(msg->header.mac))) {
		sys_err("ac reg response packet chap error\n");
		return;
	}

	strncpy(sysstat.acuuid, msg->header.acuuid, UUID_LEN);
	memcpy(sysstat.dmac, msg->header.mac, ETH_ALEN);
	if(msg->acaddr.sin_addr.s_addr)
		sysstat.server = msg->acaddr;
	if(msg->apaddr.sin_addr.s_addr) 
		setaddr((void *)&msg->apaddr);

	pr_ipv4(&msg->acaddr);

	/* if have connect to remote ac, close it. 
	 * and connect to local ac */
	if(sysstat.sock >= 0)
		close(sysstat.sock);

	ac_reconnect();
	sysstat.isreg = 1;
}
Пример #2
0
static void ac_reconnect()
{
	if(!sysstat.server.sin_addr.s_addr)
		return;

	int ret;
	struct nettcp_t tcp;
	SYSSTAT_LOCK();
	/* other process have reconnect */
	if(sysstat.sock >= 0)
		goto unlock;

	tcp.addr = sysstat.server;
	ret = tcp_connect(&tcp);
	if(ret < 0)
		goto unlock;

	pr_ipv4(&tcp.addr);
	sysstat.sock = ret;
	SYSSTAT_UNLOCK();
	sys_debug("connect success: %d\n", sysstat.sock);
	insert_sockarr(tcp.sock, __net_netrcv, NULL);
	return;

unlock:
	SYSSTAT_UNLOCK();
	return;
}
Пример #3
0
uint32_t doSysDebug(int sig, int arg) {
    // printf("[debug]%d\n", sig);
    uint32_t ret;
    if((ret = sys_debug(pid, sig, arg)) == -1)
        uninit();
    return ret;
}
Пример #4
0
static int setaddr(struct sockaddr *addr)
{
	struct ifreq req;
	strncpy(req.ifr_name, argument.nic, IFNAMSIZ);
	req.ifr_addr = *addr;
	req.ifr_addr.sa_family = AF_INET;

	sys_debug("Set client nic ip: %s, addr: %s\n", req.ifr_name, 
		inet_ntoa(((struct sockaddr_in *)&req.ifr_addr)->sin_addr));

	int sockfd = socket(AF_INET, SOCK_DGRAM, 0);
	if(sockfd < 0) {
		sys_err("Create socket failed: %s(%d)\n",
			strerror(errno), errno);
		return 0;
	}

	int ret;
	ret = ioctl(sockfd, SIOCSIFADDR, &req);
	if(ret < 0) {
		sys_err("Set ap addr failed: %s(%d)\n",
			strerror(errno), errno);
		close(sockfd);
		return 0;
	}
	close(sockfd);
	return 1;
}
Пример #5
0
int main(int argc, char* argv[]) {
    if(argc == 1)
    {
        strcpy(target, "testudb");
    } else
        strcpy(target, argv[1]);
    if ((pid = fork()) == 0) {
        subArgv[0] = target;
        subArgv[1] = NULL;
        sys_debug(0, DEBUG_ATTACH, subArgv);
        exit(0);
    }
    info = loadStab(target);
    strcpy(buf, target);
    strcat(buf, ".c");
    strcpy(loadedSource, buf);
    loadCodeFile(buf);
    // load_asm();
    cprintf("Attached.\n");
    udbWait();
    
    // test begins
    /*
    int con = 0;
    char** testtemp = split(test);
    cprintf("%d\n", con);
    while(testtemp[con]) con++;
    cprintf("%d\n", calc(con, testtemp));
    return 0;
    */
    // test ends
    
    char* inp_raw;
    while(1) {
        inp_raw = readl_raw("udb>");
        if(inp_raw == NULL)
            break;
        if(strlen(inp_raw) == 0)
            inp_raw = lastInput;
        else
            strcpy(lastInput, inp_raw);
        char** inp = split(inp_raw);
        int cnt = 0;
        while(inp[cnt]) cnt++;
        if(cnt == 0)
            continue;
        for(int i = 0; i < NCOMMANDS; ++i) {
            if(strcmp(commands[i].name, inp[0]) == 0 || strcmp(commands[i].alias, inp[0]) == 0) {
                commands[i].func(cnt, inp);
            }
        }
    }
    return 0;
}
Пример #6
0
void message_insert(struct message_t *msg)
{
	sys_debug("message insert msg: %p\n", msg);
	msg->next = NULL;

	MUTEX_LOCK(message_lock);
	message_num++; 
	*tail = msg;
	tail = &msg->next;
	MUTEX_UNLOCK(message_lock);
}
Пример #7
0
/*
 * reponse_brd recv broadcast msg from ac and update sysstat
 * */
static void proc_brd(struct msg_ac_brd_t *msg, int len, int proto)
{
	assert(proto == MSG_PROTO_ETH);

	sys_debug("receive ac broadcast packet\n");
	if(len < sizeof(*msg)) {
		sys_err("receive error msg ac broadcast packet\n");
		return;
	}

	if(sysstat.isreg)
		_proc_brd_isreg(msg, len, proto);
	else
		_proc_brd(msg, len, proto);
}
Пример #8
0
void *message_travel(void *arg)
{
	struct message_t *msg;
	while(1) {
		sleep(argument.msgitv);
		if(head == NULL) continue;
		while((msg = message_delete())) {
			msg_proc((void *)msg->data, msg->len, msg->proto);
			message_free(msg);
		}
		sys_debug("Message travel pthreads (next %d second later)\n", 
			argument.msgitv);
	}
	return NULL;
}
Пример #9
0
static void *report_apstatus(void *arg)
{
	int ret;
	struct apstatus_t *ap;

	int bufsize = sizeof(struct msg_ap_status_t) +
		sizeof(struct apstatus_t);
	char *buf = calloc(1, bufsize);
	if(buf == 0) {
		sys_err("Malloc for report apstatus failed:%s ", 
			strerror(errno));
		exit(-1);
	}

	int proto;
	/* tcp do not use chap to protect */
	fill_msg_header((void *)buf, MSG_AP_STATUS, NULL, 0);

	/* ap will first connect remote ac, but if 
	 * find local ac, ap will connect to local ac */
	while(1) {
		proto = (sysstat.sock >= 0) ? MSG_PROTO_TCP : MSG_PROTO_ETH;
		if(proto == MSG_PROTO_ETH) {
			ac_reconnect();
			goto wait;
		}

		ap = get_apstatus();
		memcpy(buf + sizeof(struct msg_ap_status_t),
			ap, sizeof(struct apstatus_t));

		ret = net_send(proto, sysstat.sock, 
			sysstat.dmac, buf, bufsize);
		if(ret <= 0 && proto == MSG_PROTO_TCP) {
			ac_lost();
			ac_reconnect();
		}
wait:
		sys_debug("report ap status (next %d seconds later)\n", 
			argument.reportitv);
		sleep(argument.reportitv);
	}
	return NULL;
}
Пример #10
0
struct message_t * message_delete()
{
	MUTEX_LOCK(message_lock);
	if(message_num == 0) {
		assert(*tail == head);
		MUTEX_UNLOCK(message_lock);
		return NULL;
	}
	
	struct message_t *tmp = head;
	message_num--;

	head = head->next;
	if(tail == &tmp->next)
		tail = &head;

	MUTEX_UNLOCK(message_lock);
	sys_debug("message delete: %p\n", tmp);
	return tmp;
}
Пример #11
0
static int syscall_dispatch(uint32_t sysnum, uint32_t args, regs_t *regs)
{
    switch (sysnum) {
        case SYS_waitpid:
            return sys_waitpid((waitpid_args_t *)args);
            
        case SYS_exit:
            do_exit((int)args);
            panic("exit failed!\n");
            return 0;
            
        case SYS_thr_exit:
            kthread_exit((void *)args);
            panic("thr_exit failed!\n");
            return 0;
            
        case SYS_thr_yield:
            sched_make_runnable(curthr);
            sched_switch();
            return 0;
            
        case SYS_fork:
            return sys_fork(regs);
            
        case SYS_getpid:
            return curproc->p_pid;
            
        case SYS_sync:
            sys_sync();
            return 0;
            
#ifdef __MOUNTING__
        case SYS_mount:
            return sys_mount((mount_args_t *) args);
            
        case SYS_umount:
            return sys_umount((argstr_t *) args);
#endif
            
        case SYS_mmap:
            return (int) sys_mmap((mmap_args_t *) args);
            
        case SYS_munmap:
            return sys_munmap((munmap_args_t *) args);
            
        case SYS_open:
            return sys_open((open_args_t *) args);
            
        case SYS_close:
            return sys_close((int)args);
            
        case SYS_read:
            return sys_read((read_args_t *)args);
            
        case SYS_write:
            return sys_write((write_args_t *)args);
            
        case SYS_dup:
            return sys_dup((int)args);
            
        case SYS_dup2:
            return sys_dup2((dup2_args_t *)args);
            
        case SYS_mkdir:
            return sys_mkdir((mkdir_args_t *)args);
            
        case SYS_rmdir:
            return sys_rmdir((argstr_t *)args);
            
        case SYS_unlink:
            return sys_unlink((argstr_t *)args);
            
        case SYS_link:
            return sys_link((link_args_t *)args);
            
        case SYS_rename:
            return sys_rename((rename_args_t *)args);
            
        case SYS_chdir:
            return sys_chdir((argstr_t *)args);
            
        case SYS_getdents:
            return sys_getdents((getdents_args_t *)args);
            
        case SYS_brk:
            return (int) sys_brk((void *)args);
            
        case SYS_lseek:
            return sys_lseek((lseek_args_t *)args);
            
        case SYS_halt:
            sys_halt();
            return -1;
            
        case SYS_set_errno:
            curthr->kt_errno = (int)args;
            return 0;
            
        case SYS_errno:
            return curthr->kt_errno;
            
        case SYS_execve:
            return sys_execve((execve_args_t *)args, regs);
            
        case SYS_stat:
            return sys_stat((stat_args_t *)args);
            
        case SYS_uname:
            return sys_uname((struct utsname *)args);
            
        case SYS_debug:
            return sys_debug((argstr_t *)args);
        case SYS_kshell:
            return sys_kshell((int)args);
        default:
            dbg(DBG_ERROR, "ERROR: unknown system call: %d (args: %#08x)\n", sysnum, args);
            curthr->kt_errno = ENOSYS;
            return -1;
    }
}
Пример #12
0
void ac_lost()
{
	sys_debug("ac lost\n");
	delete_sockarr(sysstat.sock);
	sysstat.sock = -1;
}
Пример #13
0
static void __exec_cmd(struct msg_ac_cmd_t *cmd)
{
	sys_debug("receive ac command packet\n");
	printf("cmd: %s\n", cmd->cmd);
}