47 #define DBG(X) STB_SPDebugWrite X 52 #define IP_TASK_QUEUE_SIZE 10 53 #define IP_TASK_STACK 1024 54 #define IP_TASK_PRIO 10 55 #define IP_TASK_TIMEOUT 30000 56 #define IP_TASK_PERIOD 1000 67 E_IPTASK_COMMAND command;
77 static void ConnectByStaticIP(
void);
78 static void ConnectByDhcp(BOOLEAN wait_for_completion);
79 static void StartIpTask(E_IPTASK_COMMAND command, BOOLEAN wait_for_completion);
80 static void IpTask(
void *param);
95 E_STB_IP_MODE ip_mode;
97 U8BIT *essid_password;
103 net_if = (E_NET_IF_TYPE)
APP_NvmRead(NET_IF_TYPE_NVM);
104 if (net_if != NET_IF_NONE)
106 if (net_if == NET_IF_WIRELESS)
124 ip_mode = (E_STB_IP_MODE)
APP_NvmRead(IP_MODE_NVM);
125 if (ip_mode == IP_STATIC)
134 StartIpTask(cmd, wait_for_completion);
141 static void ConnectByStaticIP(
void)
144 U8BIT subnet_mask[4];
147 U32BIT ip_address_32;
148 U32BIT subnet_mask_32;
152 FUNCTION_START(ConnectByStaticIP);
160 ip_address[0] = (ip_address_32 & 0xFF000000) >> 24;
161 ip_address[1] = (ip_address_32 & 0x00FF0000) >> 16;
162 ip_address[2] = (ip_address_32 & 0x0000FF00) >> 8;
163 ip_address[3] = (ip_address_32 & 0x000000FF);
165 subnet_mask[0] = (subnet_mask_32 & 0xFF000000) >> 24;
166 subnet_mask[1] = (subnet_mask_32 & 0x00FF0000) >> 16;
167 subnet_mask[2] = (subnet_mask_32 & 0x0000FF00) >> 8;
168 subnet_mask[3] = (subnet_mask_32 & 0x000000FF);
170 gateway[0] = (gateway_32 & 0xFF000000) >> 24;
171 gateway[1] = (gateway_32 & 0x00FF0000) >> 16;
172 gateway[2] = (gateway_32 & 0x0000FF00) >> 8;
173 gateway[3] = (gateway_32 & 0x000000FF);
175 dns[0] = (dns_32 & 0xFF000000) >> 24;
176 dns[1] = (dns_32 & 0x00FF0000) >> 16;
177 dns[2] = (dns_32 & 0x0000FF00) >> 8;
178 dns[3] = (dns_32 & 0x000000FF);
185 FUNCTION_FINISH(ConnectByStaticIP);
188 static void ConnectByDhcp(BOOLEAN wait_for_completion)
190 FUNCTION_START(ConnectByDhcp);
192 FUNCTION_FINISH(ConnectByDhcp);
202 static void IpTask(
void *param)
206 E_IPTASK_COMMAND cmd;
208 E_NW_LINK_STATUS status;
210 FUNCTION_START(IpTask);
221 if (status == NW_LINK_ACTIVE)
228 if (semaphore == NULL)
237 if (semaphore != NULL)
254 DBG((
"%s: Could not execute command because link is not after afer %d ms", __FUNCTION__, IP_TASK_TIMEOUT));
260 FUNCTION_FINISH(IpTask);
269 static void StartIpTask(E_IPTASK_COMMAND command, BOOLEAN wait_for_completion)
272 void *semaphore = NULL;
274 FUNCTION_START(StartIpTask);
279 if (wait_for_completion)
282 params->semaphore = semaphore;
286 params->semaphore = NULL;
288 params->command = command;
290 STB_OSCreateTask(IpTask, (
void *)params, IP_TASK_STACK, IP_TASK_PRIO, (U8BIT *)
"IpTask");
292 if (wait_for_completion)
295 DBG((
"%s: command=%s wait_for_completion=TRUE. Completed", __FUNCTION__,
296 (command == IPTASK_DHCP) ?
"DHCP" :
"Static"));
303 DBG((
"%s: failed allocating memory", __FUNCTION__));
307 FUNCTION_FINISH(StartIpTask);
void STB_IPGetIPByDhcp(BOOLEAN wait_for_completion)
Cause the IP address to be set using DHCP.
void AIP_ConnectToNetwork(BOOLEAN wait_for_completion)
Connect to network based on IP_MODE from NVM e.g. restore from IP NVM and connect to network...
BOOLEAN STB_NWSelectInterface(E_NW_INTERFACE iface)
Sets the network interface that will be used for all network or IP operations.
U32BIT STB_OSGetClockDiff(U32BIT timestamp)
Get Difference between Given Time and Current Time.
Header file for NVM data handling functions.
void * STB_AppGetMemory(U32BIT bytes)
Attempts to allocate memory from the application heap.
void STB_OSSemaphoreSignal(void *semaphore)
Signal a Semaphore to Release it by decrementing its counter.
void * STB_OSCreateCountSemaphore(U32BIT value)
Create a counting semaphore.
U32BIT APP_NvmRead(E_NVM_ITEMS nvm_item)
Returns the current value for the given DVB setting.
E_NW_LINK_STATUS STB_NWGetLinkStatus(void)
Get the selected interface link status.
void STB_OSDeleteSemaphore(void *semaphore)
Delete a Semaphore.
void STB_OSSemaphoreWait(void *semaphore)
Wait on Semaphore Indefinity or Until Released.
Debug functions header file.
U8BIT * APP_NvmReadString(E_NVM_ITEMS nvm_item)
Returns pointer to current string for the given DVB setting.
Contains the initialise functions for IP.
void STB_IPSetIPAddress(const U8BIT *ip_addr)
Sets the IPv4 format IP address of default network connection.
void STB_IPSetGatewayIPAddress(const U8BIT *gateway_addr)
Sets the IPv4 format gateway IP address.
Header file - Function prototypes for operating system.
System Wide Global Technical Data Type Definitions.
void STB_IPSetDnsServerIPAddress(const U8BIT *dns_addr)
Sets the IPv4 format DNS server IP address.
void STB_AppFreeMemory(void *addr)
Releases previously allocated application heap memory.
void STB_IPSetSubnetMask(const U8BIT *subnet_mask)
Sets the IPv4 format subnet mask of default network connection.
void * STB_OSCreateTask(void(*function)(void *), void *param, U32BIT stack, U8BIT priority, U8BIT *name)
Create a New Task to the calling process. Upon success, the created task runs on its own stack...
Header file - Function prototypes for heap memory.
macros and function prototypes for public use
void STB_OSTaskDelay(U16BIT timeout)
Delay Task for Specifed Time Period.
U32BIT STB_OSGetClockMilliseconds(void)
Get Current Computer Clock Time.
BOOLEAN STB_NWConnectToAccessPoint(U8BIT *essid, U8BIT *password)
Attempts to connect to the wireless network with the given SSID. If the network is open then 'passwor...