Esempio n. 1
0
File: ps2.c Progetto: sjrct/Frosk
static void chg_config(uchar clr, uchar set)
{
	uchar old = get_config();
	outb(PS2_CMND, 0x60);
	do_assert(wait_write());
	outb(PS2_DATA, (old & ~clr) | set);
}
Esempio n. 2
0
void level4(int t)
{
  if (t == Malloc)
    do_malloc();
  else if (t == Div0)
    do_div0();
  else if (t == Assert)
    do_assert();
  else
    do_crash();
}
Esempio n. 3
0
File: ps2.c Progetto: sjrct/Frosk
static void ps2_command(uint port, uchar cmd, uchar * buf, int sz)
{
	int i;

	if (port) outb(PS2_CMND, 0xD4);

	do_assert(wait_write());
	outb(PS2_DATA, cmd);
	do_assert(wait_read());

	if (inb(PS2_DATA) != 0xFA) {
		assert(0);
	}

	if (buf != NULL) {
		for (i = 0; wait_read() && i < sz; i++) {
			buf[i] = inb(PS2_DATA);
		}
	}
}
Esempio n. 4
0
File: ps2.c Progetto: sjrct/Frosk
// device should be disabled
static void detect_device(uint port, uchar enable, uchar test, uchar mask)
{
	ps2_device * ps2d;
	uchar check = 0;
	ushort type = 0;

	if (get_config() & mask) {
		outb(PS2_CMND, enable);

		if (!(get_config() & mask)) {
			outb(PS2_CMND, test);
			do_assert(wait_read());

			if (!inb(PS2_DATA)) {
				ps2_command(port, 0xFF, &check, 1);

				if (check == 0xAA) {
					ps2_command(port, 0xF5, NULL, 0);
					ps2_command(port, 0xF2, (uchar *)(&type), 2);

					if (type == PS2_NO_DEVICE) {
						type = PS2_KB_NORMAL;
					}

					if (type == PS2_KB_NORMAL || type == PS2_KB_MF2) {
						ps2_devs[port] = create_stream(
								sizeof(unsigned),
								ps2_kb_enable,
								ps2_kb_disable,
								ps2_kb_read,
								NULL
						);

						ps2d = kalloc(sizeof(ps2_device));
						ps2d->type = type;
						ps2d->port = port;
						ps2_devs[port]->data = ps2d;

						reg_dev(DEVICE_INPUT, ps2_devs[port]->hndl);
						enable_device(ps2_devs[port]);
					} else {
						ps2_devs[port] = NULL; //TODO: implement
					}

					kprintf("PS/2 Device %x detected.\n", type);
				}
			} else {
				outb(PS2_CMND, enable - 1);
			}
		}
	}
}
Esempio n. 5
0
File: ps2.c Progetto: sjrct/Frosk
void detect_ps2(void)
{
	// disable ps/2 devices
	outb(PS2_CMND, 0xAD);
	outb(PS2_CMND, 0xA7);

	flush_output();

	// disable interrupts and translation
	chg_config(0x43, 0);

	// ps/2 controller self test
	outb(PS2_CMND, 0xAA);
	do_assert(wait_read());

	if (inb(PS2_DATA) != 0x55) {
		kputs("PS/2 Controller self test failed.\n");
		return;
	}

	// individual device detection
	detect_device(0, 0xAE, 0xAB, 0x10);
	detect_device(1, 0xA8, 0xA9, 0x20);
}
Esempio n. 6
0
static void
accept_cb(struct evconnlistener *listener, evutil_socket_t fd,
    struct sockaddr *sa, int slen, void *p)
{
	ssh_session_t *session_in = NULL, *session_out = NULL;
	struct bufferevent *b_out, *b_in;
	// Create two linked bufferevent objects: one to connect, one for the new connection
	b_in = bufferevent_socket_new(base, fd,
	    BEV_OPT_CLOSE_ON_FREE|BEV_OPT_DEFER_CALLBACKS);
	
	b_out = bufferevent_socket_new(base, -1,
	    BEV_OPT_CLOSE_ON_FREE|BEV_OPT_DEFER_CALLBACKS);
	
	do_assert(b_in && b_out);
	
	if (bufferevent_socket_connect(b_out,
		(struct sockaddr*)&connect_to_addr, connect_to_addrlen)<0) {
		perror("bufferevent_socket_connect");
		bufferevent_free(b_out);
		bufferevent_free(b_in);
		return;
	}

	// client
	session_in = ssh_new();
	// server
	session_out = ssh_new();
	
	session_in->proxy = 1;
	session_in->type = SSH_SESSION_CLIENT;
	session_in->owner_ptr =  b_out;
	api_name_from_addr(sa, slen, &(session_in->cip),&(session_in->cport));
	api_name_from_addr((struct sockaddr *)&connect_to_addr, connect_to_addrlen, &(session_in->sip),&(session_in->sport));
	ssh_adapter_accept(adapter, session_in);
	session_in->session_ptr = session_out;
	session_in->evbuffer = bufferevent_get_output(b_in);
	session_in->data_send = session_data_send;
	//session_callback_init(session_in);
	ssh_handle_key_exchange(session_in);
	
