⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 igmpcon_snmp.c

📁 igmp for switch in vxworks
💻 C
📖 第 1 页 / 共 5 页
字号:

/************************************************************
  Copyright (C), 1988-2002, Fiberhome Tech. Co., Ltd.
  文件名: igmpcon_main.c
  作者:	aibin
  日期:	2007-12-19
  文件描述:    snmp网管接口函数
  版本:         // 版本信息
  
***********************************************************/


#include "Igmpcon.h"

BOOL type_snmp = FALSE;

char tempbuf[10000];
unsigned short t_len;
short *tlen = &t_len;
short packet_count;
char *totalbuf = NULL;
int SNMP_MAX_PACKET_LENGTH = 7680;

int port_value_set (char *buf, int len)
{
	UCHAR slot, onu, onuPort, control, vlanpeel;
	short glimit;
	UINT band;
	char *p;
	char tmpno;

	p = buf;
	tmpno = GetProfliebyName (p + 4);
	if (!tmpno)
	{
		return ERROR;
	}

	slot = *p;
	if (slot > 8)
	{
		slot -= 2;
	}
	p++;
	onu = *p;
	p++;
	onuPort = *p;
	p++;
	portstatlist[slot][onu][onuPort].control = *p;
	p++;

	portstatlist[slot][onu][onuPort].tmpno = tmpno;
	p += 20;
	portstatlist[slot][onu][onuPort].gouplimit = *(short *) p;
	p += 2;
	portstatlist[slot][onu][onuPort].bandwidth = *(int *) p;
	p += 4;
	portstatlist[slot][onu][onuPort].vlanpeer = *p;
	p += 1;
	portstatlist[slot][onu][onuPort].fast_leave_state = *p;
	p += 1;

	SendCfgPkt (portcfgmsg, slot, onu, onuPort, 0);

	SendCfgPkt (port2groupmsg, slot, onu, onuPort, 0);

	return OK;
}

void set_error_code (STRUCT_ERROR_INFO *err, char ret_code, int err_code, char *err_value)
{
	char *p;

	if(ret_code == SNMP_SUCCESS)
	{
		err->returncode = SNMP_SUCCESS;
		err->errnum = 0;
	}

	else if(ret_code == SNMP_ERROR)
	{
		if (err->errnum >= 20)
		return;
		
		err->returncode = SNMP_ERROR;
		p = (char *)err+6+60*err->errnum;
		*(short *)p = 58;
		p += 2;
		*(int *)p = err_code;
		p += 4;
		*(int *)p = 0; /*err->reserve*/
		p += 4;
		memcpy (p, err_value, 50);
	
		/*
		err->errarray[err->errnum].length = 58;
		err->errarray[err->errnum].reserved = 0;
		err->errarray[err->errnum].code = err_code;
		memcpy (err->errarray[err->errnum].para, err_value, 49);*/
		err->errnum++;
	}
}

int port_value_get (UCHAR inter_slot, UCHAR onu, UCHAR onuPort, char *buf,
	unsigned short *len)
{
	UCHAR control, vlanpeel;
	short glimit;
	UINT band;
	char *p;
	char tmpno;

/*	SendCfgPkt (portcfgquerymsg, inter_slot, onu, onuPort, 0);
	taskDelay (30);
	*/	
	
	p = buf;

	*p = translateslot_out(inter_slot);
	p++;
	*p = onu;
	p++;
	*p = onuPort;
	p++;
	*p = portstatlist[inter_slot][onu][onuPort].control;
	p++;

	tmpno = portstatlist[inter_slot][onu][onuPort].tmpno;
	printf ("tmpno =%d, name=%s\r\n", tmpno, profile[tmpno].name);
	memcpy (p, profile[tmpno].name, 20);
	printf ("name=%s\r\n", p);
	p += 20;
	*(short *) p = portstatlist[inter_slot][onu][onuPort].gouplimit;
	p += 2;
	*(int *) p = portstatlist[inter_slot][onu][onuPort].bandwidth;
	p += 4;
	*p = portstatlist[inter_slot][onu][onuPort].vlanpeer;
	p++;
	*p = portstatlist[inter_slot][onu][onuPort].fast_leave_state;
	p++;
	*len = p - buf;
	return OK;
}


