📄 dnsr_db.c.svn-base
字号:
/***************************************************************************************
* Copyright c 2000 D-Link Corporation All rights reserved.
*
* This is unpublished proprietary source code of D-Link Corporation
*
* The copyright notice above does not evidence any actual or intended
* publication of such source code.
***************************************************************************************
*/
/* INCLUDE FILE DECARATIONS */
#include <l3/ap/dnsr/h/dnsr_db.h>
#include <app/save/inc/sv_sec.h>
#include <string.h>
/* GLOBAL VARIABLE DECLARATIONS */
static DNSR_DB_T *dnsr_info = NULL;
static DNSR_DB_T dnsr_database ;
static void* DnsrDbSemaphore;
#define DNSR_DB_LOCK() (OS_Semaphore_Lock(DnsrDbSemaphore))
#define DNSR_DB_UNLOCK() (OS_Semaphore_Unlock(DnsrDbSemaphore))
/* LOCAL SUBPROGRAM DECLARATION */
/*
*-----------------------------------------------------------------------------------------------------
* void DNSR_DB_Factory_Default (void)
* Purpose: This function resets the boot information in EEPROM to factory
* default values.
* Params:
* Input: None
* Output: None
* Returns: None
* Notes: None
*-----------------------------------------------------------------------------------------------------
*/
static void DNSR_DB_Factory_Default (void *ptr)
{
/* BODY */
DNSR_DB_T *db_tmp;
if (ptr == NULL) return ;
DBG_L3_Printf("Reset DNSR: DNSR_DB_Factory_Default ...\n");
/* BODY */
db_tmp = (DNSR_DB_T*)ptr;
DNSR_DB_LOCK();
memset(db_tmp, 0, sizeof(DNSR_DB_T));
DNSR_DB_UNLOCK();
} /* End of DNSR_DB_Factory_Default() */
/*----------------------------------------------------------------------------
* Purpose: This funtion get device information from NV-RAM.
* Parameters:
* Input: None.
* Output: None.
* Return: eeprom section address.
*----------------------------------------------------------------------------
*/
void DNSR_DB_Init(void)
{
memset(&dnsr_database, 0x0, sizeof(DNSR_DB_T));
DnsrDbSemaphore = OS_Semaphore_Create(BINARY_SEMAPHORE,1,"dnsr");
while (DnsrDbSemaphore == NULL)
OS_Fatal_Error_Handler("DnsrDbSemaphore");
dnsr_info = &dnsr_database;
DNSR_DB_Factory_Default(dnsr_info);
return;
}
/*
*-----------------------------------------------------------------------------------------------------
* BOOLEAN_T DNSR_DB_Get_Static_Table_Entry(DNSR_DB_Static_Table_T *st, UI8_T index)
* Purpose: This function gets the value of specific type of an entry in the static
* table from EEPROM.
* Params:
* Input: index Index of an entry in static table.
* Output: st The structure of static table with the value of specific type.
* Returns: BOOLEAN_T
* Notes: None
*-----------------------------------------------------------------------------------------------------
*/
BOOLEAN_T DNSR_DB_Get_Static_Table_Entry(DNSR_DB_Static_Table_T *st,
UI8_T index)
{
if (dnsr_info == NULL) return FALSE;
/* BODY */
if (index >= MAX_STATIC_DNS_NUM)
return FALSE;
st->host_ip = dnsr_info->global.static_table[index].host_ip;
if (st->host_ip == 0)
return FALSE;
memcpy(st->host_name, dnsr_info->global.static_table[index].host_name,sizeof(dnsr_info->global.static_table[index].host_name));
st->status = dnsr_info->global.static_table[index].status;
return TRUE;
} /* End of DNSR_DB_Get_Static_Table_Entry() */
/*
*-----------------------------------------------------------------------------------------------------
* BOOLEAN_T DNSR_DB_Set_Static_Table_Entry(DNSR_DB_Static_Table_T *st, UI8_T index)
* Purpose: This function sets the value of specific type of an entry in the static
* table and saves into EEPROM.
* Params:
* Input: type Type of an entry in static table, including IP, domain name, entry status.
* Input: st The structure of static table with the value of specific type.
* Input: index Index of an entry in static table.
* Returns: BOOLEAN_T
* Notes: None
*-----------------------------------------------------------------------------------------------------
*/
BOOLEAN_T DNSR_DB_Set_Static_Table_Entry(DNSR_DB_Static_Table_T *st,
UI8_T index)
{
/* BODY */
if (dnsr_info == NULL) return FALSE;
if (index >= MAX_STATIC_DNS_NUM)
return FALSE;
dnsr_info->global.static_table[index].host_ip = st->host_ip;
memcpy(dnsr_info->global.static_table[index].host_name, st->host_name , sizeof(st->host_name));
dnsr_info->global.static_table[index].status = st->status;
DNSR_DB_StaticTable_Update_Item(index);
return TRUE;
} /* End of DNSR_DB_Set_Static_Table_Entry() */
/*
*-----------------------------------------------------------------------------------------------------
* BOOLEAN_T DNSR_DB_Get_Name_Server_IP(UI32_T *ptr, UI8_T index)
* Purpose: This function gets one of name server's IP from EEPROM.
* Params:
* Input: index Index of an entry in name server table.
* Output: ptr IP adderss.
* Returns: BOOLEAN_T
* Notes: None
*-----------------------------------------------------------------------------------------------------
*/
BOOLEAN_T DNSR_DB_Get_Name_Server_IP(UI32_T *ptr, UI8_T index)
{
/* BODY */
if (dnsr_info == NULL) return FALSE;
if (index < MAX_NAME_SERVER)
{
*ptr = dnsr_info->global.server_addr[index];
return TRUE;
}
return FALSE;
} /* End of DNSR_DB_Get_Name_Server_IP() */
/*
*-----------------------------------------------------------------------------------------------------
* BOOLEAN_T DNSR_DB_Set_Name_Server_IP(UI32_T addr, UI8_T index)
* Purpose: This function sets one of name server's IP and saves into EEPROM.
* Params:
* Input: addr IP adderss to be set.
* Input: index Index of an entry in name server table.
* Returns: BOOLEAN_T
* Notes: None
*-----------------------------------------------------------------------------------------------------
*/
BOOLEAN_T DNSR_DB_Set_Name_Server_IP(UI32_T addr, UI8_T index)
{
/* BODY */
if (dnsr_info == NULL) return FALSE;
if (index < MAX_NAME_SERVER)
{
dnsr_info->global.server_addr[index] = addr;
return TRUE;
}
return FALSE;
} /* End of DNSR_DB_Set_Name_Server_IP() */
/*
*-----------------------------------------------------------------------------------------------------
* BOOLEAN_T DNSR_DB_Get_Status(UI8_T *status)
* Purpose: This function gets the status of DNS Relay from EEPROM.
* Params:
* Output: status DNSR status.
* Returns: BOOLEAN_T
* Notes: None
*-----------------------------------------------------------------------------------------------------
*/
BOOLEAN_T DNSR_DB_Get_Status(UI8_T *status)
{
/* BODY */
if (dnsr_info == NULL) return FALSE;
if (status != 0)
{
*status = dnsr_info->global.dns_status;
return TRUE;
}
return FALSE;
} /* End of DNSR_DB_Get_Status() */
/*
*-----------------------------------------------------------------------------------------------------
* BOOLEAN_T DNSR_DB_Set_Status(UI8_T status)
* Purpose: This function sets the status of DNS Relay and saves into EEPROM.
* Params:
* Input: status DNSR status.
* Returns: BOOLEAN_T
* Notes: None
*-----------------------------------------------------------------------------------------------------
*/
BOOLEAN_T DNSR_DB_Set_Status(UI8_T status)
{
/* BODY */
if (dnsr_info == NULL) return FALSE;
if (status > 1)
return FALSE;
dnsr_info->global.dns_status = status;
return TRUE;
} /* End of DNSR_DB_Set_Status() */
/*
*-----------------------------------------------------------------------------------------------------
* BOOLEAN_T DNSR_DB_Get_Cache_Status(UI8_T *status)
* Purpose: This function gets the status of cache lookup from EEPROM.
* Params:
* Output: status Cache lookup status.
* Returns: BOOLEAN_T
* Notes: None
*-----------------------------------------------------------------------------------------------------
*/
BOOLEAN_T DNSR_DB_Get_Cache_Status(UI8_T *status)
{
/* BODY */
if (dnsr_info == NULL) return FALSE;
if (status != 0)
{
*status = dnsr_info->global.cache_status;
return TRUE;
}
return FALSE;
} /* End of DNSR_DB_Get_Cache_Status() */
/*
*-----------------------------------------------------------------------------------------------------
* BOOLEAN_T DNSR_DB_Set_Cache_Status(UI8_T status)
* Purpose: This function sets the status of cache lookup and saves into EEPROM.
* Params:
* Input: status Cache lookup status.
* Returns: BOOLEAN_T
* Notes: None
*-----------------------------------------------------------------------------------------------------
*/
BOOLEAN_T DNSR_DB_Set_Cache_Status(UI8_T status)
{
/* BODY */
if (dnsr_info == NULL) return FALSE;
if (status > 1)
return FALSE;
dnsr_info->global.cache_status = status;
return TRUE;
} /* End of DNSR_DB_Set_Cache_Status() */
/*
*-----------------------------------------------------------------------------------------------------
* BOOLEAN_T DNSR_DB_Get_Lookup_Status(UI8_T *status)
* Purpose: This function gets the status of static table lookup from EEPROM.
* Params:
* Output: status Static table lookup status.
* Returns: BOOLEAN_T
* Notes: None
*-----------------------------------------------------------------------------------------------------
*/
BOOLEAN_T DNSR_DB_Get_Lookup_Status(UI8_T *status)
{
/* BODY */
if (dnsr_info == NULL) return FALSE;
if (status != 0)
{
*status = dnsr_info->global.lookup_status;
return TRUE;
}
return FALSE;
} /* End of DNSR_DB_Get_Lookup_Status() */
/*
*-----------------------------------------------------------------------------------------------------
* BOOLEAN_T DNSR_DB_Set_Lookup_Status(UI8_T status)
* Purpose: This function sets the status of static table lookup and saves into EEPROM.
* Params:
* Input: status Static table lookup status.
* Returns: BOOLEAN_T
* Notes: None
*-----------------------------------------------------------------------------------------------------
*/
BOOLEAN_T DNSR_DB_Set_Lookup_Status(UI8_T status)
{
/* BODY */
if (dnsr_info == NULL) return FALSE;
if (status > 1)
return FALSE;
dnsr_info->global.lookup_status = status;
return TRUE;
} /* End of DNSR_DB_Set_Lookup_Status() */
/*-----------------------------------------------------------------------------------------------------
* BOOLEAN_T DNSR_DB_StaticTable_Update_Item (UI8_T index)
* Purpose: This function update the total of static table and saves into EEPROM.
* Params:
* Input: UI8_T index
* Returns: BOOLEAN_T
* Notes: None
*-----------------------------------------------------------------------------------------------------
*/
BOOLEAN_T DNSR_DB_StaticTable_Update_Item (UI8_T index)
{
UI8_T i , j=index , k;
UI32_T temp_host_ip;
UI8_T temp_host_name[255];
BOOLEAN_T temp_status;
if (dnsr_info->global.static_table[index].host_ip == 0) /* the entry is deleted */
{
if (index == MAX_STATIC_DNS_NUM-1)
return TRUE;
j++;
if (dnsr_info->global.static_table[j].host_ip == 0) /* the next entry is zero */
return TRUE;
for (i =index; i<MAX_STATIC_DNS_NUM-1 ; i++)
{
dnsr_info->global.static_table[i].host_ip = dnsr_info->global.static_table[j].host_ip;
memcpy(dnsr_info->global.static_table[i].host_name, dnsr_info->global.static_table[j].host_name,sizeof(dnsr_info->global.static_table[j].host_name));
dnsr_info->global.static_table[i].status = dnsr_info->global.static_table[j].status;
if (dnsr_info->global.static_table[j].host_ip == 0) /* the next entry is zero */
break;
j++;
}
dnsr_info->global.static_table[i].host_ip =0;
dnsr_info->global.static_table[i].status = FALSE;
}
else /* sort the added entry */
{
for (i =0; i<MAX_STATIC_DNS_NUM-1 ; i++)
{
if (dnsr_info->global.static_table[i].host_ip == 0) break;/* the entry is zero */
k=i;
k++;
for (j=k; j< MAX_STATIC_DNS_NUM;j++)
{
if (dnsr_info->global.static_table[j].host_ip == 0) break;/* the next entry is zero */
if (dnsr_info->global.static_table[j].host_ip < dnsr_info->global.static_table[i].host_ip)
{
temp_host_ip = dnsr_info->global.static_table[i].host_ip;
memcpy(temp_host_name, dnsr_info->global.static_table[i].host_name,sizeof(dnsr_info->global.static_table[i].host_name));
temp_status = dnsr_info->global.static_table[i].status;
dnsr_info->global.static_table[i].host_ip = dnsr_info->global.static_table[j].host_ip;
memcpy(dnsr_info->global.static_table[i].host_name, dnsr_info->global.static_table[j].host_name,sizeof(dnsr_info->global.static_table[j].host_name));
dnsr_info->global.static_table[i].status = dnsr_info->global.static_table[j].status;
dnsr_info->global.static_table[j].host_ip = temp_host_ip;
memcpy(dnsr_info->global.static_table[j].host_name, temp_host_name,sizeof(temp_host_name));
dnsr_info->global.static_table[j].status = temp_status;
}
}
}
}
return TRUE;
}/*End of DNSR_DB_StaticTable_Update_Item*/
/* End of DNS Relay EPM package */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -