Beispiel #1
0
/******* TapUnit::New() ***********************************/
OOP_Object *UXTapUnit__Root__New(OOP_Class *cl, OOP_Object *obj, struct pRoot_New *msg)
{
	struct HIDDTapUnitData * data;
	static const struct TagItem tags[] = {{ TAG_END, 0}};
	struct TagItem *tag, *tstate;
	ULONG unitnum = 0;
	
	EnterFunc(bug("TapUnit::New()\n"));

	tstate = msg->attrList;
	while ((tag = NextTagItem((const struct TagItem **)&tstate))) {
		ULONG idx;

		if (IS_HIDDTAPUNIT_ATTR(tag->ti_Tag, idx)) {
			switch (idx) {
				case aoHidd_TapUnit_Unit:
					unitnum = (ULONG)tag->ti_Data;
				break;
			}
		}

	} /* while (tags to process) */
		
	D(bug("!!!!Request for unit number %d\n",unitnum));

	obj = (OOP_Object *)OOP_DoSuperMethod(cl, obj, (OOP_Msg)msg);

	if (obj) {
		data = OOP_INST_DATA(cl, obj);
		
		data->unitnum = unitnum;

		D(bug("Creating network device %s.\n",unitname[data->unitnum]));

		data->filedescriptor = unix_open_nonblock("/dev/net/tun");
		if (data->filedescriptor < 0)
			data->filedescriptor = unix_open_nonblock("/dev/tap");

		D(bug("Opened %s on handle %d\n",unitname[data->unitnum], data->filedescriptor));
		
		if (-1 != data->filedescriptor) {
			struct ifreq ifr;
			memset(&ifr, 0, sizeof(ifr));
			ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
			strncpy(ifr.ifr_name, unitname[data->unitnum], IFNAMSIZ);
			
			/*
			** Configure the tty driver ?!?!?!
			*/
			{
				data->replyport_read = AllocMem(sizeof(struct MsgPort), MEMF_PUBLIC|MEMF_CLEAR);
				data->replyport_write= AllocMem(sizeof(struct MsgPort), MEMF_PUBLIC|MEMF_CLEAR);

				if (data->replyport_read && data->replyport_write) {
					/*
					** Init the msg ports. They don't need a signal to be allocated
					*/
					NEWLIST(&data->replyport_read->mp_MsgList);
					data->replyport_read ->mp_Node.ln_Type = NT_MSGPORT;

					NEWLIST(&data->replyport_write->mp_MsgList);
					data->replyport_write->mp_Node.ln_Type = NT_MSGPORT;

					data->softint_read	= AllocMem(sizeof(struct Interrupt), MEMF_CLEAR);
					data->softint_write = AllocMem(sizeof(struct Interrupt), MEMF_CLEAR);

					if (data->softint_read && data->softint_write) {
						data->softint_read->is_Data = data;
						data->softint_read->is_Code = tapunit_receive_data;

						data->softint_write->is_Data = data;
						data->softint_write->is_Code = tapunit_write_more_data;

						data->replyport_read->mp_Flags = PA_SOFTINT;
						data->replyport_read->mp_SoftInt = data->softint_read;

						data->replyport_write->mp_Flags = PA_SOFTINT;
						data->replyport_write->mp_SoftInt = data->softint_write;

						data->unixio_read	= OOP_NewObject(NULL, CLID_Hidd_UnixIO, (struct TagItem *)tags);
						data->unixio_write = OOP_NewObject(NULL, CLID_Hidd_UnixIO, (struct TagItem *)tags);

						if (NULL != data->unixio_read && NULL != data->unixio_write)
						{
							Hidd_UnixIO_IOControlFile(data->unixio_read, 
							    data->filedescriptor,
							    TUNSETIFF,
							    &ifr,
							    NULL);
							    
							ULONG error;
							D(bug("Creating UnixIO AsyncIO command!\n"));

							error = Hidd_UnixIO_AsyncIO(data->unixio_read,
							                            data->filedescriptor,
							                            vHidd_UnixIO_Terminal,
							                            data->replyport_read,
							                            vHidd_UnixIO_Read | vHidd_UnixIO_Keep,
							                            SysBase);

							error = Hidd_UnixIO_AsyncIO(data->unixio_write,
							                            data->filedescriptor,
							                            vHidd_UnixIO_Terminal,
							                            data->replyport_write,
							                            vHidd_UnixIO_Write | vHidd_UnixIO_Keep,
							                            SysBase);
							goto exit;

						}

						if (NULL != data->unixio_read)
							OOP_DisposeObject(data->unixio_read);

						if (NULL != data->unixio_write)
							OOP_DisposeObject(data->unixio_write);
					}
					
					if (data->softint_read) 
						FreeMem(data->softint_read, sizeof(struct Interrupt));
					if (data->softint_write)
						FreeMem(data->softint_write, sizeof(struct Interrupt));
				}
				
				if (data->replyport_read)
					FreeMem(data->replyport_read , sizeof(struct MsgPort));
				if (data->replyport_write)
					FreeMem(data->replyport_write, sizeof(struct MsgPort));

			} 
			
			close(data->filedescriptor);	
		}

		OOP_DisposeObject(obj);
		obj = NULL;
	} /* if (obj) */

	D(bug("%s - an error occurred!\n",__FUNCTION__));

exit:
	ReturnPtr("TapUnit::New()", OOP_Object *, obj);
}
Beispiel #2
0
static VOID inputtask_entry(struct inputtask_params *inputparams)
{
    struct linux_staticdata *lsd;
    struct inputtask_params itp;
    UBYTE lastcode = 0xFF;
    
    struct MsgPort *kbd_port = NULL;
    struct MsgPort *mouse_port = NULL;
    
    struct mouse_state oldstate = { { 0, 0, 0 }, 0, 0 };
    struct pHidd_Mouse_Event mouse_event;
    
    HIDD *unixio = NULL;
    ULONG kbdsig, mousesig, sigs;
    /* We must copy the parameter struct because they are allocated
     on the parent's stack */
kprintf("INSIDE INPUT TASK\n");
    itp = *inputparams;
    lsd = itp.lsd;
kprintf("in inputtask: lsd = %p\n", lsd);

kprintf("CREATING UNIXIO,,, OOPBase=%p\n", OOPBase);
kprintf("now\n");
    unixio = (HIDD)New_UnixIO(OOPBase, SysBase);
kprintf("UNIXIO %p\n", unixio);
    if (NULL == unixio) {
    	goto failexit;
    }
    
    kbd_port   = CreateMsgPort();
    mouse_port = CreateMsgPort();
    
    if (NULL == kbd_port || NULL == mouse_port)
	goto failexit;
    
    Signal(itp.parent, itp.ok_signal);
    
    kbdsig	= 1L << kbd_port->mp_SigBit;
    mousesig	= 1L << mouse_port->mp_SigBit;
kprintf("SIGS: %p, %p\n", kbdsig, mousesig);
kprintf("FDS: %d, %d\n", lsd->kbdfd, lsd->mousefd);

    Hidd_UnixIO_AsyncIO(unixio, lsd->kbdfd,   vHidd_UnixIO_Terminal, kbd_port,	vHidd_UnixIO_Read, SysBase);
    Hidd_UnixIO_AsyncIO(unixio, lsd->mousefd, vHidd_UnixIO_Terminal, mouse_port,  vHidd_UnixIO_Read, SysBase);
    
    for (;;) {
	LONG err_kbd, err_mouse;
	
	//kprintf("GETTING INPUT FROM UNIXIO\n");
	/* Turn on kbd support */
//	init_kbd(lsd);
	
	
//    	ret = (int)Hidd_UnixIO_Wait( unixio, lsd->kbdfd, vHidd_UnixIO_Read, NULL, NULL);
//	cleanup_kbd(lsd);
//	kprintf("GOT INPUT FROM UNIXIO\n");
	
	sigs = Wait( kbdsig | mousesig );

	if (sigs & kbdsig) {
	
//kprintf("---------- GOT KBD INPUT --------------------\n");
 	    for (;;) {
		UBYTE code;
		size_t bytesread;
	    
	    
		bytesread = read(lsd->kbdfd, &code, 1);
		if (-1 == bytesread)  {
	    	    kprintf("!!! COULD NOT READ FROM LINUX KBD DEVICE: %s\n"
			, strerror(errno));
		    break;
		
		} else {
	    	    /* Let the kbd hidd handle it */
		    /* Key doewn ? */
		    
		    //kprintf("## code %d\n", code);
		    if (code == lastcode)
			break;
		    
	    	    // if (!(code & 0x80)) kprintf("GOT SCANCODE %d from kbd hidd\n", code);
		    if (code == 88) /* F12 */
		    {
			    kill(getpid(), SIGTERM);
		    }
		
		    /* Send code to the application */
    	    	    ObtainSemaphore(&lsd->sema);
		    if (lsd->kbdhidd) HIDD_LinuxKbd_HandleEvent(lsd->kbdhidd, code);
    	    	    ReleaseSemaphore(&lsd->sema);

		    lastcode = code;
		}
		break;

	    }	/* for (;;) */
	    free_unixio_message(kbd_port, lsd);

	    err_kbd = Hidd_UnixIO_AsyncIO(unixio, lsd->kbdfd,   vHidd_UnixIO_Terminal, kbd_port,	vHidd_UnixIO_Read, SysBase);

	} /* if (sigs & kbdsig) */
	
	if (sigs & mousesig)
	{
	    ULONG i;
	    LONG bytesread;
	    UBYTE buf[4];
	    BYTE dx = 0, dy = 0;
	    struct mouse_state newstate;
	    
	    /* Got mouse event */
	    //kprintf("------------- MOUSE EVENT ------------\n");
	    for (i = 0; i < 4; i ++) {
	    	bytesread = read(lsd->mousefd, &buf[i], 1);
		if (-1 == bytesread)
		{
		    if (errno == EAGAIN)
		    {
		    	i--;
			continue;
		    }
		    kprintf("!!! linux input task: Could not read from mouse device: %s\n", strerror(errno));
		    goto end_mouse_event;    
		}
		
		if ((buf[0] & 8) != 8) i--;
	    }
	    
	    //kprintf("%02x: %02x: %02x\n", buf[0], buf[1], buf[2]);
	    /* Get button states */
	    newstate.buts[0] = (buf[0] & 0x01) ? 1 : 0;
	    newstate.buts[1] = (buf[0] & 0x02) ? 1 : 0;
	    newstate.buts[2] = (buf[0] & 0x04) ? 1 : 0;
	    
	    if (buf[1] != 0) {
		dx = (buf[0] & 0x10) ? buf[1] - 256 : buf[1];
	    }
	    
	    if (buf[2] != 0) {
		dy = (buf[0] & 0x20) ? buf[2] - 256 : buf[2];
	    }
		
	    newstate.dx = dx;
	    newstate.dy = -dy;
	    
	    //kprintf("EVENT: STATE 1:%d, 2:%d, 3:%d, dx:%d, dy:%d\n"
	    //	, newstate.buts[0], newstate.buts[1], newstate.buts[2]
	    //	, newstate.dx, newstate.dy);
		
            ObtainSemaphore(&lsd->sema);    
    	    if (lsd->mousehidd)
	    {
    		mouse_event.x = newstate.dx;
		mouse_event.y = newstate.dy;

		if (newstate.dx || newstate.dy)
		{
	    	    mouse_event.button = vHidd_Mouse_NoButton;
		    mouse_event.type = vHidd_Mouse_Motion;

	    	    HIDD_LinuxMouse_HandleEvent(lsd->mousehidd, &mouse_event);
		}

		if (newstate.buts[0] != oldstate.buts[0])
		{
	    	    mouse_event.button = vHidd_Mouse_Button1;
		    mouse_event.type = newstate.buts[0] ? vHidd_Mouse_Press : vHidd_Mouse_Release;	

	    	    HIDD_LinuxMouse_HandleEvent(lsd->mousehidd, &mouse_event);
		}

		if (newstate.buts[1] != oldstate.buts[1])
		{
	    	    mouse_event.button = vHidd_Mouse_Button2;
		    mouse_event.type = newstate.buts[1] ? vHidd_Mouse_Press : vHidd_Mouse_Release;	

	    	    HIDD_LinuxMouse_HandleEvent(lsd->mousehidd, &mouse_event);
		}

		if (newstate.buts[2] != oldstate.buts[2])
		{
	    	    mouse_event.button = vHidd_Mouse_Button3;
		    mouse_event.type = newstate.buts[2] ? vHidd_Mouse_Press : vHidd_Mouse_Release;	

	    	    HIDD_LinuxMouse_HandleEvent(lsd->mousehidd, &mouse_event);
		}
	    }
    	    ReleaseSemaphore(&lsd->sema);
	    
    	    oldstate = newstate;
	    	    	    
end_mouse_event:
	    free_unixio_message(mouse_port, lsd);

	    err_mouse	= Hidd_UnixIO_AsyncIO(unixio, lsd->mousefd, vHidd_UnixIO_Terminal, mouse_port,  vHidd_UnixIO_Read, SysBase);

	}
    	
    } /* Forever */
    
failexit:

    if (NULL != kbd_port)
    	DeleteMsgPort(kbd_port);

    if (NULL != mouse_port)
	DeleteMsgPort(mouse_port);
	
    if (NULL != unixio)
    	OOP_DisposeObject((OOP_Object *)unixio);

    Signal(itp.parent, itp.fail_signal);
     
    return;
    
}