File: nvram-wakeup-mb.c

package info (click to toggle)
nvram-wakeup 1.1-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 2,052 kB
  • ctags: 242
  • sloc: ansic: 1,943; sh: 309; ruby: 190; makefile: 102
file content (183 lines) | stat: -rw-r--r-- 5,543 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*
 *   NVRAM WakeUp
 *   Copyright (C) 2001-2005, Sergei Haller.
 *   Copyright (C) 2002 Bernhard "Bero" Rosenkraenzer <bero@arklinux.org>
 *
 *   $Id: nvram-wakeup-mb.c 870 2008-09-06 20:48:34Z tiber $
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

#define CVSREV_nvram_wakeup_mb_c \
     "$Id: nvram-wakeup-mb.c 870 2008-09-06 20:48:34Z tiber $"

#include <stdio.h>
#include <string.h>
#include <syslog.h>

#include "nvram-wakeup.h"

/*
 *  If you can't find your motherboard here, try at the MB tracker
 *    http://sourceforge.net/tracker/index.php?group_id=35022&atid=412959
 *  or the latest SVN revision of this file
 *    http://nvram-wakeup.svn.sourceforge.net/viewvc/nvram-wakeup/trunk/nvram-wakeup/boards/boards.yaml
 *  or
 *    read README.mb.
 */

typedef void (*info_writer)(struct biosinfo *b);
     
struct mainboard {
     info_writer infowriter;

     char *iw_name;     /* the function name of the infowriter */

     char *vendor;
     char *type;
     char *version;

     char *biosvendor;
     char *biosversion;
     char *biosrelease;
};


/*
 *  look into nvram-wakeup.conf(5) for the documentation of the options
 */
 
/* 
 *  By far the most common way of storing the timing information is having
 *  it in subsequent bytes in the day-hour-min-sec order. #define this
 *  here to save code later on
 */
 
#define TIMEREGS(b, base) b->addr_day  = base;  \
                          b->addr_hour = base+1;\
                          b->addr_min  = base+2;\
                          b->addr_sec  = base+3

/* 
 *  Virtually every board keeps the low and high bytes of the checksum in
 *  subsequent bytes - save some more code
 */
 
#define CHECKSUM(b, base) b->addr_chk_h = base;\
                          b->addr_chk_l = base+1

#define   BCD(b) b->nr_mon      = 5;\
                 b->nr_day      = 6;\
                 b->nr_hour     = 6;\
                 b->nr_min      = 7;\
                 b->nr_sec      = 7;\
                 b->nr_rtc_mon  = 5;\
                 b->nr_rtc_day  = 6;\
                 b->nr_wdays    = 7;\
                 b->bcd         = ON

#define NOBCD(b) b->nr_mon      = 4;\
                 b->nr_day      = 5;\
                 b->nr_hour     = 5;\
                 b->nr_min      = 6;\
                 b->nr_sec      = 6;\
                 b->nr_rtc_day  = 6;\
                 b->nr_rtc_mon  = 5;\
                 b->nr_wdays    = 7

#include "infowriters.c.inc"

#define IW(x) x, #x

/*
 * Definitions of the mainboards below are in the format
 *
 *             { infowriter,        iwname,             boardvendor, boardtype, boardversion, biosvendor, biosversion, biosrelease }
 *
 * Where NULL means "Don't care" and "" is a real empty field.
 */
#include "boards.c.inc"


int set_biosinfo_defaults(struct biosinfo *b) {
     if (b) {
          memset(b, 0, sizeof(struct biosinfo));
          b->nr_stat = 1;
          b->addr_stat = -1;
          NOBCD(b);
          return 1;
     }
     else return 0;
}

int get_bios_info_by_dmi(struct biosinfo *b) {

     int i;

     /* Set defaults... */
     if (!set_biosinfo_defaults(b))
          return 0;

     if (!__dmi_probe())
          return -1;

     /* Check if we know the mainboard... */
     for(i=0; boards[i].infowriter; i++) {
          if (boards[i].vendor      && (!board_vendor()  || strcmp(boards[i].vendor,      board_vendor() )))
               continue;
          if (boards[i].type        && (!board_type()    || strcmp(boards[i].type,        board_type()   )))
               continue;
          if (boards[i].version     && (!board_version() || strcmp(boards[i].version,     board_version())))
               continue;
          if (boards[i].biosvendor  && (!bios_vendor()   || strcmp(boards[i].biosvendor,  bios_vendor()  )))
               continue;
          if (boards[i].biosversion && (!bios_version()  || strcmp(boards[i].biosversion, bios_version() )))
               continue;
          if (boards[i].biosrelease && (!bios_release()  || strcmp(boards[i].biosrelease, bios_release() )))
               continue;

          /* This is our board... */
          nvprintf(LOG_DEBUG, "Using infowriter \"%s\" (automatically detected)\n", boards[i].iw_name);
          boards[i].infowriter(b);
          return 1;
     }
     return 0;
}



int get_bios_info_by_iw(struct biosinfo *b, const char * iw_name) {

     int i;

     /* Set defaults... */
     if (!set_biosinfo_defaults(b))
          return 0;

     /* Check if we know that infowriter... */
     for(i=0; boards[i].infowriter; i++) {
          if ( strcmp( boards[i].iw_name, iw_name ) )
               continue;

          /* This is our board... */
          nvprintf(LOG_DEBUG, "Using infowriter \"%s\" (manually choosen)\n", boards[i].iw_name);
          boards[i].infowriter(b);
          return 1;
     }
     return 0;
}