OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [uclinux/] [userland/] [route/] [lib/] [rose.c] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 745 simons
/*
2
 * lib/rose.c This file contains an implementation of the "ROSE"
3
 *              support functions for the NET-2 base distribution.
4
 *
5
 * Version:     $Id: rose.c,v 1.1 2002-03-17 19:58:53 simons Exp $
6
 *
7
 * Author:      Terry Dawson, VK2KTJ, <terry@perf.no.itg.telstra.com.au>
8
 *              based on ax25.c by:
9
 *              Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
10
 *              Copyright 1993 MicroWalt Corporation
11
 *
12
 *              This program is free software; you can redistribute it
13
 *              and/or  modify it under  the terms of  the GNU General
14
 *              Public  License as  published  by  the  Free  Software
15
 *              Foundation;  either  version 2 of the License, or  (at
16
 *              your option) any later version.
17
 */
18
#include "config.h"
19
 
20
#if HAVE_AFROSE || HAVE_HWROSE
21
#include <features.h>
22
#include <sys/types.h>
23
#include <sys/ioctl.h>
24
#include <sys/socket.h>
25
#include <net/if_arp.h>         /* ARPHRD_ROSE */
26
#include <stdlib.h>
27
#include <stdio.h>
28
#include <ctype.h>
29
#include <errno.h>
30
#include <fcntl.h>
31
#include <string.h>
32
#include <termios.h>
33
#include <unistd.h>
34
#include "net-support.h"
35
#include "pathnames.h"
36
#include "intl.h"
37
 
38
#ifndef _NETROSE_ROSE_H
39
#include <linux/ax25.h>
40
#include <linux/rose.h>
41
/* this will check for the broken #define PF_ROSE AF_ROSE define in some older kernel headers */
42
#undef AF_ROSE
43
#if PF_ROSE == AF_ROSE
44
#warning "Your <linux/rose.h> is broken and defines PF_ROSE, better remove the define in /usr/include/linux/rose.h (using private define for PF_ROSE meanwhile)"
45
#undef PF_ROSE
46
#define PF_ROSE         11      /* Amateur Radio X.25 PLP       */
47
#endif
48
/* now restore the value of AF_ROSE (which had to be deleted to catch the case where #define AF_ROSE PF_ROSE) */
49
#define AF_ROSE         PF_ROSE
50
#endif
51
 
52
static char ROSE_errmsg[128];
53
 
54
extern struct aftype rose_aftype;
55
 
56
static char *
57
 ROSE_print(unsigned char *ptr)
58
{
59
    static char buff[12];
60
 
61
    snprintf(buff, sizeof(buff), "%02x%02x%02x%02x%02x", ptr[0], ptr[1], ptr[2], ptr[3], ptr[4]);
62
    buff[10] = '\0';
63
    return (buff);
64
}
65
 
66
/* Display a ROSE socket address. */
67
static char *
68
 ROSE_sprint(struct sockaddr *sap, int numeric)
69
{
70
    if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
71
        return _("[NONE SET]");
72
 
73
    return (ROSE_print(((struct sockaddr_rose *) sap)->srose_addr.rose_addr));
74
}
75
 
76
 
77
static int ROSE_input(int type, char *bufp, struct sockaddr *sap)
78
{
79
    char *ptr;
80
    int i, o;
81
 
82
    sap->sa_family = rose_aftype.af;
83
    ptr = ((struct sockaddr_rose *) sap)->srose_addr.rose_addr;
84
 
85
    /* Node address the correct length ? */
86
    if (strlen(bufp) != 10) {
87
        strcpy(ROSE_errmsg, _("Node address must be ten digits"));
88
#ifdef DEBUG
89
        fprintf(stderr, "rose_input(%s): %s !\n", ROSE_errmsg, orig);
90
#endif
91
        errno = EINVAL;
92
        return (-1);
93
    }
94
    /* Ok, lets set it */
95
    for (i = 0, o = 0; i < 5; i++) {
96
        o = i * 2;
97
        ptr[i] = (((bufp[o] - '0') << 4) | (bufp[o + 1] - '0'));
98
    }
99
 
100
    /* All done. */
101
#ifdef DEBUG
102
    fprintf(stderr, "rose_input(%s): ", orig);
103
    for (i = 0; i < sizeof(rose_address); i++)
104
        fprintf(stderr, "%02X ", sap->sa_data[i] & 0377);
105
    fprintf(stderr, "\n");
106
#endif
107
 
108
    return (0);
109
}
110
 
111
 
112
/* Display an error message. */
113
static void ROSE_herror(char *text)
114
{
115
    if (text == NULL)
116
        fprintf(stderr, "%s\n", ROSE_errmsg);
117
    else
118
        fprintf(stderr, "%s: %s\n", text, ROSE_errmsg);
119
}
120
 
121
 
122
static char *
123
 ROSE_hprint(struct sockaddr *sap)
124
{
125
    if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
126
        return _("[NONE SET]");
127
 
128
    return (ROSE_print(((struct sockaddr_rose *) sap)->srose_addr.rose_addr));
129
}
130
 
131
 
132
static int ROSE_hinput(char *bufp, struct sockaddr *sap)
133
{
134
    if (ROSE_input(0, bufp, sap) < 0)
135
        return (-1);
136
    sap->sa_family = ARPHRD_ROSE;
137
    return (0);
138
}
139
 
140
struct hwtype rose_hwtype =
141
{
142
    "rose", NULL, /*"AMPR ROSE", */ ARPHRD_ROSE, 10,
143
    ROSE_print, ROSE_hprint, ROSE_hinput, NULL
144
};
145
 
146
struct aftype rose_aftype =
147
{
148
    "rose", NULL, /*"AMPR ROSE", */ AF_ROSE, 10,
149
    ROSE_print, ROSE_sprint, ROSE_input, ROSE_herror,
150
    NULL, NULL, NULL,
151
    -1,
152
    "/proc/net/rose"
153
};
154
 
155
#endif                          /* HAVE_xxROSE */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.