summaryrefslogtreecommitdiff
path: root/libthor/thor.h
blob: dceb273d63d8600b4ae9a34b4f563bf7cc498718 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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__ */