aboutsummaryrefslogtreecommitdiffstats
path: root/lib/lufa/Projects/AVRISP-MKII/Config
diff options
context:
space:
mode:
authorAlex Mayer <amayer5125@gmail.com>2019-04-01 12:02:30 -0400
committerMechMerlin <30334081+mechmerlin@users.noreply.github.com>2019-04-01 09:02:30 -0700
commit58b065cfdaca29144fa7fd18d482223bc1ea7308 (patch)
treecb5e86ecea13f767c236d10aab4e7ae5431dcc61 /lib/lufa/Projects/AVRISP-MKII/Config
parent3654d0f080c85da3b2ae33cc035777a445cca769 (diff)
downloadfirmware-58b065cfdaca29144fa7fd18d482223bc1ea7308.tar.gz
firmware-58b065cfdaca29144fa7fd18d482223bc1ea7308.tar.bz2
firmware-58b065cfdaca29144fa7fd18d482223bc1ea7308.zip
1UP Keyboards: Use Right Variant Of Keys On Right Side Of Board (#5529)
Diffstat (limited to 'lib/lufa/Projects/AVRISP-MKII/Config')
0 files changed, 0 insertions, 0 deletions
id='n125' href='#n125'>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 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321
/****************************************************************
 * acm_policy.c
 * 
 * Copyright (C) 2005 IBM Corporation
 *
 * Author:
 * Reiner Sailer <sailer@watson.ibm.com>
 *
 * Contributors:
 * Stefan Berger <stefanb@watson.ibm.com>
 *
 * 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, version 2 of the
 * License.
 *
 * sHype access control policy management for Xen.
 *       This interface allows policy tools in authorized
 *       domains to interact with the Xen access control module
 * 
 */

#include <xen/config.h>
#include <xen/errno.h>
#include <xen/types.h>
#include <xen/lib.h>
#include <xen/delay.h>
#include <xen/sched.h>
#include <acm/acm_core.h>
#include <public/acm_ops.h>
#include <acm/acm_hooks.h>
#include <acm/acm_endian.h>

int
acm_set_policy(void *buf, u32 buf_size, int isuserbuffer)
{
    u8 *policy_buffer = NULL;
    struct acm_policy_buffer *pol;
 
    if (buf_size < sizeof(struct acm_policy_buffer))
        return -EFAULT;

    /* 1. copy buffer from domain */
    if ((policy_buffer = xmalloc_array(u8, buf_size)) == NULL)
        return -ENOMEM;

    if (isuserbuffer) {
        if (copy_from_user(policy_buffer, buf, buf_size))
        {
            printk("%s: Error copying!\n",__func__);
            goto error_free;
        }
    } else
        memcpy(policy_buffer, buf, buf_size);

    /* 2. some sanity checking */
    pol = (struct acm_policy_buffer *)policy_buffer;

    if ((ntohl(pol->magic) != ACM_MAGIC) ||
        (buf_size != ntohl(pol->len)) ||
        (ntohl(pol->policy_version) != ACM_POLICY_VERSION))
    {
        printk("%s: ERROR in Magic, Version, or buf size.\n", __func__);
        goto error_free;
    }

    if (acm_active_security_policy == ACM_POLICY_UNDEFINED) {
        /* setup the policy with the boot policy */
        if (acm_init_binary_policy((ntohl(pol->secondary_policy_code) << 4) |
                                   ntohl(pol->primary_policy_code))) {
            goto error_free;
        }
        acm_active_security_policy =
            (acm_bin_pol.secondary_policy_code << 4) | acm_bin_pol.primary_policy_code;
    }

    /* once acm_active_security_policy is set, it cannot be changed */
    if ((ntohl(pol->primary_policy_code) != acm_bin_pol.primary_policy_code) ||
        (ntohl(pol->secondary_policy_code) != acm_bin_pol.secondary_policy_code))
    {
        printkd("%s: Wrong policy type in boot policy!\n", __func__);
        goto error_free;
    }

    /* get bin_policy lock and rewrite policy (release old one) */
    write_lock(&acm_bin_pol_rwlock);

    /* 3. set label reference name */
    if (acm_set_policy_reference(buf + ntohl(pol->policy_reference_offset),
                                 ntohl(pol->primary_buffer_offset) -
                                 ntohl(pol->policy_reference_offset)))
        goto error_lock_free;

    /* 4. set primary policy data */
    if (acm_primary_ops->set_binary_policy(buf + ntohl(pol->primary_buffer_offset),
                                           ntohl(pol->secondary_buffer_offset) -
                                           ntohl(pol->primary_buffer_offset)))
        goto error_lock_free;

    /* 5. set secondary policy data */
    if (acm_secondary_ops->set_binary_policy(buf + ntohl(pol->secondary_buffer_offset),
                                             ntohl(pol->len) - 
                                             ntohl(pol->secondary_buffer_offset)))
        goto error_lock_free;

    write_unlock(&acm_bin_pol_rwlock);
    xfree(policy_buffer);
    return ACM_OK;

 error_lock_free:
    write_unlock(&acm_bin_pol_rwlock);
 error_free:
    printk("%s: Error setting policy.\n", __func__);
    xfree(policy_buffer);
    return -EFAULT;
}

int
acm_get_policy(void *buf, u32 buf_size)
{ 
    u8 *policy_buffer;
    int ret;
    struct acm_policy_buffer *bin_pol;
 
    if (buf_size < sizeof(struct acm_policy_buffer))
        return -EFAULT;

    if ((policy_buffer = xmalloc_array(u8, buf_size)) == NULL)
        return -ENOMEM;

    read_lock(&acm_bin_pol_rwlock);

    bin_pol = (struct acm_policy_buffer *)policy_buffer;
    bin_pol->magic = htonl(ACM_MAGIC);
    bin_pol->primary_policy_code = htonl(acm_bin_pol.primary_policy_code);
    bin_pol->secondary_policy_code = htonl(acm_bin_pol.secondary_policy_code);

    bin_pol->len = htonl(sizeof(struct acm_policy_buffer));
    bin_pol->policy_reference_offset = htonl(ntohl(bin_pol->len));
    bin_pol->primary_buffer_offset = htonl(ntohl(bin_pol->len));
    bin_pol->secondary_buffer_offset = htonl(ntohl(bin_pol->len));
     
    ret = acm_dump_policy_reference(policy_buffer + ntohl(bin_pol->policy_reference_offset),
                                    buf_size - ntohl(bin_pol->policy_reference_offset));
    if (ret < 0)
        goto error_free_unlock;

    bin_pol->len = htonl(ntohl(bin_pol->len) + ret);
    bin_pol->primary_buffer_offset = htonl(ntohl(bin_pol->len));

    ret = acm_primary_ops->dump_binary_policy (policy_buffer + ntohl(bin_pol->primary_buffer_offset),