Esempio n. 1
0
obex_t *obex_open(int fd, obex_callback_t *callback, void *data)
{
	obex_t *handle;
	obex_context_t *context;

	context = malloc(sizeof(*context));
	if (!context)
		return NULL;

	memset(context, 0, sizeof(*context));

	context->state = OBEX_OPEN;
	context->cid = CID_INVALID;

	handle = OBEX_Init(OBEX_TRANS_FD, obex_event, 0);
	if (!handle) {
		free(context);
		return NULL;
	}

	context->user_data = data;
	context->callback = callback;
	context->tx_max = sizeof(context->buf);

	OBEX_SetUserData(handle, context);

	OBEX_SetTransportMTU(handle, sizeof(context->buf), sizeof(context->buf));

	if (FdOBEX_TransportSetup(handle, fd, fd, 0) < 0) {
		OBEX_Cleanup(handle);
		return NULL;
	}

        return handle;
}
Esempio n. 2
0
int obex_open(bdaddr_t *src, bdaddr_t *dst, uint8_t channel)
{
	obex_t *handle;
	struct obex_context *context;

	if (!(context = malloc(sizeof(struct obex_context))))
		return -1;

	if (!(handle = OBEX_Init(OBEX_TRANS_BLUETOOTH, obex_event, 0)))
		return -1;

	context->state = OBEX_OPEN;
	context->mode = OBEX_IDLE;

	OBEX_SetUserData(handle, context);

	OBEX_SetTransportMTU(handle, OBEX_MAXIMUM_MTU, OBEX_MAXIMUM_MTU);

	if (BtOBEX_TransportConnect(handle, src, dst, channel) < 0)
		return -1;

	obex_handles[0] = handle;

	return 0;
}
Esempio n. 3
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;
}