~ubuntu-branches/ubuntu/precise/openipmi/precise

« back to all changes in this revision

Viewing changes to lib/domain.c

  • Committer: Bazaar Package Importer
  • Author(s): Noèl Köthe
  • Date: 2005-10-20 23:01:55 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20051020230155-32ns8hnb1es8hntb
Tags: 2.0.2-2
added missing libgdbm-dev to libopenipmi-dev
(closes: Bug#334623)

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
 
54
54
#ifdef DEBUG_EVENTS
55
55
static void
56
 
dump_hex(unsigned char *data, int len)
 
56
dump_hex(const unsigned char *data, int len)
57
57
{
58
58
    int i;
59
59
    for (i=0; i<len; i++) {
190
190
 
191
191
#define IPMB_HASH 32
192
192
    mc_table_t ipmb_mcs[IPMB_HASH];
193
 
#define SYS_INTF_MCS 2
194
 
    ipmi_mc_t *sys_intf_mcs[SYS_INTF_MCS];
 
193
#define MAX_CONS 2
 
194
    ipmi_mc_t *sys_intf_mcs[MAX_CONS];
195
195
    ipmi_lock_t *mc_lock;
196
196
 
197
197
    /* A list of outstanding messages.  We use this so we can reroute
218
218
    ipmi_entity_info_t    *entities;
219
219
    ipmi_lock_t           *entities_lock;
220
220
 
221
 
#define MAX_CONS 2
222
221
    ipmi_lock_t   *con_lock;
223
222
    int           working_conn;
224
223
    ipmi_con_t    *conn[MAX_CONS];
985
984
 
986
985
#ifdef IPMI_CHECK_LOCKS
987
986
void
988
 
__ipmi_check_domain_lock(ipmi_domain_t *domain)
 
987
__ipmi_check_domain_lock(const ipmi_domain_t *domain)
989
988
{
990
989
    if (!domain)
991
990
        return;
1361
1360
#define HASH_SLAVE_ADDR(x) (((x) >> 1) & (IPMB_HASH-1))
1362
1361
 
1363
1362
ipmi_mc_t *
1364
 
_ipmi_find_mc_by_addr(ipmi_domain_t *domain,
1365
 
                      ipmi_addr_t   *addr,
1366
 
                      unsigned int  addr_len)
 
1363
_ipmi_find_mc_by_addr(ipmi_domain_t     *domain,
 
1364
                      const ipmi_addr_t *addr,
 
1365
                      unsigned int      addr_len)
1367
1366
{
1368
1367
    ipmi_mc_t     *mc = NULL;
1369
1368
 
1374
1373
    if (addr->addr_type == IPMI_SYSTEM_INTERFACE_ADDR_TYPE) {
1375
1374
        if (addr->channel == IPMI_BMC_CHANNEL)
1376
1375
            mc = domain->si_mc;
1377
 
        else if (addr->channel < SYS_INTF_MCS)
 
1376
        else if (addr->channel < MAX_CONS)
1378
1377
            mc = domain->sys_intf_mcs[addr->channel];
1379
1378
    } else if (addr->addr_type == IPMI_IPMB_ADDR_TYPE) {
1380
 
        ipmi_ipmb_addr_t *ipmb = (ipmi_ipmb_addr_t *) addr;
1381
 
        int              idx;
1382
 
        mc_table_t       *tab;
1383
 
        ipmi_addr_t      addr2;
1384
 
        unsigned int     addr2_len;
1385
 
        int              i;
 
1379
        const ipmi_ipmb_addr_t *ipmb = (ipmi_ipmb_addr_t *) addr;
 
1380
        int                    idx;
 
1381
        const mc_table_t       *tab;
 
1382
        ipmi_addr_t            addr2;
 
1383
        unsigned int           addr2_len;
 
1384
        int                    i;
1386
1385
 
1387
1386
        if (addr_len >= sizeof(*ipmb)) {
1388
1387
            idx = HASH_SLAVE_ADDR(ipmb->slave_addr);
1497
1496
    ipmi_lock(domain->mc_lock);
1498
1497
 
1499
1498
    if (addr.addr_type == IPMI_SYSTEM_INTERFACE_ADDR_TYPE) {
1500
 
        if (addr.channel > SYS_INTF_MCS)
 
1499
        if (addr.channel >= MAX_CONS)
1501
1500
            rv = EINVAL;
1502
1501
        else
1503
1502
            domain->sys_intf_mcs[addr.channel] = mc;
1590
1589
    ipmi_mc_get_ipmi_address(mc, &addr, &addr_len);
1591
1590
    
1592
1591
    if (addr.addr_type == IPMI_SYSTEM_INTERFACE_ADDR_TYPE) {
1593
 
        if ((addr.channel < SYS_INTF_MCS)
 
1592
        if ((addr.channel < MAX_CONS)
1594
1593
            && (mc == domain->sys_intf_mcs[addr.channel]))
1595
1594
        {
1596
1595
            domain->sys_intf_mcs[addr.channel] = NULL;
1756
1755
    ipmi_domain_t                *domain = orspi->data1;
1757
1756
    ll_msg_t                     *nmsg = orspi->data2;
1758
1757
    int                          rv;
1759
 
    ipmi_system_interface_addr_t *si;
1760
1758
 
1761
1759
    rspi = nmsg->rsp_item;
1762
1760
 
1771
1769
 
1772
1770
    if (nmsg->rsp_handler) {
1773
1771
        ipmi_move_msg_item(rspi, orspi);
1774
 
 
1775
 
        /* Override the address with the system interface address. */
1776
 
        si = (ipmi_system_interface_addr_t *) &rspi->addr;
1777
 
        si->addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
1778
 
        si->channel = (long) orspi->data4;
1779
 
        si->lun = ipmi_addr_get_lun(&rspi->addr);
1780
 
        rspi->addr_len = sizeof(*si);
1781
 
 
 
1772
        /* Set the LUN from the response message. */
 
1773
        ipmi_addr_set_lun(&rspi->addr, ipmi_addr_get_lun(&rspi->addr));
1782
1774
        deliver_rsp(domain, nmsg->rsp_handler, rspi);
1783
1775
    } else
1784
1776
        ipmi_free_msg_item(rspi);
1789
1781
}
1790
1782
 
1791
1783
static int
1792
 
matching_domain_sysaddr(ipmi_domain_t *domain, ipmi_addr_t *addr,
 
1784
matching_domain_sysaddr(ipmi_domain_t *domain, const ipmi_addr_t *addr,
1793
1785
                        ipmi_system_interface_addr_t *si)
1794
1786
{
1795
1787
    if (addr->addr_type == IPMI_IPMB_ADDR_TYPE) {
1796
1788
        ipmi_ipmb_addr_t *ipmb = (ipmi_ipmb_addr_t *) addr;
1797
1789
        int              i;
1798
1790
 
1799
 
        if (ipmb->channel == 0)
 
1791
        if (ipmb->channel != 0)
1800
1792
            return 0;
1801
1793
 
1802
1794
        for (i=0; i<MAX_CONS; i++) {
1803
1795
            if (domain->con_active[i]
1804
 
                && (domain->con_ipmb_addr[i] == ipmb->slave_addr))
 
1796
                && domain->con_up[i]
 
1797
                && (domain->con_ipmb_addr[i] == ipmb->slave_addr)
 
1798
                && domain->sys_intf_mcs[i])
1805
1799
            {
1806
1800
                si->addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
1807
 
                si->channel = 0;
 
1801
                si->channel = i;
1808
1802
                si->lun = ipmb->lun;
1809
1803
                return 1;
1810
1804
            }
1816
1810
 
1817
1811
int
1818
1812
ipmi_send_command_addr(ipmi_domain_t                *domain,
1819
 
                       ipmi_addr_t                  *addr,
 
1813
                       const ipmi_addr_t            *addr,
1820
1814
                       unsigned int                 addr_len,
1821
 
                       ipmi_msg_t                   *msg,
 
1815
                       const ipmi_msg_t             *msg,
1822
1816
                       ipmi_addr_response_handler_t rsp_handler,
1823
1817
                       void                         *rsp_data1,
1824
1818
                       void                         *rsp_data2)
1852
1846
        return ENOMEM;
1853
1847
    }
1854
1848
 
 
1849
    /* Copy the address here because where we send it may change.  But
 
1850
       we want the response address to match what we sent. */
 
1851
    memcpy(&nmsg->rsp_item->addr, addr, addr_len);
 
1852
    nmsg->rsp_item->addr_len = addr_len;
 
1853
 
1855
1854
    if (matching_domain_sysaddr(domain, addr, &si)) {
1856
 
        /* We have a direct connection to this BMC, so talk directly
1857
 
           to it. */
 
1855
        /* We have a direct connection to this BMC and it is up and
 
1856
           operational, so talk directly to it. */
1858
1857
        u = si.channel;
 
1858
        si.channel = IPMI_BMC_CHANNEL;
1859
1859
        addr = (ipmi_addr_t *) &si;
1860
1860
        addr_len = sizeof(si);
1861
1861
        handler = ll_si_rsp_handler;
1862
 
        data4 = (void *) (long) u;
1863
1862
    } else if ((addr->addr_type == IPMI_SYSTEM_INTERFACE_ADDR_TYPE)
1864
1863
        && (addr->channel != IPMI_BMC_CHANNEL))
1865
1864
    {
1882
1881
        addr = (ipmi_addr_t *) &si;
1883
1882
        addr_len = sizeof(si);
1884
1883
        handler = ll_si_rsp_handler;
1885
 
        data4 = (void *) (long) u;
1886
1884
    } else {
1887
1885
        u = domain->working_conn;
1888
1886
 
1896
1894
 
1897
1895
    nmsg->domain = domain;
1898
1896
    nmsg->con = u;
1899
 
    memcpy(&nmsg->rsp_item->addr, addr, addr_len);
1900
 
    nmsg->rsp_item->addr_len = addr_len;
1901
1897
 
1902
1898
    memcpy(&nmsg->msg, msg, sizeof(nmsg->msg));
1903
1899
    nmsg->msg.data = nmsg->msg_data;
2640
2636
       single-threaded, so ordering is always preserved there. */
2641
2637
 
2642
2638
    if (DEBUG_EVENTS) {
2643
 
        ipmi_mcid_t mcid = ipmi_event_get_mcid(event);
2644
 
        unsigned int record_id = ipmi_event_get_record_id(event);
2645
 
        unsigned int data_len = ipmi_event_get_data_len(event);
2646
 
        unsigned char *data;
 
2639
        ipmi_mcid_t         mcid = ipmi_event_get_mcid(event);
 
2640
        unsigned int        record_id = ipmi_event_get_record_id(event);
 
2641
        unsigned int        data_len = ipmi_event_get_data_len(event);
 
2642
        const unsigned char *data;
2647
2643
 
2648
2644
        ipmi_log(IPMI_LOG_DEBUG_START,
2649
2645
                 "Event recid mc (0x%x):%4.4x type:%2.2x timestamp %lld:",
2670
2666
        ipmi_ipmb_addr_t    addr;
2671
2667
        ipmi_sensor_id_t    id;
2672
2668
        event_sensor_info_t info;
2673
 
        unsigned char       *data;
 
2669
        const unsigned char *data;
2674
2670
 
2675
2671
        data = ipmi_event_get_data_ptr(event);
2676
2672
        addr.addr_type = IPMI_IPMB_ADDR_TYPE;
2726
2722
}
2727
2723
 
2728
2724
static void
2729
 
ll_event_handler(ipmi_con_t   *ipmi,
2730
 
                 ipmi_addr_t  *addr,
2731
 
                 unsigned int addr_len,
2732
 
                 ipmi_event_t *event,
2733
 
                 void         *cb_data)
 
2725
ll_event_handler(ipmi_con_t        *ipmi,
 
2726
                 const ipmi_addr_t *addr,
 
2727
                 unsigned int      addr_len,
 
2728
                 ipmi_event_t      *event,
 
2729
                 void              *cb_data)
2734
2730
{
2735
2731
    ipmi_domain_t                *domain = cb_data;
2736
2732
    ipmi_mc_t                    *mc;
2891
2887
 
2892
2888
typedef struct next_event_handler_info_s
2893
2889
{
2894
 
    ipmi_event_t *rv;
2895
 
    ipmi_event_t *event;
2896
 
    ipmi_mcid_t  event_mcid;
2897
 
    int          found_curr_mc;
2898
 
    int          do_prev; /* If going backwards, this will be 1. */
 
2890
    ipmi_event_t       *rv;
 
2891
    const ipmi_event_t *event;
 
2892
    ipmi_mcid_t        event_mcid;
 
2893
    int                found_curr_mc;
 
2894
    int                do_prev; /* If going backwards, this will be 1. */
2899
2895
} next_event_handler_info_t;
2900
2896
 
2901
2897
static void
2962
2958
}
2963
2959
 
2964
2960
ipmi_event_t *
2965
 
ipmi_domain_next_event(ipmi_domain_t *domain, ipmi_event_t *event)
 
2961
ipmi_domain_next_event(ipmi_domain_t *domain, const ipmi_event_t *event)
2966
2962
{
2967
2963
    next_event_handler_info_t info;
2968
2964
 
2979
2975
}
2980
2976
 
2981
2977
ipmi_event_t *
2982
 
ipmi_domain_prev_event(ipmi_domain_t *domain, ipmi_event_t *event)
 
2978
ipmi_domain_prev_event(ipmi_domain_t *domain, const ipmi_event_t *event)
2983
2979
{
2984
2980
    next_event_handler_info_t info;
2985
2981
 
3310
3306
    CHECK_DOMAIN_LOCK(domain);
3311
3307
 
3312
3308
    ipmi_lock(domain->mc_lock);
3313
 
    for (i=0; i<SYS_INTF_MCS; i++) {
 
3309
    for (i=0; i<MAX_CONS; i++) {
3314
3310
        ipmi_mc_t *mc = domain->sys_intf_mcs[i];
3315
3311
        if (mc && !_ipmi_mc_get(mc)) {
3316
3312
            ipmi_unlock(domain->mc_lock);
3359
3355
            }
3360
3356
        }
3361
3357
    }
3362
 
    for (i=SYS_INTF_MCS-1; i>=0; i--) {
 
3358
    for (i=MAX_CONS-1; i>=0; i--) {
3363
3359
        ipmi_mc_t *mc = domain->sys_intf_mcs[i];
3364
3360
        if (mc && !_ipmi_mc_get(mc)) {
3365
3361
            ipmi_unlock(domain->mc_lock);
3511
3507
}
3512
3508
 
3513
3509
int
3514
 
ipmi_domain_id_is_invalid(ipmi_domain_id_t *id)
 
3510
ipmi_domain_id_is_invalid(const ipmi_domain_id_t *id)
3515
3511
{
3516
3512
    return (id->domain == NULL);
3517
3513
}
4866
4862
    return addr;
4867
4863
}
4868
4864
 
4869
 
char *
4870
 
_ipmi_domain_name(ipmi_domain_t *domain)
 
4865
const char *
 
4866
_ipmi_domain_name(const ipmi_domain_t *domain)
4871
4867
{
4872
4868
    return domain->name;
4873
4869
}
5228
5224
 
5229
5225
typedef struct domain_stat_cmp_s
5230
5226
{
5231
 
    char               *name;
5232
 
    char               *instance;
 
5227
    const char         *name;
 
5228
    const char         *instance;
5233
5229
    ipmi_domain_stat_t *stat;
5234
5230
} domain_stat_cmp_t;
5235
5231
 
5251
5247
 
5252
5248
int
5253
5249
ipmi_domain_stat_register(ipmi_domain_t      *domain,
5254
 
                          char               *name,
5255
 
                          char               *instance,
 
5250
                          const char         *name,
 
5251
                          const char         *instance,
5256
5252
                          ipmi_domain_stat_t **stat)
5257
5253
{
5258
5254
    ipmi_domain_stat_t  *val = NULL;
5326
5322
 
5327
5323
int
5328
5324
ipmi_domain_find_stat(ipmi_domain_t      *domain,
5329
 
                      char               *name,
5330
 
                      char               *instance,
 
5325
                      const char         *name,
 
5326
                      const char         *instance,
5331
5327
                      ipmi_domain_stat_t **stat)
5332
5328
{
5333
5329
    domain_stat_cmp_t   info;
5410
5406
typedef struct stat_iterate_s
5411
5407
{
5412
5408
    ipmi_domain_t *domain;
5413
 
    char          *name;
5414
 
    char          *instance;
 
5409
    const char    *name;
 
5410
    const char    *instance;
5415
5411
    ipmi_stat_cb  handler;
5416
5412
    void          *cb_data;
5417
5413
} stat_iterate_t;
5449
5445
 
5450
5446
void
5451
5447
ipmi_domain_stat_iterate(ipmi_domain_t *domain,
5452
 
                         char          *name,
5453
 
                         char          *instance,
 
5448
                         const char    *name,
 
5449
                         const char    *instance,
5454
5450
                         ipmi_stat_cb  handler,
5455
5451
                         void          *cb_data)
5456
5452
{