/*增加分包的功能*/
int port_value_set_new(int index, char *buf, int len, STRUCT_ERROR_INFO *err)
{
	int total_len = 0;
	int count = 0;
	char *p;
	char reval = 0;
	STRUCT_ERROR_INFO *success;

	p = buf;
	total_len = NULL;
		
	/*第一个包要分配空间*/
	if (index == 1)
	{
		set_error_code(err, SNMP_SUCCESS, 0,0);
		/*only one snmp-packet*/
		if (len < SNMP_MAX_PACKET_LENGTH)
		{
			clear_port_config ();
			reval = port_set_config_all (buf, len, err);
			return reval;
		}

		/*the first snmp-packet*/
		else if (len == SNMP_MAX_PACKET_LENGTH)
		{
			count = *(short *)p;
			totalbuf = (char *)malloc (31*count + 2);
			if (NULL == totalbuf)
			{
				set_error_code(err, SNMP_ERROR, 0x002efffe,0);
				return 0;
			}
			
			memset (totalbuf, 0, 31*count+2);
			memcpy (totalbuf, buf, SNMP_MAX_PACKET_LENGTH);
			return 0;
		}
		else
		{
			return 0;
		}
	}

	/*the middle packet*/
	else if (len == SNMP_MAX_PACKET_LENGTH)
	{
		memcpy (totalbuf+(index-1)*SNMP_MAX_PACKET_LENGTH, buf, SNMP_MAX_PACKET_LENGTH);
		return 0;
	}

	/*the last packet*/
	else
	{
		memcpy (totalbuf+(index-1)*SNMP_MAX_PACKET_LENGTH, buf, len);
		clear_port_config ();
		reval = port_set_config_all (totalbuf, len+(index-1)*SNMP_MAX_PACKET_LENGTH, err);
		free (totalbuf);
		totalbuf = NULL;
		return reval;
	}
}

/*return packet number*/
int port_value_get_new(void)
{
	int count, size;
	int i, j, k;
	char start, end;
	char *p;
	char temp[100];
	unsigned short len =0;

	count = 0;
	PASS_ONU(i, j)
	{
		if (onulist[i][j].used)
		{
			if (onulist[i][j].flag_ftth)
			{
				start = onulist[i][j].igmp_port;
				end =start;
			}
			else
			{
				start = 1;
				end = onulist[i][j].total_port;
			}
			for (k = start; k <= end; ++k)
			{
				if (!is_port_default_config(i,j,k))
				count++;
			}
		}
	}
	END_PASS_ONU
		
	size = 32*count +6;	
	t_len = size;
	/*need to split packet upload, if size more than 7680 then malloc a space*/
	if (size > SNMP_MAX_PACKET_LENGTH)
	{
		totalbuf = (char *)malloc (size);
		if (NULL == totalbuf)
		return -1;
		memset (totalbuf, 0, size);
		p = totalbuf;
	}
	else
	{
		memset (tempbuf, 0, sizeof (tempbuf));
		p = tempbuf;
	}

	*(int *)p = SNMP_SUCCESS;
	p += 4;
	*(short *)p = count;
	p += 2;

	PASS_ONU(i, j)
	{
		if (onulist[i][j].used)
		{
			if (onulist[i][j].flag_ftth)
			{
				start = onulist[i][j].igmp_port;
				end =start;
			}
			else
			{
				start = 1;
				end = onulist[i][j].total_port;
			}
			for (k = start; k <= end; ++k)
			{
				if (!is_port_default_config(i,j,k))
				{
					memset (temp, 0, sizeof (temp));
					port_value_get(i, j, k, temp, &len);
					memcpy (p,temp, len);
					p = p + len;
				}
			}
		}
	}
	END_PASS_ONU

	if (type_snmp)
	typePkt(tempbuf, size);
	return (size/SNMP_MAX_PACKET_LENGTH) +1;
}

/*return total size*/
int port_value_get_size(void)
{
	int count, size, len;
	int i, j, k;
	char start, end;
	char *p;
	char temp[50];

	count = 0;
	PASS_ONU(i, j)
	{
		if (onulist[i][j].used)
		{
			if (onulist[i][j].flag_ftth)
			{
				start = onulist[i][j].igmp_port;
				end =start;
			}
			else
			{
				start = 1;
				end = onulist[i][j].total_port;
			}
			for (k = start; k <= end; ++k)
			{
				if (!is_port_default_config(i,j,k))
				count++;
			}
		}
	}
	END_PASS_ONU
		
	size = 32*count +2;	
	return size;
}