	bufferevent_setcb(b_in, data_read_handler, data_write_handler, event_error_handler, session_in);
	
	session_out->proxy = 1;
	session_out->session_state = SSH_SESSION_STATE_SOCKET_CONNECTED;
	session_out->type = SSH_SESSION_SERVER;
	session_out->owner_ptr = b_in;
	api_name_from_addr(sa, slen, &(session_out->cip),&(session_out->cport));
	api_name_from_addr((struct sockaddr*)&connect_to_addr, connect_to_addrlen, 
		&(session_out->sip),&(session_out->sport));
	//ssh_adapter_accept(adapter, session_out);
	session_out->session_ptr = session_in;
	session_out->evbuffer = bufferevent_get_output(b_out);
	session_out->data_send = session_data_send;
	//session_callback_init(session_out);
	{
		int ret = ssh_connect(session_out);
		if(ret != SSH_OK) {
			trace_err("init proxy-client failed.");
		}
		/*
		ret = knownhost_verify(session_out);
		if(ret != SSH_OK) {
			trace_err("iknownhost_verify failed.");
		}*/
	}
	ssh_log(session_in, "accept a new session: [%s:%d] -> [%s:%d]",
			session_in->cip, session_in->cport,
			session_in->sip, session_in->sport);
	
	bufferevent_setcb(b_out, data_read_handler, data_write_handler, event_error_handler, session_out);

	bufferevent_enable(b_in, EV_READ|EV_WRITE);
	bufferevent_enable(b_out, EV_READ|EV_WRITE);
}
Esempio n. 7
0
File: ps2.c Progetto: sjrct/Frosk
static uchar get_config(void)
{
	outb(PS2_CMND, 0x20);
	do_assert(wait_read());
	return inb(PS2_DATA);
}
Esempio n. 8
0
int main(int argc, char* argv[])
{
	api_init();
	{
		int n = 0x01fffc;
		printf("n has [%d]<=>[%d] 1.\n", api_bitset_count(n), api_bitset_count(0x01) + api_bitset_count(0xff) + api_bitset_count(0xfc));
	}
	int rc = 0;
	{
		char s1[1024];
		memset(s1, 0x00, sizeof(s1));
		strcpy(s1, "log path is <${MSF_LOGS}>-<${MSF_LOGS}>${MSF_RUNTIME}");
		api_strfilter(s1, NULL, NULL);
		printf("s1 = [%s]\n", s1);
	}
	api_conhash_t *conhash = calloc(1, sizeof(api_conhash_t));
	rc = api_conhash_init(conhash, API_SIZE_FROM_MB(32), 100);
	do_assert(rc == API_SUCCESS);
	int index = 0;
	char serverId[100];
	for(index = 0; index < 3; index++)
	{
		memset(serverId, 0x00, sizeof(serverId));
		snprintf(serverId, sizeof(serverId), "10.1.15.1%d", index);
		printf(">>>>>>>>>>>>>>>>>>>>>>>>>>> %s\n", serverId);
		api_conhash_add_node(conhash, (uint8_t *)serverId, api_strlen(serverId), NULL);
	}

	
	//char serverId[100];
	api_vector_t *slist = api_vector_new(1);
	char *str = NULL;
	for(index = 0; index < 10; index++)
	{
		memset(serverId, 0x00, sizeof(serverId));
		snprintf(serverId, sizeof(serverId), "cookie:%d", 9 - index);
		str = strdup(serverId);
		api_vector_push(slist, str);
		printf("cookie: [%s]\t", serverId);
		api_conhash_lookup_node(conhash, (uint8_t *)serverId, api_strlen(serverId), server_get, NULL);
	}
	printf("----------------------------------------------------------------\n");
	api_vector_sort(slist, (int (*) (const void *, const void *)) str_sort);
	api_vector_remove(slist, 0);
	for(index = 0; index < api_vector_size(slist); index++)
	{
		str = api_vector_get(slist, index);
		printf("cookie: [%s]\n", str);
	}
	printf("----------------------------------------------------------------\n");
	for(index = 0; index < 1; index++)
	{
		memset(serverId, 0x00, sizeof(serverId));
		snprintf(serverId, sizeof(serverId), "10.1.15.1%d", index + 2);
		api_conhash_del_node(conhash, (uint8_t *)serverId, api_strlen(serverId));
	}
	printf("----------------------------------------------------------------\n");
	for(index = 0; index < 10; index++)
	{
		memset(serverId, 0x00, sizeof(serverId));
		snprintf(serverId, sizeof(serverId), "cookie:%d", index);
		printf("cookie: [%s]\t", serverId);
		api_conhash_lookup_node(conhash, (uint8_t *)serverId, api_strlen(serverId), server_get, NULL);
	}
	printf("----------------------------------------------------------------\n");
	api_safefree(conhash);
	return 0;
}