Ejemplo n.º 1
0
int obex_setpath(int od, const char *path, uint8_t flags)
{
	unsigned char taildata[2] = { 0x00, 0x00 };
	obex_t *handle = obex_handles[0];
	struct obex_context *context;
	char unicode[200];
	int err, size;

	obex_object_t *object;
	obex_headerdata_t hd;

	if (!(context = OBEX_GetUserData(handle)))
		return -1;

	if (context->state != OBEX_CONNECTED)
		return -1;

	if (context->mode != OBEX_IDLE)
		return -1;

	context->mode = OBEX_REQUEST;

	if (!(object = OBEX_ObjectNew(handle, OBEX_CMD_SETPATH)))
		return -1;

	if (context->cid > 0) {
		hd.bq4 = context->cid;
		OBEX_ObjectAddHeader(handle, object,
			OBEX_HDR_CONNECTION, hd, 4, OBEX_FL_FIT_ONE_PACKET);
	}

	if (path) {
		size = OBEX_CharToUnicode((uint8_t *) unicode, (uint8_t *) path, sizeof(unicode));
		hd.bs = (uint8_t *) unicode;
		OBEX_ObjectAddHeader(handle, object,
			OBEX_HDR_NAME, hd, size, OBEX_FL_FIT_ONE_PACKET);
	}

	taildata[0] = flags;
	OBEX_ObjectSetNonHdrData(object, taildata, sizeof(taildata));

	if ((err = OBEX_Request(handle, object)) < 0)
		return err;

	while (1) {
		OBEX_HandleInput(handle, OBEX_TIMEOUT);

		if (context->mode == OBEX_ERROR) {
			err = -EIO;
			break;
		}

		if (context->mode == OBEX_DONE)
			break;
	}

	context->mode = OBEX_IDLE;

	return err;
}
Ejemplo n.º 2
0
int obex_disconnect(int od)
{
	obex_t *handle = obex_handles[0];
	struct obex_context *context;
	int err;

	obex_object_t *object;

	if (!(context = OBEX_GetUserData(handle)))
		return -1;

	if (!(object = OBEX_ObjectNew(handle, OBEX_CMD_DISCONNECT)))
		return -1;

	context->state = OBEX_DISCONN;

	if ((err = OBEX_Request(handle, object)) < 0)
		return err;

	while (1) {
		OBEX_HandleInput(handle, OBEX_TIMEOUT);

		if (context->state == OBEX_CLOSED)
			break;
	}

	return err;
}
Ejemplo n.º 3
0
int
WaitRsp(void)
{
    int ret;

    while (!sendingFinished) {
        ret = OBEX_HandleInput(handleSend, 10);
        if (ret < 0)
            return ret;
    }
    return lastSendRsp;
}
Ejemplo n.º 4
0
void obex_poll(obex_t *handle)
{
	obex_context_t *context = OBEX_GetUserData(handle);
	unsigned long state = context->state;

	while (1) {
		OBEX_HandleInput(handle, OBEX_TIMEOUT);
		if (context->state != state)
			break;
        }

	obex_do_callback(handle);
}
Ejemplo n.º 5
0
int
Rcv(void)
{
/*     obex_object_t* object; */
    handleRcv = OBEX_Init(OBEX_TRANS_IRDA, ObexEvent, 0);
    IrOBEX_ServerRegister(handleRcv, "OBEX");

    while (!receivingFinished)
        OBEX_HandleInput(handleRcv, 1);

    receivingFinished = 0;
    return 0;
}
Ejemplo n.º 6
0
static PyObject *
OBEXServer_process(OBEXServer *self, PyObject *args)
{
    int timeout;
    int result;

    DEBUG("%s()\n", __func__);

    if (!PyArg_ParseTuple(args, "i", &timeout))
        return NULL;

    result = OBEX_HandleInput(self->obex, timeout);
    return PyInt_FromLong(result);
}
Ejemplo n.º 7
0
int main(int argc, char **argv)
{
    obex_object_t *object;

    handle = OBEX_Init(OBEX_TRANS_BLUETOOTH, obex_event, 0);

    if (argc == 1)
    {
        BtOBEX_ServerRegister(handle, NULL, OBEX_PUSH_HANDLE);
        printf("Waiting for connection...\n");
        btobex_accept(handle);

        while (!finished)
            OBEX_HandleInput(handle, 1);
    }
}
Ejemplo n.º 8
0
static char *get_named_object(obex_t *handle, char *name, int *len)
{
	struct obex_state *state;
	int req_done;
	obex_object_t *obj;
	obex_headerdata_t hd;
	int size, i;
	glong num;

	state = OBEX_GetUserData(handle);

	obj = OBEX_ObjectNew(handle, OBEX_CMD_GET);
	hd.bq4 = state->connid;
	size = 4;
	OBEX_ObjectAddHeader(handle, obj, OBEX_HDR_CONNECTION,
			     hd, size, OBEX_FL_FIT_ONE_PACKET);

	hd.bs = (unsigned char *)g_utf8_to_utf16(name, strlen(name),
						 NULL, &num, NULL);

	for (i=0; i<num; i++) {
		uint16_t *wchar = (uint16_t*)&hd.bs[i*2];
		*wchar = ntohs(*wchar);
	}
	size = (num+1) * sizeof(uint16_t);
	OBEX_ObjectAddHeader(handle, obj, OBEX_HDR_NAME, hd, size, OBEX_FL_FIT_ONE_PACKET);

	if (OBEX_Request(handle, obj) < 0)
		return NULL;

	req_done = state->req_done;
	while (state->req_done == req_done) {
		OBEX_HandleInput(handle, 100);
	}

	if (state->body) {
		*len = state->body_len;
		state->body[state->body_len] = '\0';
	} else {
		*len = 0;
	}
	return state->body;
}
Ejemplo n.º 9
0
int obex_connect(int od, int mode)
{
	obex_t *handle = obex_handles[0];
	struct obex_context *context;
	int err;

	obex_object_t *object;
	obex_headerdata_t hd;

	if (!(context = OBEX_GetUserData(handle)))
		return -1;

	if (!(object = OBEX_ObjectNew(handle, OBEX_CMD_CONNECT)))
		return -1;

	if (mode == OBEX_FILE_TRANSFER) {
		hd.bs = target_ftseq;
		if (OBEX_ObjectAddHeader(handle, object,
				OBEX_HDR_TARGET, hd, 16, OBEX_FL_FIT_ONE_PACKET) < 0) {
			OBEX_ObjectDelete(handle, object);
			return -1;
		}
	} else
		context->cid = 0;

	if ((err = OBEX_Request(handle, object)) < 0)
		return err;

	while (1) {
		OBEX_HandleInput(handle, OBEX_TIMEOUT);

		if (context->state == OBEX_CLOSED) {
			err = -ENODEV;
			break;
		}

		if (context->state == OBEX_CONNECTED)
			break;
	}

	return err;
}
Ejemplo n.º 10
0
/*
 * obex_start_server()
 *
 * runs obex server fds transport
 */
