libnjb 2.2.7

protocol3.h
Go to the documentation of this file.
1
57 #ifndef __NJB__PROTO3__H
58 #define __NJB__PROTO3__H
59
60 #include "libnjb.h"
61
62 /* Buffer for short reads */
63 #define NJB3_SHORTREAD_BUFSIZE 1024
64
65 /* Transfer block size (adding and fetching tracks, files */
66 #define NJB3_CHUNK_SIZE 0x100000U
67 #define NJB3_FIRMWARE_CHUNK_SIZE 0x40000U
68 #define NJB3_DEFAULT_GET_FILE_BLOCK_SIZE 0x2000U
69 #define NJB3_DEFAULT_SEND_FILE_BLOCK_SIZE 0x2000U
70
71 /*
72 * These are the frame IDs used by the series 3 devices.
73 * The frames are used for all the commands listed above, so
74 * the same number series will contain very different things
75 * like different kind of device properties and parameters
76 * (e.g. disk utilization) and metadata tag elements (e.g.
77 * "artist field"). The only way to see what a frame actually
78 * represents is to see how it is used.
79 */
80 #define NJB3_CODECS_FRAME_ID 0x0001U /* 16 bit array R: List of supported audio file types/codecs */
81 #define NJB3_DISKUTIL_FRAME_ID 0x0002U /* 14 bytes R: disk utilization information */
82 #define NJB3_PRODID_FRAME_ID 0x0003U /* 3 bytes FW rev 3 bytes HW rev, string product ID */
83 /*
84 * 0x0004 and 0x0005 return NULL when read as device
85 * parameters, are probably used as some kind of
86 * metadata frames.
87 */
88 #define NJB3_LOCKED_FRAME_ID 0x0006U /* 16 bit word */
89 #define NJB3_FNAME_FRAME_ID 0x0007U /* String: Original filename on host */
90 #define NJB3_UNKNOWN1_FRAME_ID 0x0008U /* 16 bit word, value 0x0004 on NJB Zen USB 2.0, not read by Win SW */
91 #define NJB3_KEY_FRAME_ID 0x000aU /* 4 bytes string "AR00", "PL00", "SG00", "LG00" known */
92 #define NJB3_CODEC_FRAME_ID 0x000bU /* 16 bit word */
93 #define NJB3_POSTID_FRAME_ID 0x000cU /* 16 bit word TrackID on tracks, PlaylistID on playlists */
94 #define NJB3_DIR_FRAME_ID 0x000dU /* String: Original directory on host */
95 #define NJB3_FILESIZE_FRAME_ID 0x000eU /* 32 bit word */
96 /*
97 * 0x0010 and 0x0011 return a 16-bit value of 0x0002
98 * respective 0x0200 when read as device parameters.
99 * e.g. 0000 0004 0011 0200 0000
100 * 0x0011 may be sector size or USB xfer block size...
101 */
102 #define NJB3_FILECOUNT_FRAME_ID 0x0013U /* 32 bit word R: file & directory count */
103 #define NJB3_VALUE_FRAME_ID 0x0014U /* 8 bytes, 2*32 bit words */
104 #define NJB3_JUKEBOXID_FRAME_ID 0x0015U /* 16 bytes R: unique device ID */
105 #define NJB3_FILETIME_FRAME_ID 0x0016U /* 32 bit word - timestamp (UNIX format) */
106 #define NJB3_UNKNOWN6_FRAME_ID 0x0017U /* 32 bit word - could be FAT32 attributes */
107 #define NJB3_FILEFLAGS_FRAME_ID 0x0018U /* 32 bit word set on files and folders - NTFS file attributes */
108 /*
109 * 0x0100 is some kind of 6-byte device parameter, value
110 * from NJB Zen USB 2.0: 0001 0000 03ff
111 */
112 #define NJB3_ALBUM_FRAME_ID 0x0101U /* String */
113 #define NJB3_ARTIST_FRAME_ID 0x0102U /* String */
114 #define NJB3_GENRE_FRAME_ID 0x0103U /* String */
115 #define NJB3_TITLE_FRAME_ID 0x0104U /* String */
116 #define NJB3_LENGTH_FRAME_ID 0x0105U /* String */
117 #define NJB3_TRACKNO_FRAME_ID 0x0106U /* 16 bit word */
118 #define NJB3_YEAR_FRAME_ID 0x0107U /* 16 bit word */
119 /*
120 * Smartvolume parameters for a track is sent after a track with the command:
121 * 0x0001 0x0001 update file with info
122 * 0x0000 0x0000 4 bytes trackid
123 * 0x01b6 (length)
124 * 0x010a (smartvol)
125 * 0x01b6 unknown bytes, appears to be an array of 109 32-bit words.
126 * 0x0000 terminator
127 */
128 #define NJB3_SMARTPAR_FRAME_ID 0x010aU
129 /*
130 * 16 bit word R/W: Info about current track playing on the device
131 * First byte appear to always be 0x0b, second means the following:
132 * 0x00 = play/playing
133 * 0x01 = stop/stopped
134 * 0x02 = pause/paused
135 * 0x03 = resume (write only)
136 */
137 #define NJB3_PLAYINFO_FRAME_ID 0x010bU
138 #define NJB3_SEEKTRACK_FRAME_ID 0x010cU /* 32 bit word W: seek to position (in ms) in current track */
139 #define NJB3_EAX_TYPENAME 0x010eU /* String with the name of an EAX type */
140 #define NJB3_PLNAME_FRAME_ID 0x010fU /* String: playlist name */
141 /*
142 * 8 bytes R/W, BCD-encoded time and date:
143 * byte: meaning:
144 * 00: day of the week (0 = sunday)
145 * 01: day of the month (1-31)
146 * 02: month of the year (1-12)
147 * 03: year century digit (20 mostly...)
148 * 04: year lower part
149 * 05: hours
150 * 06: minutes
151 * 07: seconds
152 * e.g.: 0619 1120 0518 4351,
153 * means saturday, 2005-11-19, 18:43:51
154 */
155 #define NJB3_TIME_FRAME_ID 0x0110U
156 #define NJB3_ALBUMCNT_FRAME_ID 0x0111U /* 32 bit word R: number of albums on device */
157 #define NJB3_TRACKCNT_FRAME_ID 0x0112U /* 32 bit word R: number of tracks on device */
158 #define NJB3_OWNER_FRAME_ID 0x0113U /* String: owner name */
159 /*
160 * 4 bytes: 0x14, one byte charging status then 16 bits of battery level
161 * The first byte appear to always contain 0x14.
162 * The second value is interpreted as follows:
163 * 0x00 = power connected and charging
164 * 0x01 = power connected, battery fully charged
165 * 0x02 = power disconnected
166 * Then follows the battery level as a 16bit value.
167 */
168 #define NJB3_BATTERY_FRAME_ID 0x0114U
169 #define NJB3_PLCNT_FRAME_ID 0x0115U /* 32 bit word: number of playlists on device */
170 /*
171 * 0x0116-0x0118 can be read as device registers.
172 * they will return one 32 bit word each, this is
173 * what it looks like on NJB Zen USB 2.0 in rest
174 * mode:
175 *
176 * 0x0116: 00000000
177 * 0x0117: 00000000
178 * 0x0118: ffffffff
179 *
180 */
181 #define NJB3_PLAYTRACK_FRAME_ID 0x0119U /* 32 bit word track ID to play */
182 /*
183 * Seen after clearing the playback queue in this sequence:
184 * 0007 0001 0004 011a 1a00 0000 reading it out gives the
185 * same value so probably the writing of it is useless.
186 */
187 #define NJB3_UNKNOWN4_FRAME_ID 0x011aU
188 #define NJB3_PLTRACKS_FRAME_ID 0x011cU /* Array of 16bit words */
189 /*
190 * 0x011d - 0x0120 return sensible, static but undeciphered values
191 * when read out as device registers. Sample values from NJB Zen USB 2.0:
192 * 0x011d: 00000407
193 * 0x011e: 00000070
194 * 0x011f: 1f00 1f01 1f02 1f03
195 * 0x0120: 0001 fffe 0011
196 */
197 #define NJB3_MINMAX_ID 0x0201U /* 2x16 bit values, max and min */
198 #define NJB3_EAX_ACTIVE_ID 0x0202U /* 16 bit word - this EAX type is active/to
199 * be activated (0x0000 = off, 0x0001 = on) */
200 #define NJB3_VOLUME_FRAME_ID 0x0203U /* 16 bit word */
201 #define NJB3_ENV_FRAME_ID 0x0204U /* 16 bit word - environment setting */
202 #define NJB3_EQ_FRAME_ID 0x0205U /* 16 bit word - equalizer setting */
203 #define NJB3_SPAT_FRAME_ID 0x0206U /* 16 bit word - spatialization 2 = full */
204 #define NJB3_TSCALE_FRAME_ID 0x0207U /* 16 bit word - time scaling factor */
205 #define NJB3_SMARTVOL_FRAME_ID 0x0208U /* 16 bit word - smart volume setting */
206 #define NJB3_EAXACTIVE_FRAME_ID 0x020aU /* 16 bit word - 0x0000/0x0001 = activate/deactivate EAX processor */
207 #define NJB3_EAXID_FRAME_ID 0x020bU /* 16 bit word with the numerical ID of a certain EAX type */
208 #define NJB3_EAX_INDEX_ID 0x020cU /* 16 bit word - currently selected effect in a set of effects */
209 #define NJB3_KEYVALUE_FRAME_ID 0x1400U /* Array of value-key-pairs, requested in a
210 subrequest parameter to this request */
211
212 /* Database IDs, used for eg create_file */
213 #define NJB3_FILE_DATABASE 0x0000U
214 #define NJB3__PLAYLIST_DATABASE 0x0001U
215 #define NJB3_TRACK_DATABASE 0x0002U
216
217 /* Codec IDs */
218 #define NJB3_CODEC_MP3_ID_OLD 0x0000U /* Used on NJB3/Zen FW? */
219 #define NJB3_CODEC_WAV_ID 0x0001U
220 #define NJB3_CODEC_MP3_ID 0x0002U
221 #define NJB3_CODEC_WMA_ID 0x0003U
222 /*
223 * 0x0004, 0x0005 and 0x0006 unknown, one of them is
224 * undoubtedly the Real Networks AAC + Helix DRM
225 * decoder. Only very certain firmwares will support
226 * these I believe...
227 */
228 #define NJB3_CODEC_AA_ID 0x0007U /* Audible.com codec */
229 #define NJB3_CODEC_PROTECTED_WMA_ID 0x0203U /* Is it two bytes actually? */
230
231 /* Stop, pause and resume are very much alike. */
232 #define NJB3_START_PLAY 0x00
233 #define NJB3_STOP_PLAY 0x01
234 #define NJB3_PAUSE_PLAY 0x02
235 #define NJB3_RESUME_PLAY 0x03
236
237 /* Status codes */
238 #define NJB3_STATUS_OK 0x0000U
239 #define NJB3_STATUS_EMPTY 0x0001U /* You tried to retrieve an empty item */
240 #define NJB3_STATUS_TRANSFER_ERROR 0x0002U /* Error during read or write */
241 #define NJB3_STATUS_BAD_FILESIZE 0x0003U /* Illegal file size (e.g. negative, too large) */
242 #define NJB3_STATUS_NOTIMPLEMENTED 0x0004U /* For example if EAX is not supported on a device */
243 #define NJB3_STATUS_NOTEXIST 0x0005U /* Tried to access nonexistant track */
244 #define NJB3_STATUS_PROTECTED 0x000cU /* Tried to access protected object */
245 #define NJB3_STATUS_EMPTY_CHUNK 0x000eU /* Appear when requesting empty metadata lists
246 * or beyond the end of files. */
247
248 /*
249 * Status codes that must exist, find by trial-and-error:
250 * - postid invalid (does not exist)
251 * - disk full
252 * - file path / track name etc too long
253 * - playing (cannot transfer when playing)
254 * - tried to skip to position outside file in playback mode
255 * - too many files/tracks etc - limit reached.
256 * - filename or track+artist+(all metadata) is the same as
257 * one already present on the player
258 * - transfer in progress (a track/file is transferring in
259 * either direction
260 */
261
262 #define njb3_start_play(njb) njb3_ctrl_playing(njb, NJB3_START_PLAY)
263 #define njb3_stop_play(njb) njb3_ctrl_playing(njb, NJB3_STOP_PLAY)
264 #define njb3_pause_play(njb) njb3_ctrl_playing(njb, NJB3_PAUSE_PLAY)
265 #define njb3_resume_play(njb) njb3_ctrl_playing(njb, NJB3_RESUME_PLAY)
266
267 /* Structure to hold protocol3 states */
268 typedef struct {
269 /* Get extended tags */
270 int get_extended_tag_info;
271 njb_songid_t *first_songid;
272 njb_songid_t *next_songid;
273 njb_playlist_t *first_plid;
274 njb_playlist_t *next_plid;
275 njb_datafile_t *first_dfid;
276 njb_datafile_t *next_dfid;
277 int current_playing_track;
278 njb_keyval_t *first_key;
279 njb_keyval_t *next_key;
280 njb_eax_t *first_eax;
281 njb_eax_t *next_eax;
283 u_int8_t eax_processor_active;
285 char *product_name;
287 u_int8_t fwMajor;
289 u_int8_t fwMinor;
291 u_int8_t fwRel;
293 u_int8_t hwMajor;
295 u_int8_t hwMinor;
297 u_int8_t hwRel;
299 u_int16_t last_elapsed;
301 u_int8_t turbo_mode;
302 } njb3_state_t;
303
304
305 /*
306 * NJB3 functions: the commands listed at the top of this
307 * file are wrapped in binary form more or less using the defined
308 * values in this file to conjure and decipher byte-sequences
309 * sent by the devices.
310 */
311 int njb3_init_state (njb_t *njb);
312 int njb3_set_bitmap(njb_t *njb, u_int16_t x_size, u_int16_t y_size, const unsigned char *bitmap);
313 int njb3_current_track (njb_t *njb, u_int16_t * track);
314 int njb3_elapsed_time (njb_t *njb, u_int16_t * elapsed, int * change);
315 int njb3_play_track (njb_t *njb, u_int32_t trackid);
316 int njb3_queue_track (njb_t *njb, u_int32_t trackid);
317 int njb3_clear_play_queue(njb_t *njb);
318 int njb3_ctrl_playing (njb_t *njb, int cmd);
319 int njb3_seek_track (njb_t *njb, u_int32_t position);
320 int njb3_get_codecs(njb_t *njb);
321 int njb3_ping (njb_t *njb, int type);
322 int njb3_power_status (njb_t *njb, int *battery_level, int *charging, int *ac_power);
323 int njb3_readid (njb_t *njb, u_int8_t *sdmiid);
324 int njb3_capture (njb_t *njb);
325 int njb3_release (njb_t *njb);
326 int njb3_get_disk_usage (njb_t *njb, u_int64_t *totalbytes, u_int64_t *freebytes);
327 int njb3_turnoff_flashing(njb_t *njb);
328 int njb3_get_owner_string (njb_t *njb, char *name);
329 int njb3_set_owner_string (njb_t *njb, const char *name);
330 njb_time_t *njb3_get_time(njb_t *njb);
331 int njb3_set_time(njb_t *njb, njb_time_t *time);
332 int njb3_reset_get_track_tag (njb_t *njb);
333 njb_songid_t *njb3_get_next_track_tag (njb_t *njb);
334 int njb3_reset_get_playlist_tag (njb_t *njb);
335 njb_playlist_t *njb3_get_next_playlist_tag (njb_t *njb);
336 int njb3_reset_get_datafile_tag (njb_t *njb);
337 njb_datafile_t *njb3_get_next_datafile_tag (njb_t *njb);
338 int njb3_read_keys(njb_t *njb);
339 njb_keyval_t *njb3_get_keys(njb_t *njb);
340 int njb3_request_file_chunk(njb_t *njb, u_int32_t fileid, u_int32_t offset);
341 int njb3_get_file_block(njb_t *njb, unsigned char *data, u_int32_t maxsize);
342 u_int32_t njb3_create_file(njb_t *njb, unsigned char *ptag, u_int32_t tagsize, u_int16_t database);
343 u_int32_t njb3_send_file_chunk(njb_t *njb, unsigned char *chunk, u_int32_t chunksize, u_int32_t fileid);
344 int njb3_send_file_complete(njb_t *njb, u_int32_t fileid);
345 int njb3_create_folder(njb_t *njb, const char *name, u_int32_t *folderid);
346 int njb3_delete_item(njb_t *njb, u_int32_t itemid);
347 int njb3_update_16bit_frame(njb_t *njb, u_int32_t itemid, u_int16_t frameid, u_int16_t value);
348 int njb3_update_string_frame(njb_t *njb, u_int32_t itemid, u_int16_t frameid, unsigned char *str);
349 int njb3_update_tag(njb_t *njb, u_int32_t trackid, unsigned char *ptag, u_int32_t ptagsize);
350 int njb3_create_playlist(njb_t *njb, char *name, u_int32_t *plid);
351 int njb3_add_multiple_tracks_to_playlist (njb_t *njb, u_int32_t *plid, u_int32_t *trids, u_int16_t ntracks);
352 int njb3_adjust_volume(njb_t *njb, u_int16_t value);
353 int njb3_control_eax_processor (njb_t * njb, u_int16_t state);
354 int njb3_adjust_eax(njb_t *njb, u_int16_t eaxid, u_int16_t patchindex, u_int16_t active, u_int16_t scalevalue);
355 void njb3_read_eaxtypes(njb_t *njb);
356 njb_eax_t *njb3_get_nexteax(njb_t *njb);
357 int njb3_announce_firmware(njb_t *njb, u_int32_t size);
358 u_int32_t njb3_send_firmware_chunk(njb_t *njb, u_int32_t chunksize, unsigned char *chunk);
359 int njb3_get_firmware_confirmation(njb_t *njb);
360 void njb3_destroy_state(njb_t *njb);
361
362 #endif
njb3_destroy_state
void njb3_destroy_state(njb_t *njb)
Definition: protocol3.c:4593
njb3_state_t
Definition: protocol3.h:268
njb3_state_t::fwMajor
u_int8_t fwMajor
Definition: protocol3.h:287
njb3_state_t::product_name
char * product_name
Definition: protocol3.h:285
njb3_get_codecs
int njb3_get_codecs(njb_t *njb)
Definition: protocol3.c:223
njb3_set_bitmap
int njb3_set_bitmap(njb_t *njb, u_int16_t x_size, u_int16_t y_size, const unsigned char *bitmap)
Definition: protocol3.c:950
njb3_state_t::eax_processor_active
u_int8_t eax_processor_active
Definition: protocol3.h:283
njb3_state_t::turbo_mode
u_int8_t turbo_mode
Definition: protocol3.h:301
njb3_control_eax_processor
int njb3_control_eax_processor(njb_t *njb, u_int16_t state)
Definition: protocol3.c:4028
njb3_init_state
int njb3_init_state(njb_t *njb)
Definition: protocol3.c:41
njb3_reset_get_datafile_tag
int njb3_reset_get_datafile_tag(njb_t *njb)
Definition: protocol3.c:3019
njb3_update_string_frame
int njb3_update_string_frame(njb_t *njb, u_int32_t itemid, u_int16_t frameid, unsigned char *str)
Definition: protocol3.c:3728
njb3_add_multiple_tracks_to_playlist
int njb3_add_multiple_tracks_to_playlist(njb_t *njb, u_int32_t *plid, u_int32_t *trids, u_int16_t ntracks)
Definition: protocol3.c:3944
njb3_get_firmware_confirmation
int njb3_get_firmware_confirmation(njb_t *njb)
Definition: protocol3.c:4569
njb3_state_t::hwRel
u_int8_t hwRel
Definition: protocol3.h:297
njb3_get_file_block
int njb3_get_file_block(njb_t *njb, unsigned char *data, u_int32_t maxsize)
Definition: protocol3.c:3342
njb3_reset_get_playlist_tag
int njb3_reset_get_playlist_tag(njb_t *njb)
Definition: protocol3.c:2814
njb3_state_t::fwRel
u_int8_t fwRel
Definition: protocol3.h:291
njb3_update_16bit_frame
int njb3_update_16bit_frame(njb_t *njb, u_int32_t itemid, u_int16_t frameid, u_int16_t value)
Definition: protocol3.c:3675
njb3_power_status
int njb3_power_status(njb_t *njb, int *battery_level, int *charging, int *ac_power)
Definition: protocol3.c:403
njb3_send_firmware_chunk
u_int32_t njb3_send_firmware_chunk(njb_t *njb, u_int32_t chunksize, unsigned char *chunk)
Definition: protocol3.c:4545
njb_eax_struct
Definition: libnjb.h:349
njb3_create_playlist
int njb3_create_playlist(njb_t *njb, char *name, u_int32_t *plid)
Definition: protocol3.c:3865
njb3_state_t::fwMinor
u_int8_t fwMinor
Definition: protocol3.h:289
njb3_update_tag
int njb3_update_tag(njb_t *njb, u_int32_t trackid, unsigned char *ptag, u_int32_t ptagsize)
Definition: protocol3.c:3798
njb_songid_struct
Definition: libnjb.h:222
njb3_state_t::hwMinor
u_int8_t hwMinor
Definition: protocol3.h:295
njb_struct
Definition: libnjb.h:182
njb3_announce_firmware
int njb3_announce_firmware(njb_t *njb, u_int32_t size)
Definition: protocol3.c:4519
njb3_state_t::last_elapsed
u_int16_t last_elapsed
Definition: protocol3.h:299
njb_keyval_struct
Definition: libnjb.h:417
njb_time_struct
Definition: libnjb.h:403
njb_playlist_struct
Definition: libnjb.h:247
njb_datafile_struct
Definition: libnjb.h:275
libnjb.h
njb3_state_t::hwMajor
u_int8_t hwMajor
Definition: protocol3.h:293
njb3_request_file_chunk
int njb3_request_file_chunk(njb_t *njb, u_int32_t fileid, u_int32_t offset)
Definition: protocol3.c:3239