11619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kelly/* -----------------------------------------------------------------------------
21619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kelly * Copyright (c) 2011 Ozmo Inc
31619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kelly * Released under the GNU General Public License Version 2 (GPLv2).
41619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kelly * -----------------------------------------------------------------------------
51619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kelly */
61619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kelly#ifndef _OZPROTO_H
71619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kelly#define _OZPROTO_H
81619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kelly
91619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kelly#include <asm/byteorder.h>
101619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kelly#include "ozconfig.h"
111619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kelly#include "ozappif.h"
121619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kelly
131619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kelly#define OZ_ALLOCATED_SPACE(__x)	(LL_RESERVED_SPACE(__x)+(__x)->needed_tailroom)
141619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kelly
151619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kelly/* Converts millisecs to jiffies.
161619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kelly */
171619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kelly#define oz_ms_to_jiffies(__x)	(((__x)*1000)/HZ)
181619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kelly
191619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kelly/* Quantum milliseconds.
201619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kelly */
211619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kelly#define OZ_QUANTUM_MS		8
221619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kelly/* Quantum jiffies
231619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kelly */
241619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kelly#define OZ_QUANTUM_J		(oz_ms_to_jiffies(OZ_QUANTUM_MS))
251619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kelly/* Default timeouts.
261619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kelly */
271619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kelly#define OZ_CONNECTION_TOUT_J	(2*HZ)
281619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kelly#define OZ_PRESLEEP_TOUT_J	(11*HZ)
291619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kelly
301619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kelly/* Maximun sizes of tx frames. */
311619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kelly#define OZ_MAX_TX_SIZE		1514
321619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kelly
331619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kelly/* Application handler functions.
341619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kelly */
351619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kellytypedef int (*oz_app_init_fn_t)(void);
361619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kellytypedef void (*oz_app_term_fn_t)(void);
371619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kellytypedef int (*oz_app_start_fn_t)(struct oz_pd *pd, int resume);
381619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kellytypedef void (*oz_app_stop_fn_t)(struct oz_pd *pd, int pause);
391619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kellytypedef void (*oz_app_rx_fn_t)(struct oz_pd *pd, struct oz_elt *elt);
401619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kellytypedef int (*oz_app_hearbeat_fn_t)(struct oz_pd *pd);
411619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kellytypedef void (*oz_app_farewell_fn_t)(struct oz_pd *pd, u8 ep_num,
421619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kelly			u8 *data, u8 len);
431619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kelly
441619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kellystruct oz_app_if {
451619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kelly	oz_app_init_fn_t	init;
461619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kelly	oz_app_term_fn_t	term;
471619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kelly	oz_app_start_fn_t	start;
481619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kelly	oz_app_stop_fn_t	stop;
491619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kelly	oz_app_rx_fn_t		rx;
501619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kelly	oz_app_hearbeat_fn_t	heartbeat;
511619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kelly	oz_app_farewell_fn_t	farewell;
521619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kelly	int			app_id;
531619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kelly};
541619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kelly
551619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kellyint oz_protocol_init(char *devs);
561619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kellyvoid oz_protocol_term(void);
571619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kellyint oz_get_pd_list(struct oz_mac_addr *addr, int max_count);
581619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kellyvoid oz_app_enable(int app_id, int enable);
591619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kellystruct oz_pd *oz_pd_find(u8 *mac_addr);
601619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kellyvoid oz_binding_add(char *net_dev);
611619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kellyvoid oz_binding_remove(char *net_dev);
621619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kellyvoid oz_timer_add(struct oz_pd *pd, int type, unsigned long due_time,
631619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kelly		int remove);
641619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kellyvoid oz_timer_delete(struct oz_pd *pd, int type);
651619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kellyvoid oz_pd_request_heartbeat(struct oz_pd *pd);
661619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kellyvoid oz_polling_lock_bh(void);
671619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kellyvoid oz_polling_unlock_bh(void);
681619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kelly
691619cb6f2dd9674491e5772bf37b45e03666dc10Chris Kelly#endif /* _OZPROTO_H */
70