/*增加分包的功能*/
int igmp_profile_set_new(int index, char *buf, int len, STRUCT_ERROR_INFO *err)
{
	int total_len = 0;
	int count = 0;
	char *p;
	char reval = 0;
	STRUCT_ERROR_INFO *success;
	int size =0;

	p = buf;
	total_len = NULL;

	/*第一个包要分配空间*/
	if (index == 1)
	{
		set_error_code(err, SNMP_SUCCESS, 0,0);
		/*only one snmp-packet*/
		if (len < SNMP_MAX_PACKET_LENGTH)
		{
			reval = igmp_profile_set_all (buf, len, err);
			return reval;
		}

		/*the first snmp-packet*/
		else if (len == SNMP_MAX_PACKET_LENGTH)
		{
			size  = 30000;
			totalbuf = (char *)malloc (size);
			if (NULL == totalbuf)
			{
				set_error_code(err, SNMP_ERROR, 0x002efffe,0);
				return 0;
			}
			
			memset (totalbuf, 0, size);
			memcpy (totalbuf, buf, SNMP_MAX_PACKET_LENGTH);
			return 0;
		}
		else
		{
			return 0;
		}
	}

	/*the middle packet*/
	else if (len == SNMP_MAX_PACKET_LENGTH)
	{
		memcpy (totalbuf+(index-1)*SNMP_MAX_PACKET_LENGTH, buf, SNMP_MAX_PACKET_LENGTH);
		err->returncode = 1;
		err->errnum = 0;
		return 0;
	}

	/*the last packet*/
	else
	{
		memcpy (totalbuf+(index-1)*SNMP_MAX_PACKET_LENGTH, buf, len);
		reval = igmp_profile_set_all (totalbuf, len+(index-1)*SNMP_MAX_PACKET_LENGTH, err);
		free (totalbuf);
		totalbuf = NULL;
		return reval;
	}
}

/*return the packet number*/
int igmp_profile_get_new(void)
{
	GroupAuth *ptmp;
	char  *p_count, *g_count, *p;
	short profilecount= 0, groupcount= 0;
	int i, tmpno;
	int size = 0;

	size = 2;
	for (i = 1; i <= MaxTemp; i++)
	{
		if (profile[i].used)
		{
			groupcount = 0;
			ptmp = authlist;
			while (ptmp)
			{
				if (ptmp->profile[i])
				groupcount++;
				ptmp = ptmp->pNext;
			}
			size += 21+groupcount*5;
			profilecount++;
		}
	}
	size += 4; /*success head*/
	
	/*need to split packet upload, if size more than 7680 then malloc a space*/
	if (size > SNMP_MAX_PACKET_LENGTH)
	{
		totalbuf = (char *)malloc (size);
		if (NULL == totalbuf)
		return -1;
		memset (totalbuf, 0, size);
		p = totalbuf;
	}
	else
	{
		memset (tempbuf, 0, sizeof (tempbuf));
		p = tempbuf;
	}

	*(int *)p = SNMP_SUCCESS;
	p += 4;
	*(short *)p = profilecount;
	p += 2;

	for (i = 1; i <= MaxTemp; i++)
	{
		if (profile[i].used)
		{
			strcpy (p, profile[i].name);
			p += 20;
			g_count = p;
			p++;
			ptmp = authlist;
			groupcount = 0;
			while (ptmp)
			{
				if (ptmp->profile[i])
				{
					groupcount++;
					*(unsigned int *)p = ptmp->groupaddress;
					p += 4;
					*p = ptmp->profile[i];
					p++;
				}
				ptmp = ptmp->pNext;
			}
			*g_count = groupcount;
		}
	}

	t_len = size;

	if (size%SNMP_MAX_PACKET_LENGTH)
	return size/SNMP_MAX_PACKET_LENGTH + 1;
	else
	return size/SNMP_MAX_PACKET_LENGTH;
}

/*return the total size*/
int igmp_profile_get_size(void)
{
	GroupAuth *ptmp;
	char  *p_count, *g_count, *p;
	short profilecount= 0, groupcount= 0;
	int i, tmpno;
	int size = 0;

	size = 2;
	for (i = 1; i <= MaxTemp; i++)
	{
		if (profile[i].used)
		{
			groupcount = 0;
			ptmp = authlist;
			while (ptmp)
			{
				if (ptmp->profile[i])
				groupcount++;
				ptmp = ptmp->pNext;
			}
			size += 21+groupcount*5;
			profilecount++;
		}
	}
	return size;
}