int obexsrv_run(obexsrv_t *srv, int rfd, int wfd)
{
	int	err = 0, to;

	srv->handle = OBEX_Init(OBEX_TRANS_FD, obexsrv_event, 0);
	if (!srv->handle) {
		BTERROR( "OBEX_Init failed:%s", strerror(errno));
		return -1;
	}

	/* init some members */
	srv->sfd = -1;
	srv->name = NULL;
	srv->flags = 0;
	srv->buf = NULL;

	// set private pointer
	OBEX_SetUserData(srv->handle, srv);

	FdOBEX_TransportSetup(srv->handle, rfd, wfd, 0);
	
	for (;;) {
		/* request processing loop */
		DBPRT("Processing request...\n");
		srv->serverdone = FALSE;
		to = 1000;	/* unlimmited - waiting for request */
		while (!srv->serverdone) {
			if ((err = OBEX_HandleInput(srv->handle, to)) < 0) {
				BTERROR("Error while doing OBEX_HandleInput()");
				break;
			}
			to = 5;	/* processing request */
		}
		if (srv->state == SRVSTATE_CLOSED)
			break;
		if (err < 0)
			break;
	}
	OBEX_Cleanup(srv->handle);
	srv->handle = NULL;
	return 0;
}
Ejemplo n.º 11
0
void smartpen_disconnect (obex_t *handle)
{
	struct obex_state *state;
	int req_done;
	obex_object_t *obj;
	obex_headerdata_t hd;
	int size;

	state = OBEX_GetUserData(handle);
	obj = OBEX_ObjectNew(handle, OBEX_CMD_DISCONNECT);
	hd.bq4 = state->connid;
	size = 4;
	OBEX_ObjectAddHeader(handle, obj, OBEX_HDR_CONNECTION,
			     hd, size, OBEX_FL_FIT_ONE_PACKET);

	if (OBEX_Request(handle, obj) < 0)
		return;

	req_done = state->req_done;
	while (state->req_done == req_done) {
		OBEX_HandleInput(handle, 100);
	}
}
Ejemplo n.º 12
0
//
// Do an OBEX request sync.
//
static int cli_sync_request(ircp_client_t *cli, obex_object_t *object)
{
	int ret;
	DEBUG(4, "\n");

	cli->finished = FALSE;
	OBEX_Request(cli->obexhandle, object);

	while(cli->finished == FALSE) {
		ret = OBEX_HandleInput(cli->obexhandle, 20);
		DEBUG(4, "ret = %d\n", ret);

		if (ret <= 0)
			return -1;
	}

	DEBUG(4, "Done success=%d\n", cli->success);

	if(cli->success)
		return 1;
	else
		return -1;
}
Ejemplo n.º 13
0
/**
	Wait for the OBEX client to finish.
 */
static int obexftp_sync(obexftp_client_t *cli)
{
	int ret;
	DEBUG(3, "%s()\n", __func__);

	/* cli->finished = FALSE; */

	while(cli->finished == FALSE) {
		ret = OBEX_HandleInput(cli->obexhandle, cli->accept_timeout);
		DEBUG(3, "%s() OBEX_HandleInput = %d\n", __func__, ret);

		if (ret <= 0) {
			DEBUG(2, "%s() OBEX_HandleInput error: %d\n", __func__, errno);
			return -1;
		}
	}

	DEBUG(3, "%s() Done success=%d\n", __func__, cli->success);

	if(cli->success)
		return 1;
	else
		return - cli->obex_rsp;
}
Ejemplo n.º 14
0
/*
 * Function main (argc, )
 *
 *    Starts all the fun!
 *
 */
int main(int argc, char *argv[])
{
	struct sockaddr_in peer;

	obex_object_t *object;
	int ret;

	printf("Send and receive files over TCP OBEX\n");
	if ( ((argc < 3) || (argc > 3)) && (argc != 1) )	{
		printf ("Usage: %s [name] [peer]\n", argv[0]); 
		return -1;
	}

	handle = OBEX_Init(OBEX_TRANS_INET, obex_event, 0);

	if (argc == 1)	{
		printf("Waiting for files\n");
		ret = InOBEX_ServerRegister(handle);
		if(ret < 0) {
                        printf("Cannot listen to socket\n");
			exit(ret);
		}

		while (!finished) {
			ret = OBEX_HandleInput(handle, 10);
			if (ret == 0) {
				printf("Timeout waiting for connection\n");
				break;
			} else if (ret < 0) {
			        printf("Error waiting for connection\n");
				break;
			}
		}
	}
	else {
		/* We are a client */

		get_peer_addr(argv[2], &peer);
		ret = OBEX_TransportConnect(handle, (struct sockaddr *) &peer,
					  sizeof(struct sockaddr_in));

		if (ret < 0) {
			printf("Sorry, unable to connect!\n");
			exit(ret);
		}

		object = OBEX_ObjectNew(handle, OBEX_CMD_CONNECT);
		ret = do_sync_request(handle, object, 0);

		if( (object = build_object_from_file(handle, argv[1], 0)) )	{
			ret = do_sync_request(handle, object, 0);
		}
		else	{
			perror("PUT failed");
		}

		object = OBEX_ObjectNew(handle, OBEX_CMD_DISCONNECT);
		ret = do_sync_request(handle, object, 0);

		printf("PUT successful\n");
	}
	return 0;
}
Ejemplo n.º 15
0
static int get_peer_addr(char *name, struct sockaddr_storage *peer) 
{
	struct addrinfo hint = {
		.ai_family = AF_UNSPEC,
		.ai_socktype = SOCK_STREAM,
		.ai_protocol = 0,
		.ai_flags = AI_ADDRCONFIG

	};
	struct addrinfo *info;

	int err = getaddrinfo(name, NULL, &hint, &info);
	if (err)
		return err;
	memcpy(peer, info->ai_addr, info->ai_addrlen);
	freeaddrinfo(info);
	return 0;
}

