1 /* Copyright (c) 2013-2014, 2016, The Linux Foundation. All rights reserved.
2  *
3  * Redistribution and use in source and binary forms, with or without
4  * modification, are permitted provided that the following conditions are
5  * met:
6  *     * Redistributions of source code must retain the above copyright
7  *       notice, this list of conditions and the following disclaimer.
8  *     * Redistributions in binary form must reproduce the above
9  *       copyright notice, this list of conditions and the following
10  *       disclaimer in the documentation and/or other materials provided
11  *       with the distribution.
12  *     * Neither the name of The Linux Foundation nor the names of its
13  *       contributors may be used to endorse or promote products derived
14  *       from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  */
29 
30 #ifndef __MM_QCAMERA_SOCKET_H__
31 #define __MM_QCAMERA_SOCKET_H__
32 
33 // System dependencies
34 #include <arpa/inet.h>
35 
36 #undef __FD_SET
37 #define __FD_SET(fd, fdsetp) \
38   (((fd_set *)(fdsetp))->fds_bits[(fd) >> 5] |= (1LU<<((fd) & 31)))
39 
40 #undef __FD_CLR
41 #define __FD_CLR(fd, fdsetp) \
42   (((fd_set *)(fdsetp))->fds_bits[(fd) >> 5] &= ~(1LU<<((fd) & 31)))
43 
44 #undef  __FD_ISSET
45 #define __FD_ISSET(fd, fdsetp) \
46   ((((fd_set *)(fdsetp))->fds_bits[(fd) >> 5] & (1LU<<((fd) & 31))) != 0)
47 
48 #undef  __FD_ZERO
49 #define __FD_ZERO(fdsetp) \
50   (memset (fdsetp, 0, sizeof (*(fd_set *)(fdsetp))))
51 
52 #define TUNESERVER_MAX_RECV 2048
53 #define TUNESERVER_MAX(a, b)  (((a) > (b)) ? (a) : (b))
54 
55 #define TUNESERVER_GET_LIST 1014
56 #define TUNESERVER_GET_PARMS 1015
57 #define TUNESERVER_SET_PARMS 1016
58 #define TUNESERVER_MISC_CMDS 1021
59 
60 #define TUNE_PREV_GET_INFO        0x0001
61 #define TUNE_PREV_CH_CNK_SIZE     0x0002
62 #define TUNE_PREV_GET_PREV_FRAME  0x0003
63 #define TUNE_PREV_GET_JPG_SNAP    0x0004
64 #define TUNE_PREV_GET_RAW_SNAP    0x0005
65 #define TUNE_PREV_GET_RAW_PREV    0x0006
66 
67 typedef struct {
68   char data[128];
69 } tuneserver_misc_cmd;
70 
71 typedef enum {
72   TUNESERVER_RECV_COMMAND = 1,
73   TUNESERVER_RECV_PAYLOAD_SIZE,
74   TUNESERVER_RECV_PAYLOAD,
75   TUNESERVER_RECV_RESPONSE,
76   TUNESERVERER_RECV_INVALID,
77 } tuneserver_recv_cmd_t;
78 
79 typedef struct {
80   uint16_t          current_cmd;
81   tuneserver_recv_cmd_t next_recv_code;
82   uint32_t          next_recv_len;
83   void              *recv_buf;
84   uint32_t          recv_len;
85   uint32_t          send_len;
86   void              *send_buf;
87 } tuneserver_protocol_t;
88 
89 typedef enum {
90   TUNE_PREV_RECV_COMMAND = 1,
91   TUNE_PREV_RECV_NEWCNKSIZE,
92   TUNE_PREV_RECV_INVALID
93 } tune_prev_cmd_t;
94 
95 typedef struct _eztune_preview_protocol_t {
96   uint16_t         current_cmd;
97   tune_prev_cmd_t  next_recv_code;
98   uint32_t         next_recv_len;
99   int32_t          send_len;
100   char*            send_buf;
101   uint32_t         send_buf_size;
102   uint32_t         new_cnk_size;
103   uint32_t         new_cmd_available;
104 } prserver_protocol_t;
105 
106 typedef union {
107   struct sockaddr addr;
108   struct sockaddr_in addr_in;
109 } mm_qcamera_sock_addr_t;
110 
111 int eztune_server_start(void *lib_handle);
112 
113 #endif /*__MM_QCAMERA_SOCKET_H__*/
114