00001 /* ----------------------------------------------------------------------------- 00002 * connections.h 00003 * 00004 * iPDC - Phasor Data Concentrator 00005 * 00006 * Copyright (C) 2011 Nitesh Pandit 00007 * Copyright (C) 2011 Kedar V. Khandeparkar 00008 * 00009 * This program is free software; you can redistribute it and/or 00010 * modify it under the terms of the GNU General Public License 00011 * as published by the Free Software Foundation; either version 2 00012 * of the License, or (at your option) any later version. 00013 * 00014 * This program is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 * GNU General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU General Public License 00020 * along with this program; if not, write to the Free Software 00021 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00022 * 00023 * Authors: 00024 * Kedar V. Khandeparkar <kedar.khandeparkar@gmail.com> 00025 * Nitesh Pandit <panditnitesh@gmail.com> 00026 * 00027 * ----------------------------------------------------------------------------- */ 00028 00029 00030 #include <netinet/in.h> 00031 #include <signal.h> 00032 00033 /* ---------------------------------------------------------------- */ 00034 /* global variable */ 00035 /* ---------------------------------------------------------------- */ 00036 00037 #define DBPORT 9000 // the port users will be connecting to 00038 #define BACKLOG 10 // how many pending connections queue will hold 00039 #define MAXBUFLEN 2000 00040 00041 int UL_UDP_addr_len,UL_TCP_sin_size, numbytes; 00042 unsigned char UL_udp_command[19]; 00043 unsigned char UL_tcp_command[19]; 00044 00045 struct sigaction sa; 00046 00047 struct Lower_Layer_Details { 00048 00049 unsigned int pmuid; 00050 char ip[16]; 00051 int port; 00052 char protocol[4]; 00053 int sockfd; 00054 int up; //used only in tcp 00055 struct sockaddr_in llpmu_addr; 00056 pthread_t thread_id; 00057 int data_transmission_off; 00058 int pmu_remove; 00059 int request_cfg_frame; 00060 struct Lower_Layer_Details *next; 00061 struct Lower_Layer_Details *prev; 00062 00063 }*LLfirst,*LLlast; 00064 00065 00066 struct Upper_Layer_Details { 00067 00068 char ip[16]; 00069 int port; 00070 char protocol[4]; 00071 int sockfd; 00072 int tcpup; 00073 pthread_t thread_id; 00074 struct sockaddr_in pdc_addr; 00075 int config_change; 00076 int UL_upper_pdc_cfgsent; 00077 int UL_data_transmission_off; 00078 int address_set; 00079 struct Upper_Layer_Details *next; 00080 struct Upper_Layer_Details *prev; 00081 00082 }*ULfirst,*ULlast; 00083 00084 00085 /* ---------------------------------------------------------------- */ 00086 /* Function prototypes */ 00087 /* ---------------------------------------------------------------- */ 00088 00089 void sigchld_handler(int s); 00090 00091 void setup(); 00092 00093 void* UL_tcp(); 00094 00095 void* UL_tcp_connection(void * newfd); 00096 00097 void* UL_udp(); 00098 00099 void PMU_process_UDP(unsigned char *,struct sockaddr_in,int sockfd); 00100 00101 void PMU_process_TCP(unsigned char tcp_buffer[],int sockfd);