/*
 * Function main (argc, )
 *
 *    Starts all the fun!
 *
 */
int main(int argc, char *argv[])
{
	struct sockaddr_storage peer;

	obex_object_t *object;
	int ret;

	printf("Send and receive files over TCP OBEX\n");
	if ( ((argc < 3) || (argc > 3)) && (argc != 1) )	{
		printf ("Usage: %s [name] [peer]\n", argv[0]); 
		return -1;
	}

	handle = OBEX_Init(OBEX_TRANS_INET, obex_event, 0);

	if (argc == 1)	{
		printf("Waiting for files\n");
		ret = TcpOBEX_ServerRegister(handle, NULL, 0);
		if(ret < 0) {
                        printf("Cannot listen to socket\n");
			exit(ret);
		}

		while (!finished) {
			ret = OBEX_HandleInput(handle, 10);
			if (ret == 0) {
				printf("Timeout waiting for connection\n");
				break;
			} else if (ret < 0) {
			        printf("Error waiting for connection\n");
				break;
			}
		}
	}
	else {
		/* We are a client */

		ret = get_peer_addr(argv[2], &peer);
		if (ret) {
			perror("Bad name");
			exit(1);
		}
		ret = TcpOBEX_TransportConnect(handle, (struct sockaddr *) &peer,
					  sizeof(peer));

		if (ret < 0) {
			printf("Sorry, unable to connect!\n");
			exit(1);
		}

		object = OBEX_ObjectNew(handle, OBEX_CMD_CONNECT);
		ret = do_sync_request(handle, object, 0);

		if( (object = build_object_from_file(handle, argv[1], 0)) )	{
			ret = do_sync_request(handle, object, 0);
		}
		else	{
			perror("PUT failed");
		}

		object = OBEX_ObjectNew(handle, OBEX_CMD_DISCONNECT);
		ret = do_sync_request(handle, object, 0);

		printf("PUT successful\n");
	}
	return 0;
}
Ejemplo n.º 16
0
/*
 * Function main (argc, )
 *
 *    Starts all the fun!
 *
 */