int igmp_profile_set_all (char *buf, int len, STRUCT_ERROR_INFO *err)
{
	GroupAuth *backup_authlist = NULL, *ptmp, *pfind;
	ProfileData backup_profile[MaxTemp +1];
	short count;
	char *p;
	int tmpno, i, j, k, start ,end;
	int gcount;
	int ret;

	if (type_snmp)
	typePkt(buf, len);

	p = buf;
	/*create new profile spcace, but make survive profile has its origin tmpno*/ 
	memset (backup_profile, 0, sizeof (backup_profile));
	count = *(short *)buf;
	if (count > MaxTemp)
	{
		set_error_code(err, SNMP_ERROR, 0x0030fff1,  NULL); /*超过最大模板个数*/
		return -1;
	}
	
	p += 2;
	for (i = 1; i <= count; i++)
	{
		tmpno = GetProfliebyName(p);
		/*printf ("tmpno =%d, name:%s\r\n", tmpno, p);*/
		/*copy to backup*/
		if (tmpno)
		{
			strcpy (backup_profile[tmpno].name, profile[tmpno].name);
			backup_profile[tmpno].used = 1;
		}
		gcount = *(p+20);
		p = p +20+1+gcount*5;
	}

	if (0)
	{
		for (i =1; i <= MaxTemp; i++)
		{
			if (backup_profile[i].used);
		}
	}
	
	/*make backup_profile to new profile space*/
	memcpy (profile, backup_profile, sizeof(profile));

	/*dettach port from deleted profile*/
	PASS_ONU(i, j)
	{
		if (onulist[i][j].used)
		{
			
			if (onulist[i][j].flag_ftth)
			{
				start = onulist[i][j].igmp_port;
				end =start;
			}
			else
			{
				start = 1;
				end = onulist[i][j].total_port;
			}
			for (k = start; k <= end; ++k)
			{
				if (profile[portstatlist[i][j][k].tmpno].used == 0)
				portstatlist[i][j][k].tmpno =0;
			}
		}
	}
	END_PASS_ONU
		
	/*backup authlist first*/
	backup_authlist = authlist;
	authlist = NULL;
	Totalauthgroup = 0;

	/*add new-named profle to new profle space*/
	p = buf+2;
	for (i = 1; i <= count; i++)
	{
		tmpno = GetProfliebyName(p);
		/*new-named profile*/
		if (!tmpno)
		{
			ret = createProfilebyName(p);
			/*printf("ret =%d\r\n", ret);*/
			if (ret<0)
			{
				set_error_code(err, SNMP_ERROR, 0x0030fffd,  NULL);
				p = p+20+1+(*(p+20))*5;
				continue;
			}
			else
			{
				tmpno = ret;
			}
		}
		/*printf ("profile[%d]:%s\r\n",tmpno, profile[i].name);
		typePkt(profile[i].name, 20);*/

		/*add group to authilist*/
		p += 20;
		gcount = *p;
		p++;
		for (j = 1; j <= gcount; j++)
		{
			if (ERROR ==addGroup2Profile(tmpno, *(int *)p, *(p+4)) )
			{
				set_error_code(err, SNMP_ERROR, 0x0030fffc,  NULL);
			}
			p += 5;
		}
	}

	if (0)
	{
		for (i =1; i <= MaxTemp; i++)
		{
			if (profile[i].used)
			printf ("profile[%d]:%s\r\n",i, profile[i].name);
		}
	}
	
	/*compare new authlist to backup, if have same group, copy parameter from old to new*/
	ptmp = backup_authlist;
	while (ptmp)
	{
		pfind = (GroupAuth *)GetAuthGroup(ptmp->groupaddress);
		if (pfind != NULL)
		{
			pfind->active = ptmp->active;
			pfind->bandwidth = ptmp->bandwidth;
			pfind->leavedelay = ptmp->leavedelay;
			pfind->preCount = ptmp->preCount;
			pfind->preInterval = ptmp->preInterval;
			pfind->preReset = ptmp->preReset;
			pfind->preTime = ptmp->preTime;
			pfind->pretotaltime = ptmp->pretotaltime;
			pfind->vlanid = ptmp->vlanid;
			pfind->uplink_vlan = ptmp->uplink_vlan;
		}
		ptmp = ptmp->pNext;
	}
	/*free the backup_authlist*/
	ptmp = backup_authlist;
	while (ptmp)
	{
		pfind = ptmp;
		ptmp = ptmp->pNext;
		free (pfind);
		pfind = NULL;
	}
	
	/*inform ec2*/
	for (i = 1; i <=MAX_DOWN_SLOT; i++)
	SendAuth2Slot(i);

	return 0;
}

int igmp_profile_create (char *buf, int len, STRUCT_ERROR_INFO *err)
{
	UCHAR state, pretime, preinteral, precount, prereset, pretotal,
		leavedelay;
	USHORT band, vlanid;
	UINT groupaddress, group[MaxtTempGroup], vlan[MaxtTempGroup];
	char *p;
	GroupInfo *onlineGroup;
	int i, j, k, gcount, count, rev;
	int tmpno;
	char err_value[50], start, end;

	memset (group, 0, sizeof (group));
	memset (vlan, 0, sizeof (vlan));

	set_error_code(err, SNMP_SUCCESS, 0,0);

	if (bConDebugSnmp)
	{
		typePkt (buf, len);
	}

	if (len < 21)
	{
		return ERROR;
	}
	p = buf;
	tmpno = GetProfliebyName (p);
	p += 20;
	p++;

	gcount = *p;
	p++;
	i = 0;
	count = gcount;
	
	/*模版已经存在 */
	if (tmpno)
	{
		DelConTempGroup (tmpno);
	}
	/*不存在,创建一个 */
	else
	{
		tmpno = createProfilebyName (buf);
		if (tmpno == ERROR)
		{
			set_error_code(err, SNMP_ERROR, 0x0030fffd,  NULL);
			if (bConDebugSnmp)
			{
				printf ("createProfilebyName\r\n");
			}
			return -3;
		}
	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -