diff options
author | Krzysztof Opasiak <k.opasiak@samsung.com> | 2016-05-09 13:19:28 +0200 |
---|---|---|
committer | Seung-Woo Kim <sw0312.kim@samsung.com> | 2016-07-25 14:39:49 +0900 |
commit | c3eab3671569f01d454c66caf56875b01c3e9923 (patch) | |
tree | ac839d1271812b5aea8fbff7318dd6c7f892584a | |
parent | 9247d6c94bf9cca613b85b25d8002789b53577e0 (diff) | |
download | lthor-c3eab3671569f01d454c66caf56875b01c3e9923.tar.gz lthor-c3eab3671569f01d454c66caf56875b01c3e9923.tar.bz2 lthor-c3eab3671569f01d454c66caf56875b01c3e9923.zip |
Add headers with API for new implementation of thor protocol
Add new headers with:
- API for accessing new implementation of thor protocol
- Internal data structure which will be used by libthor
Copy also header with definitions of messages used by thor
protocol.
Change-Id: I0e6901a45737e3711f9328f757f76de96b88bdd3
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
-rw-r--r-- | libthor/thor-proto.h | 78 | ||||
-rw-r--r-- | libthor/thor.h | 101 | ||||
-rw-r--r-- | libthor/thor_internal.h | 48 |
3 files changed, 227 insertions, 0 deletions
diff --git a/libthor/thor-proto.h b/libthor/thor-proto.h new file mode 100644 index 0000000..b02c6d5 --- /dev/null +++ b/libthor/thor-proto.h @@ -0,0 +1,78 @@ +#ifndef __THOR_PROTO_H__ +#define __THOR_PROTO_H__ + +typedef enum { + RQT_INFO = 200, + RQT_CMD, + RQT_DL, + RQT_UL, +} request_type; + +/* Request Data */ +/* RQT_INFO */ +enum { + RQT_INFO_VER_PROTOCOL = 1, + RQT_INFO_VER_HW, + RQT_INFO_VER_BOOT, + RQT_INFO_VER_KERNEL, + RQT_INFO_VER_PLATFORM, + RQT_INFO_VER_CSC, +}; + +/* RQT_CMD */ +enum { + RQT_CMD_REBOOT = 1, + RQT_CMD_POWEROFF, +}; + +/* RQT_DL */ +enum { + RQT_DL_INIT = 1, + RQT_DL_FILE_INFO, + RQT_DL_FILE_START, + RQT_DL_FILE_END, + RQT_DL_EXIT, +}; + +/* RQT_UL */ +enum { + RQT_UL_INIT = 1, + RQT_UL_START, + RQT_UL_END, + RQT_UL_EXIT, +}; + +enum __binary_type { + BINARY_TYPE_NORMAL = 0, + BINARY_TYPE_PIT, +}; + +struct rqt_pkt { + int32_t id; /* Request Group ID. */ + int32_t sub_id; /* Request Data ID. */ + int32_t int_data[14]; /* Int. Datas. */ + char str_data[5][32]; /* Str. Data. */ + char md5[32]; /* MD5 Checksum. */ +}; + + +struct res_pkt { + int32_t id; /* Response Group ID == Request Group ID. */ + int32_t sub_id; /* Response Data ID == Request Data ID. */ + int32_t ack; /* Ack. */ + int32_t int_data[5]; /* Int. Datas. */ + char str_data[3][32]; /* Str. Data. */ +}; + + +struct data_res_pkt { + int32_t ack; /* Ack. */ + int32_t cnt; /* Int. Datas. */ +}; + + +#define RQT_PKT_SIZE sizeof(struct rqt_pkt) +#define RES_PKT_SIZE sizeof(struct res_pkt) +#define DATA_RES_PKT_SIZE sizeof(struct data_res_pkt) + +#endif /* __THOR_PROTO_H__ */ diff --git a/libthor/thor.h b/libthor/thor.h new file mode 100644 index 0000000..dceb273 --- /dev/null +++ b/libthor/thor.h @@ -0,0 +1,101 @@ +/* + * libthor - Tizen Thor communication protocol + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef THOR_H__ +#define THOR_H__ + +#include <sys/types.h> +#include <stdio.h> +#include <stddef.h> + +struct thor_device_id { + const char *busid; + int vid; + int pid; + const char *serial; +}; + +struct thor_device_handle; +typedef struct thor_device_handle thor_device_handle; + +enum thor_data_type { + THOR_NORMAL_DATA = 0, + THOR_PIT_DATA, +}; + +struct thor_data_src { + size_t (*get_file_length)(struct thor_data_src *src); + size_t (*get_size)(struct thor_data_src *src); + size_t (*get_block)(struct thor_data_src *src, void *data, size_t len); + const char* (*get_name)(struct thor_data_src *src); + int (*next_file)(struct thor_data_src *src); + void (*release)(struct thor_data_src *src); +}; + +enum thor_data_src_format { + THOR_FORMAT_RAW = 0, + THOR_FORMAT_TAR, +}; + +typedef void (*thor_progress_cb)(thor_device_handle *th, + struct thor_data_src *data, + int sent, int left, int chunk_nmb, + void *user_data); + +typedef void (*thor_next_entry_cb)(thor_device_handle *th, + struct thor_data_src *data, + void *user_data); + +/* Init the Thor library */ +int thor_init(); + +/* Cleanup the thor library */ +void thor_cleanup(); + +/* Check if device is thor compatible */ +int thor_check_proto(struct thor_device_id *dev_id); + +/* Open the device and prepare it for thor communication */ +int thor_open(struct thor_device_id *dev_id, int wait, + thor_device_handle **handle); + +/* Close the device */ +void thor_close(thor_device_handle *th); + +/* Start thor "session" */ +int thor_start_session(thor_device_handle *th, size_t total); + +/* Send a butch of data to the target */ +int thor_send_data(thor_device_handle *th, struct thor_data_src *data, + enum thor_data_type type, thor_progress_cb report_progress, + void *user_data, thor_next_entry_cb report_next_entry, + void *ne_cb_data); + +/* End the session */ +int thor_end_session(thor_device_handle *th); + +/* Open a standard file or archive as data source for thor */ +int thor_get_data_src(const char *path, enum thor_data_src_format format, + struct thor_data_src **data); + +/* Release data source */ +void thor_release_data_src(struct thor_data_src *data); + +/* Request target reboot */ +int thor_reboot(thor_device_handle *th); + +#endif /* THOR_H__ */ + diff --git a/libthor/thor_internal.h b/libthor/thor_internal.h new file mode 100644 index 0000000..467a450 --- /dev/null +++ b/libthor/thor_internal.h @@ -0,0 +1,48 @@ +/* + * libthor - Tizen Thor communication protocol + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef THOR_INTERNAL_H__ +#define THOR_INTERNAL_H__ + +#include <libusb-1.0/libusb.h> + +#include "thor.h" +#include "thor-proto.h" + +#define DEFAULT_TIMEOUT 1000 /* 1000 ms */ + +#ifndef offsetof +#define offsetof(type, member) ((size_t) &((type *)0)->member) +#endif /* offsetof */ + +#define container_of(ptr, type, member) ({ \ + const typeof( ((type *)0)->member ) *__mptr = (ptr); \ + (type *)( (char *)__mptr - offsetof(type,member) );}) + +#define ARRAY_SIZE(_a) (sizeof(_a)/sizeof(_a[0])) + +struct thor_device_handle { + libusb_device_handle *devh; + int control_interface; + int control_interface_id; + int data_interface; + int data_interface_id; + int data_ep_in; + int data_ep_out; +}; + +#endif /* THOR_INTERNAL_H__ */ + |