int main(int argc, char *argv[])
{
   obex_object_t *object;
   int ret;
   unsigned height,width;
   int i;

   DAParseArguments(argc, argv, options,
		    sizeof(options)/sizeof(DAProgramOption),
		    "CapShare Document Management Dock Applet\nBen Moore [email protected]\n",
		    VERSION);


   DAInitialize(displayName, "wmcapshare", 60,60, argc, argv);
   DAMakePixmapFromData(lcdchars2_xpm, &char_buf, &char_mask, &height, &width);
   DAMakePixmapFromData(lcdnums_xpm, &num_buf, &num_mask, &height, &width);
   DAMakePixmapFromData(base_xpm, &pixmap, &mask, &height, &width);
   DAMakePixmapFromData(tstatfld_xpm, &tstatfld_buf, &tstatfld_mask, &height, &width);
   DAMakePixmapFromData(tstatfld_xpm, &blank_buf, &blank_mask, &height, &width);
   DAMakePixmapFromData(capshare_xpm, &capshare_pic, &capshare_mask, &height, &width);
   DAMakePixmapFromData(transfering_xpm, &transfer_pic, &transfer_mask, &height, &width);
   DAMakePixmapFromData(connected_xpm, &connect_pic, &connect_mask, &height, &width);
   DAMakePixmapFromData(disconnected_xpm, &disconnect_pic, &disconnect_mask, &height, &width);
   DAMakePixmapFromData( plane00_xpm, &plane_anim[0], &plane_animmask[1], &height, &width);
   DAMakePixmapFromData( plane01_xpm, &plane_anim[1], &plane_animmask[2], &height, &width);
   DAMakePixmapFromData( plane02_xpm, &plane_anim[2], &plane_animmask[3], &height, &width);
   DAMakePixmapFromData( plane03_xpm, &plane_anim[3], &plane_animmask[4], &height, &width);
   DAMakePixmapFromData( plane04_xpm, &plane_anim[4], &plane_animmask[5], &height, &width);
   DAMakePixmapFromData( plane05_xpm, &plane_anim[5], &plane_animmask[6], &height, &width);
   DAMakePixmapFromData( plane06_xpm, &plane_anim[6], &plane_animmask[6], &height, &width);
   DAMakePixmapFromData( plane07_xpm, &plane_anim[7], &plane_animmask[7], &height, &width);
   DAMakePixmapFromData( plane08_xpm, &plane_anim[8], &plane_animmask[8], &height, &width);
   DAMakePixmapFromData( plane09_xpm, &plane_anim[9], &plane_animmask[9], &height, &width);
   DAMakePixmapFromData( plane10_xpm, &plane_anim[10], &plane_animmask[10], &height, &width);
   DAMakePixmapFromData( plane11_xpm, &plane_anim[11], &plane_animmask[11], &height, &width);
   DAMakePixmapFromData( plane12_xpm, &plane_anim[12], &plane_animmask[12], &height, &width);
   DAMakePixmapFromData( plane13_xpm, &plane_anim[13], &plane_animmask[13], &height, &width);
   DAMakePixmapFromData( plane14_xpm, &plane_anim[14], &plane_animmask[14], &height, &width);
   DAMakePixmapFromData( plane15_xpm, &plane_anim[15], &plane_animmask[15], &height, &width);
   DAMakePixmapFromData( plane16_xpm, &plane_anim[16], &plane_animmask[16], &height, &width);
   DAMakePixmapFromData( plane17_xpm, &plane_anim[17], &plane_animmask[17], &height, &width);
   DAMakePixmapFromData( plane18_xpm, &plane_anim[18], &plane_animmask[18], &height, &width);
   DAMakePixmapFromData( plane19_xpm, &plane_anim[19], &plane_animmask[19], &height, &width);

   gc = DefaultGC(DADisplay, DefaultScreen(DADisplay));


/*
 string2pixmap("recieve", &tstatfld_buf);
 XCopyArea(DADisplay, plane_pic, pixmap, gc, 0, 0, 60, 29, 0, 15);
 XCopyArea(DADisplay, tstatfld_buf, pixmap, gc, 0, 0, 42,  8, 16, 48);
 DASetPixmap(pixmap);
 XCopyArea(DADisplay, connect_pic, pixmap, gc, 0, 0, 14, 15, 0, 45);
 DASetPixmap(pixmap);
 */

   XCopyArea(DADisplay, capshare_pic, pixmap, gc, 0, 0, 60, 29,  0, 15);
   DAShow();

   while(1) {
      handle = OBEX_Init(OBEX_TRANS_IRDA, obex_event, 0);

      printf("Waiting for files\n");
      OBEX_ServerRegister(handle, "OBEX");

      while (!finished) {
	 updateDisplay();
	 OBEX_HandleInput(handle, 1);
      }

      finished = FALSE;
   }

   return 0;
}
Ejemplo n.º 17
0
int obex_get(int od, const char *type, const char *name, unsigned char **data, size_t *size)
{
	obex_t *handle = obex_handles[0];
	struct obex_context *context;
	char *unicode;
	int err, len, ulen;

	obex_object_t *object;
	obex_headerdata_t hd;

	if (!(context = OBEX_GetUserData(handle)))
		return -1;

	if (context->state != OBEX_CONNECTED)
		return -1;

	if (context->mode != OBEX_IDLE)
		return -1;

	context->command = OBEX_CMD_GET;
	context->response = 0;

	if (!(object = OBEX_ObjectNew(handle, OBEX_CMD_GET)))
		return -1;

	if (context->cid > 0) {
		hd.bq4 = context->cid;
		OBEX_ObjectAddHeader(handle, object,
			OBEX_HDR_CONNECTION, hd, 4, OBEX_FL_FIT_ONE_PACKET);
	}

	if (type) {
		hd.bs = (uint8_t *) type;
		OBEX_ObjectAddHeader(handle, object,
			OBEX_HDR_TYPE, hd, strlen(type) + 1, OBEX_FL_FIT_ONE_PACKET);
	}

	if (name) {
		ulen = (strlen(name) + 1) * 2;
		unicode = malloc(ulen);
		if (!unicode) {
			OBEX_ObjectDelete(handle, object);
			return -1;
		}

		len = OBEX_CharToUnicode((uint8_t *) unicode, (uint8_t *) name, ulen);
		hd.bs = (uint8_t *) unicode;
		OBEX_ObjectAddHeader(handle, object,
			OBEX_HDR_NAME, hd, len, OBEX_FL_FIT_ONE_PACKET);

		free(unicode);
	}

	if ((err = OBEX_Request(handle, object)) < 0)
		return err;

	context->time = time(0);

	while (1) {
		OBEX_HandleInput(handle, OBEX_TIMEOUT);
		if (context->response)
			break;
	}

	//printf("Rsp: %02x\n", context->response);
	//printf("Err: %s\n", strerror(obex_error(context->response)));

	if (context->response == OBEX_RSP_SUCCESS) {
		*data = context->data_buf;
		*size = context->data_len;
	} else {
		free(context->data_buf);
		err = -1;
	}

	context->mode = OBEX_IDLE;

	return err;
}
Ejemplo n.º 18
0
obex_t *smartpen_connect(short vendor, short product)
{
	obex_t *handle;
	obex_object_t *obj;
	int rc, num, i;
	struct obex_state *state;
	obex_interface_t *obex_intf;
	obex_headerdata_t hd;
	int size, count;
	char *buf;

again:
	handle = OBEX_Init(OBEX_TRANS_USB, obex_event, 0);
	if (!handle)
		goto out;

        num = OBEX_EnumerateInterfaces(handle);
	for (i=0; i<num; i++) {
                obex_intf = OBEX_GetInterfaceByIndex(handle, i);
		if (!strcmp(obex_intf->usb.manufacturer, "Livescribe"))
			break;
	}

        if (i == num) {
		printf("No such device\n");
		handle = NULL;
		goto out;
        }

	state = malloc(sizeof(struct obex_state));
	if (!state) {
		handle = NULL;
		goto out;
	}
	memset(state, 0, sizeof(struct obex_state));

	if (!swizzle_usb(vendor, product)) {
		handle = NULL;
		goto out;
	}

        rc = OBEX_InterfaceConnect(handle, obex_intf);
        if (rc < 0) {
		printf("Connect failed %d\n", rc);
		handle = NULL;
		goto out;
	}

        OBEX_SetUserData(handle, state);
        OBEX_SetTransportMTU(handle, 0x400, 0x400);

        obj = OBEX_ObjectNew(handle, OBEX_CMD_CONNECT);
        hd.bs = (unsigned char *)"LivescribeService";
        size = strlen((char*)hd.bs)+1;
        OBEX_ObjectAddHeader(handle, obj, OBEX_HDR_TARGET, hd, size, 0);

        rc = OBEX_Request(handle, obj);

	count = state->req_done;
        while (rc == 0 && state->req_done <= count) {
            OBEX_HandleInput(handle, 100);
        }

	if (rc < 0 || !state->got_connid) {
		printf("Retry connection...\n");
		OBEX_Cleanup(handle);
		goto again;
	}

	buf = get_named_object(handle, "ppdata?key=pp0000", &rc);
	if (!buf) {
		printf("Retry connection...\n");
		OBEX_Cleanup(handle);
		pen_reset(vendor, product);
		goto again;
	}

out:
	return handle;
}